@@ -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
@@ -141,7 +144,7 @@ module fpm_command_line
141
144
& ' test' , ' runner' , ' install' , ' update' , ' list' , ' help' , ' version' , ' publish' ]
142
145
143
146
character (len= :), allocatable :: val_runner, val_compiler, val_flag, val_cflag, val_cxxflag, val_ldflag, &
144
- val_profile
147
+ val_profile, val_runner_args
145
148
146
149
! '12345678901234567890123456789012345678901234567890123456789012345678901234567890',&
147
150
character (len= 80 ), parameter :: help_text_build_common(* ) = [character (len= 80 ) :: &
@@ -268,7 +271,8 @@ subroutine get_command_line_settings(cmd_settings)
268
271
run_args = &
269
272
' --target " "' // &
270
273
' --list F' // &
271
- ' --runner " "'
274
+ ' --runner " "' // &
275
+ ' --runner-args " "'
272
276
273
277
compiler_args = &
274
278
' --profile " "' // &
@@ -317,12 +321,17 @@ subroutine get_command_line_settings(cmd_settings)
317
321
if (names(i)==' ..' )names(i)= ' *'
318
322
enddo
319
323
324
+ ! If there are additional command-line arguments, remove the additional
325
+ ! double quotes which have been added by M_CLI2
326
+ call remove_characters_in_set(remaining,set= ' "' )
327
+
320
328
c_compiler = sget(' c-compiler' )
321
329
cxx_compiler = sget(' cxx-compiler' )
322
330
archiver = sget(' archiver' )
323
331
allocate (fpm_run_settings :: cmd_settings)
324
332
val_runner= sget(' runner' )
325
333
if (specified(' runner' ) .and. val_runner==' ' )val_runner= ' echo'
334
+ val_runner_args= sget(' runner-args' )
326
335
cmd_settings= fpm_run_settings(&
327
336
& args= remaining,&
328
337
& profile= val_profile,&
@@ -340,6 +349,7 @@ subroutine get_command_line_settings(cmd_settings)
340
349
& build_tests= .false. ,&
341
350
& name= names,&
342
351
& runner= val_runner,&
352
+ & runner_args= val_runner_args, &
343
353
& verbose= lget(' verbose' ) )
344
354
345
355
case (' build' )
@@ -565,12 +575,17 @@ subroutine get_command_line_settings(cmd_settings)
565
575
if (names(i)==' ..' )names(i)= ' *'
566
576
enddo
567
577
578
+ ! If there are additional command-line arguments, remove the additional
579
+ ! double quotes which have been added by M_CLI2
580
+ call remove_characters_in_set(remaining,set= ' "' )
581
+
568
582
c_compiler = sget(' c-compiler' )
569
583
cxx_compiler = sget(' cxx-compiler' )
570
584
archiver = sget(' archiver' )
571
585
allocate (fpm_test_settings :: cmd_settings)
572
586
val_runner= sget(' runner' )
573
587
if (specified(' runner' ) .and. val_runner==' ' )val_runner= ' echo'
588
+ val_runner_args= sget(' runner-args' )
574
589
cmd_settings= fpm_test_settings(&
575
590
& args= remaining, &
576
591
& profile= val_profile, &
@@ -588,6 +603,7 @@ subroutine get_command_line_settings(cmd_settings)
588
603
& build_tests= .true. , &
589
604
& name= names, &
590
605
& runner= val_runner, &
606
+ & runner_args= val_runner_args, &
591
607
& verbose= lget(' verbose' ) )
592
608
593
609
case (' update' )
@@ -768,7 +784,7 @@ subroutine set_help()
768
784
' executables. ' , &
769
785
' ' , &
770
786
' SYNOPSIS ' , &
771
- ' fpm run|test --runner CMD ... -- SUFFIX_OPTIONS ' , &
787
+ ' fpm run|test --runner CMD ... --runner-args ARGS -- SUFFIX_OPTIONS ' , &
772
788
' ' , &
773
789
' DESCRIPTION ' , &
774
790
' The --runner option allows specifying a program to launch ' , &
@@ -784,8 +800,11 @@ subroutine set_help()
784
800
' Available for both the "run" and "test" subcommands. ' , &
785
801
' If the keyword is specified without a value the default command ' , &
786
802
' is "echo". ' , &
803
+ ' --runner-args "args" an additional option to pass command-line arguments ' , &
804
+ ' to the runner command, instead of to the fpm app. ' , &
787
805
' -- SUFFIX_OPTIONS additional options to suffix the command CMD and executable ' , &
788
- ' file names with. ' , &
806
+ ' file names with. These options are passed as command-line ' , &
807
+ ' arguments to the app. ' , &
789
808
' EXAMPLES ' , &
790
809
' Use cases for '' fpm run|test --runner "CMD"'' include employing ' , &
791
810
' the following common GNU/Linux and Unix commands: ' , &
@@ -814,6 +833,7 @@ subroutine set_help()
814
833
' ' , &
815
834
' fpm test --runner gdb ' , &
816
835
' fpm run --runner "tar cvfz $HOME/bundle.tgz" ' , &
836
+ ' fpm run --runner "mpiexec" --runner-args "-np 12" ' , &
817
837
' fpm run --runner ldd ' , &
818
838
' fpm run --runner strip ' , &
819
839
' fpm run --runner '' cp -t /usr/local/bin'' ' , &
@@ -1430,4 +1450,20 @@ function get_fpm_env(env, default) result(val)
1430
1450
val = get_env(fpm_prefix// env, default)
1431
1451
end function get_fpm_env
1432
1452
1453
+
1454
+ ! > Build a full runner command (executable + command-line arguments)
1455
+ function runner_command (cmd ) result(run_cmd)
1456
+ class(fpm_run_settings), intent (in ) :: cmd
1457
+ character (len= :), allocatable :: run_cmd
1458
+ ! > Get executable
1459
+ if (len_trim (cmd% runner)>0 ) then
1460
+ run_cmd = trim (cmd% runner)
1461
+ else
1462
+ run_cmd = ' '
1463
+ end if
1464
+ ! > Append command-line arguments
1465
+ if (len_trim (cmd% runner_args)>0 ) run_cmd = run_cmd// ' ' // trim (cmd% runner_args)
1466
+ end function runner_command
1467
+
1468
+
1433
1469
end module fpm_command_line
0 commit comments