Skip to content

Commit 29c1fa5

Browse files
committed
This option already exists in the Haskell version. It helps reduce the need
for the user to interact directly with the build/ directory, which ideally should be a black box as far as the user is concerned. --runner CMD A command to prefix the program execution paths with. For use with utilities like valgrind(1), time(1), and other utilities that launch executables; commands that inspect the files like ldd(1), file(1), and ls(1); and that copy or change the files like strip(1) and install(1). EXAMPLES # install executables in directory (assuming install(1) exists) fpm run -c 'install -b -m 0711 -p -t /usr/local/bin'
1 parent ca1a0e4 commit 29c1fa5

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

fpm/fpm.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tag = "v0.2.1"
1212

1313
[dependencies.M_CLI2]
1414
git = "https://github.com/urbanjost/M_CLI2.git"
15-
rev = "649075aceb97f997665a1a4656514fd2e9b4becc"
15+
rev = "09b4079f58ccf3e2ddbd82fe9f44986dc58f85bd"
1616

1717
[[test]]
1818
name = "cli-test"

fpm/src/fpm.f90

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,11 @@ subroutine cmd_run(settings,test)
453453
else
454454

455455
if (exists(executables(i)%s)) then
456-
call run(executables(i)%s//" "//settings%args)
456+
if(settings%runner .ne. ' ')then
457+
call run(settings%runner//' '//executables(i)%s//" "//settings%args)
458+
else
459+
call run(executables(i)%s//" "//settings%args)
460+
endif
457461
else
458462
write(stderr,*)'fpm::run<ERROR>',executables(i)%s,' not found'
459463
stop 1

fpm/src/fpm_command_line.f90

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module fpm_command_line
22
use fpm_environment, only : get_os_type, &
33
OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_WINDOWS, &
44
OS_CYGWIN, OS_SOLARIS, OS_FREEBSD
5-
use M_CLI2, only : set_args, lget, unnamed, remaining, specified
5+
use M_CLI2, only : set_args, lget, sget, unnamed, remaining, specified
66
use fpm_strings, only : lower
77
use fpm_filesystem, only : basename, canon_path
88
use,intrinsic :: iso_fortran_env, only : stdin=>input_unit, &
@@ -39,6 +39,7 @@ module fpm_command_line
3939
type, extends(fpm_build_settings) :: fpm_run_settings
4040
character(len=ibug),allocatable :: name(:)
4141
character(len=:),allocatable :: args
42+
character(len=:),allocatable :: runner
4243
end type
4344

4445
type, extends(fpm_run_settings) :: fpm_test_settings
@@ -57,6 +58,7 @@ module fpm_command_line
5758
& help_text(:), help_install(:), help_help(:), &
5859
& help_list(:), help_list_dash(:), help_list_nodash(:)
5960

61+
character(len=:), allocatable :: charbug
6062
contains
6163
subroutine get_command_line_settings(cmd_settings)
6264
class(fpm_cmd_settings), allocatable, intent(out) :: cmd_settings
@@ -97,7 +99,7 @@ subroutine get_command_line_settings(cmd_settings)
9799
select case(trim(cmdarg))
98100

99101
case('run')
100-
call set_args('--list F --release F --',help_run,version_text)
102+
call set_args('--list:l F --release:r F --runner:c " " --',help_run,version_text)
101103

102104
if( size(unnamed) .gt. 1 )then
103105
names=unnamed(2:)
@@ -107,17 +109,17 @@ subroutine get_command_line_settings(cmd_settings)
107109

108110
allocate(fpm_run_settings :: cmd_settings)
109111
cmd_settings=fpm_run_settings( name=names, list=lget('list'), &
110-
& release=lget('release'), args=remaining )
112+
& release=lget('release'), args=remaining ,runner=sget('runner'))
111113

112114
case('build')
113-
call set_args( '--release F --list F --',help_build,version_text )
115+
call set_args( '--release:r F --list:l F --',help_build,version_text )
114116

115117
allocate( fpm_build_settings :: cmd_settings )
116118
cmd_settings=fpm_build_settings( release=lget('release'), &
117119
& list=lget('list') )
118120

119121
case('new')
120-
call set_args(' --src F --lib F --app F --test F --backfill F', &
122+
call set_args(' --src:s F --lib:l F --app:a F --test:t F --backfill:b F', &
121123
& help_new, version_text)
122124
select case(size(unnamed))
123125
case(1)
@@ -203,17 +205,17 @@ subroutine get_command_line_settings(cmd_settings)
203205
call printhelp(help_text)
204206

205207
case('install')
206-
call set_args('--release F ', help_install, version_text)
208+
call set_args('--release:r F ', help_install, version_text)
207209

208210
allocate(fpm_install_settings :: cmd_settings)
209211
case('list')
210-
call set_args(' --list F', help_list, version_text)
212+
call set_args(' --list:l F', help_list, version_text)
211213
call printhelp(help_list_nodash)
212214
if(lget('list'))then
213215
call printhelp(help_list_dash)
214216
endif
215217
case('test')
216-
call set_args('--list F --release F --',help_test,version_text)
218+
call set_args('--list:l F --release:r F --runner:c " " --',help_test,version_text)
217219

218220
if( size(unnamed) .gt. 1 )then
219221
names=unnamed(2:)
@@ -222,12 +224,13 @@ subroutine get_command_line_settings(cmd_settings)
222224
endif
223225

224226
allocate(fpm_test_settings :: cmd_settings)
227+
charbug=sget('runner')
225228
cmd_settings=fpm_test_settings( name=names, list=lget('list'), &
226-
& release=lget('release'), args=remaining )
229+
& release=lget('release'), args=remaining ,runner=charbug )
227230

228231
case default
229232

230-
call set_args(' --list F', help_fpm, version_text)
233+
call set_args(' --list:l F', help_fpm, version_text)
231234
! Note: will not get here if --version or --usage or --help
232235
! is present on commandline
233236
help_text=help_usage
@@ -296,8 +299,8 @@ subroutine set_help()
296299
' help [NAME(s)] ', &
297300
' new NAME [--lib|--src] [--app] [--test] [--backfill] ', &
298301
' list [--list] ', &
299-
' run [NAME(s)] [--release] [--list] [-- ARGS] ', &
300-
' test [NAME(s)] [--release] [--list] [-- ARGS] ', &
302+
' run [NAME(s)] [--release] [--runner "CMD"] [--list] [-- ARGS] ', &
303+
' test [NAME(s)] [--release] [--runner "CMD"] [--list] [-- ARGS] ', &
301304
' ']
302305
help_usage=[character(len=80) :: &
303306
'' ]
@@ -334,10 +337,10 @@ subroutine set_help()
334337
' new NAME [--lib|--src] [--app] [--test] [--backfill] ', &
335338
' Create a new Fortran package directory ', &
336339
' with sample files ', &
337-
' run [NAME(s)] [--release] [--list] [-- ARGS] ', &
340+
' run [NAME(s)] [--release] [--list] [--runner "CMD"][-- ARGS] ', &
338341
' Run the local package binaries. defaults to all ', &
339342
' binaries for that release. ', &
340-
' test [NAME(s)] [--release] [--list] [-- ARGS] ', &
343+
' test [NAME(s)] [--release] [--list] [--runner "CMD"] [-- ARGS] ', &
341344
' Run the tests ', &
342345
' help [NAME(s)] Alternate method for displaying subcommand help ', &
343346
' list [--list] Display brief descriptions of all subcommands. ', &
@@ -350,6 +353,7 @@ subroutine set_help()
350353
' optimization flags are used. ', &
351354
' --list List candidates instead of building or running them. On ', &
352355
' the fpm(1) command this shows a brief list of subcommands.', &
356+
' --runner CMD Provides a command to prefix program execution paths. ', &
353357
' -- ARGS Arguments to pass to executables. ', &
354358
' --help Show help text and exit. Valid for all subcommands. ', &
355359
' --version Show version information and exit. Valid for all ', &
@@ -398,7 +402,7 @@ subroutine set_help()
398402
' run(1) - the fpm(1) subcommand to run project applications ', &
399403
' ', &
400404
'SYNOPSIS ', &
401-
' fpm run [NAME(s)] [--release] [-- ARGS] ', &
405+
' fpm run [NAME(s)] [--release] [--runner "CMD"] [-- ARGS] ', &
402406
' ', &
403407
' fpm run --help|--version ', &
404408
' ', &
@@ -412,12 +416,18 @@ subroutine set_help()
412416
' --release selects the optimized build instead of the debug ', &
413417
' build. ', &
414418
' --list list candidates instead of building or running them ', &
419+
' --runner CMD A command to prefix the program execution paths with. ', &
420+
' For use with utilities like valgrind(1), time(1), and ', &
421+
' other utilities that launch executables; commands that ', &
422+
' inspect the files like ldd(1), file(1), and ls(1); and ', &
423+
' ones that copy or change files like strip(1) and ', &
424+
' install(1). ', &
415425
' -- ARGS optional arguments to pass to the program(s). ', &
416426
' The same arguments are passed to all names ', &
417427
' specified. ', &
418428
' ', &
419429
'EXAMPLES ', &
420-
' run fpm(1) project applications ', &
430+
' fpm(1) "run" project applications ', &
421431
' ', &
422432
' # run default programs in /app or as specified in "fpm.toml" ', &
423433
' fpm run ', &
@@ -428,6 +438,9 @@ subroutine set_help()
428438
' # run production version of two applications ', &
429439
' fpm run prg1 prg2 --release ', &
430440
' ', &
441+
' # install executables in directory (assuming install(1) exists) ', &
442+
' fpm run -c ''install -b -m 0711 -p -t /usr/local/bin'' ', &
443+
' ', &
431444
'SEE ALSO ', &
432445
' The fpm(1) home page at https://github.com/fortran-lang/fpm ', &
433446
'' ]
@@ -589,7 +602,7 @@ subroutine set_help()
589602
' test(1) - the fpm(1) subcommand to run project tests ', &
590603
' ', &
591604
'SYNOPSIS ', &
592-
' fpm test [NAME(s)] [--release] [--list] [-- ARGS] ', &
605+
' fpm test [NAME(s)] [--release] [--list] [--runner "CMD"] [-- ARGS] ', &
593606
' ', &
594607
' fpm test --help|--version ', &
595608
' ', &
@@ -603,6 +616,12 @@ subroutine set_help()
603616
' --release selects the optimized build instead of the debug ', &
604617
' build. ', &
605618
' --list list candidates instead of building or running them ', &
619+
' --runner CMD A command to prefix the program execution paths with. ', &
620+
' For use with utilities like valgrind(1), time(1), and ', &
621+
' other utilities that launch executables; commands that ', &
622+
' inspect the files like ldd(1), file(1), and ls(1); and ', &
623+
' ones that copy or change files like strip(1) and ', &
624+
' install(1). ', &
606625
' -- ARGS optional arguments to pass to the test program(s). ', &
607626
' The same arguments are passed to all test names ', &
608627
' specified. ', &

0 commit comments

Comments
 (0)