@@ -28,7 +28,7 @@ module fpm_command_line
28
28
OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD
29
29
use M_CLI2, only : set_args, lget, sget, unnamed, remaining, specified
30
30
use M_CLI2, only : get_subcommand, CLI_RESPONSE_FILE
31
- use fpm_strings, only : lower, split, to_fortran_name, is_fortran_name
31
+ use fpm_strings, only : lower, split, to_fortran_name, is_fortran_name, remove_characters_in_set, string_t
32
32
use fpm_filesystem, only : basename, canon_path, which, run
33
33
use fpm_environment, only : get_command_arguments_quoted
34
34
use fpm_error, only : fpm_stop, error_t
@@ -88,9 +88,12 @@ module fpm_command_line
88
88
89
89
type, extends(fpm_build_settings) :: fpm_run_settings
90
90
character (len= ibug),allocatable :: name (:)
91
- character (len= :),allocatable :: args
91
+ character (len= :),allocatable :: args ! passed to the app
92
92
character (len= :),allocatable :: runner
93
+ character (len= :),allocatable :: runner_args ! passed to the runner
93
94
logical :: example
95
+ contains
96
+ procedure :: runner_command
94
97
end type
95
98
96
99
type, extends(fpm_run_settings) :: fpm_test_settings
@@ -139,7 +142,7 @@ module fpm_command_line
139
142
& ' test' , ' runner' , ' install' , ' update' , ' list' , ' help' , ' version' , ' publish' ]
140
143
141
144
character (len= :), allocatable :: val_runner, val_compiler, val_flag, val_cflag, val_cxxflag, val_ldflag, &
142
- val_profile
145
+ val_profile, val_runner_args
143
146
144
147
! '12345678901234567890123456789012345678901234567890123456789012345678901234567890',&
145
148
character (len= 80 ), parameter :: help_text_build_common(* ) = [character (len= 80 ) :: &
@@ -264,7 +267,8 @@ subroutine get_command_line_settings(cmd_settings)
264
267
run_args = &
265
268
' --target " "' // &
266
269
' --list F' // &
267
- ' --runner " "'
270
+ ' --runner " "' // &
271
+ ' --runner-args " "'
268
272
269
273
compiler_args = &
270
274
' --profile " "' // &
@@ -313,12 +317,18 @@ subroutine get_command_line_settings(cmd_settings)
313
317
if (names(i)==' ..' )names(i)= ' *'
314
318
enddo
315
319
320
+ ! If there are additional command-line arguments, remove the additional
321
+ ! double quotes which have been added by M_CLI2
322
+ val_runner_args= sget(' runner-args' )
323
+ call remove_characters_in_set(val_runner_args,set= ' "' )
324
+
316
325
c_compiler = sget(' c-compiler' )
317
326
cxx_compiler = sget(' cxx-compiler' )
318
327
archiver = sget(' archiver' )
319
328
allocate (fpm_run_settings :: cmd_settings)
320
329
val_runner= sget(' runner' )
321
330
if (specified(' runner' ) .and. val_runner==' ' )val_runner= ' echo'
331
+
322
332
cmd_settings= fpm_run_settings(&
323
333
& args= remaining,&
324
334
& profile= val_profile,&
@@ -336,6 +346,7 @@ subroutine get_command_line_settings(cmd_settings)
336
346
& build_tests= .false. ,&
337
347
& name= names,&
338
348
& runner= val_runner,&
349
+ & runner_args= val_runner_args, &
339
350
& verbose= lget(' verbose' ) )
340
351
341
352
case (' build' )
@@ -561,12 +572,18 @@ subroutine get_command_line_settings(cmd_settings)
561
572
if (names(i)==' ..' )names(i)= ' *'
562
573
enddo
563
574
575
+ ! If there are additional command-line arguments, remove the additional
576
+ ! double quotes which have been added by M_CLI2
577
+ val_runner_args= sget(' runner-args' )
578
+ call remove_characters_in_set(val_runner_args,set= ' "' )
579
+
564
580
c_compiler = sget(' c-compiler' )
565
581
cxx_compiler = sget(' cxx-compiler' )
566
582
archiver = sget(' archiver' )
567
583
allocate (fpm_test_settings :: cmd_settings)
568
584
val_runner= sget(' runner' )
569
585
if (specified(' runner' ) .and. val_runner==' ' )val_runner= ' echo'
586
+
570
587
cmd_settings= fpm_test_settings(&
571
588
& args= remaining, &
572
589
& profile= val_profile, &
@@ -584,6 +601,7 @@ subroutine get_command_line_settings(cmd_settings)
584
601
& build_tests= .true. , &
585
602
& name= names, &
586
603
& runner= val_runner, &
604
+ & runner_args= val_runner_args, &
587
605
& verbose= lget(' verbose' ))
588
606
589
607
case (' update' )
@@ -762,7 +780,7 @@ subroutine set_help()
762
780
' executables. ' , &
763
781
' ' , &
764
782
' SYNOPSIS ' , &
765
- ' fpm run|test --runner CMD ... -- SUFFIX_OPTIONS ' , &
783
+ ' fpm run|test --runner CMD ... --runner-args ARGS -- SUFFIX_OPTIONS ' , &
766
784
' ' , &
767
785
' DESCRIPTION ' , &
768
786
' The --runner option allows specifying a program to launch ' , &
@@ -778,8 +796,11 @@ subroutine set_help()
778
796
' Available for both the "run" and "test" subcommands. ' , &
779
797
' If the keyword is specified without a value the default command ' , &
780
798
' is "echo". ' , &
799
+ ' --runner-args "args" an additional option to pass command-line arguments ' , &
800
+ ' to the runner command, instead of to the fpm app. ' , &
781
801
' -- SUFFIX_OPTIONS additional options to suffix the command CMD and executable ' , &
782
- ' file names with. ' , &
802
+ ' file names with. These options are passed as command-line ' , &
803
+ ' arguments to the app. ' , &
783
804
' EXAMPLES ' , &
784
805
' Use cases for '' fpm run|test --runner "CMD"'' include employing ' , &
785
806
' the following common GNU/Linux and Unix commands: ' , &
@@ -808,6 +829,7 @@ subroutine set_help()
808
829
' ' , &
809
830
' fpm test --runner gdb ' , &
810
831
' fpm run --runner "tar cvfz $HOME/bundle.tgz" ' , &
832
+ ' fpm run --runner "mpiexec" --runner-args "-np 12" ' , &
811
833
' fpm run --runner ldd ' , &
812
834
' fpm run --runner strip ' , &
813
835
' fpm run --runner '' cp -t /usr/local/bin'' ' , &
@@ -1424,4 +1446,20 @@ function get_fpm_env(env, default) result(val)
1424
1446
val = get_env(fpm_prefix// env, default)
1425
1447
end function get_fpm_env
1426
1448
1449
+
1450
+ ! > Build a full runner command (executable + command-line arguments)
1451
+ function runner_command (cmd ) result(run_cmd)
1452
+ class(fpm_run_settings), intent (in ) :: cmd
1453
+ character (len= :), allocatable :: run_cmd
1454
+ ! > Get executable
1455
+ if (len_trim (cmd% runner)>0 ) then
1456
+ run_cmd = trim (cmd% runner)
1457
+ else
1458
+ run_cmd = ' '
1459
+ end if
1460
+ ! > Append command-line arguments
1461
+ if (len_trim (cmd% runner_args)>0 ) run_cmd = run_cmd// ' ' // trim (cmd% runner_args)
1462
+ end function runner_command
1463
+
1464
+
1427
1465
end module fpm_command_line
0 commit comments