Skip to content

Commit b1f0970

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 b1f0970

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-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: 32 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
@@ -97,7 +98,7 @@ subroutine get_command_line_settings(cmd_settings)
9798
select case(trim(cmdarg))
9899

99100
case('run')
100-
call set_args('--list F --release F --',help_run,version_text)
101+
call set_args('--list:l F --release:r F --runner:c " " --',help_run,version_text)
101102

102103
if( size(unnamed) .gt. 1 )then
103104
names=unnamed(2:)
@@ -107,17 +108,17 @@ subroutine get_command_line_settings(cmd_settings)
107108

108109
allocate(fpm_run_settings :: cmd_settings)
109110
cmd_settings=fpm_run_settings( name=names, list=lget('list'), &
110-
& release=lget('release'), args=remaining )
111+
& release=lget('release'), args=remaining ,runner=sget('runner') )
111112

112113
case('build')
113-
call set_args( '--release F --list F --',help_build,version_text )
114+
call set_args( '--release:r F --list:l F --',help_build,version_text )
114115

115116
allocate( fpm_build_settings :: cmd_settings )
116117
cmd_settings=fpm_build_settings( release=lget('release'), &
117118
& list=lget('list') )
118119

119120
case('new')
120-
call set_args(' --src F --lib F --app F --test F --backfill F', &
121+
call set_args(' --src:s F --lib:l F --app:a F --test:t F --backfill:b F', &
121122
& help_new, version_text)
122123
select case(size(unnamed))
123124
case(1)
@@ -203,17 +204,17 @@ subroutine get_command_line_settings(cmd_settings)
203204
call printhelp(help_text)
204205

205206
case('install')
206-
call set_args('--release F ', help_install, version_text)
207+
call set_args('--release:r F ', help_install, version_text)
207208

208209
allocate(fpm_install_settings :: cmd_settings)
209210
case('list')
210-
call set_args(' --list F', help_list, version_text)
211+
call set_args(' --list:l F', help_list, version_text)
211212
call printhelp(help_list_nodash)
212213
if(lget('list'))then
213214
call printhelp(help_list_dash)
214215
endif
215216
case('test')
216-
call set_args('--list F --release F --',help_test,version_text)
217+
call set_args('--list:l F --release:r F --runner:c " " --',help_test,version_text)
217218

218219
if( size(unnamed) .gt. 1 )then
219220
names=unnamed(2:)
@@ -223,11 +224,11 @@ subroutine get_command_line_settings(cmd_settings)
223224

224225
allocate(fpm_test_settings :: cmd_settings)
225226
cmd_settings=fpm_test_settings( name=names, list=lget('list'), &
226-
& release=lget('release'), args=remaining )
227+
& release=lget('release'), args=remaining ,runner=sget('runner') )
227228

228229
case default
229230

230-
call set_args(' --list F', help_fpm, version_text)
231+
call set_args(' --list:l F', help_fpm, version_text)
231232
! Note: will not get here if --version or --usage or --help
232233
! is present on commandline
233234
help_text=help_usage
@@ -296,8 +297,8 @@ subroutine set_help()
296297
' help [NAME(s)] ', &
297298
' new NAME [--lib|--src] [--app] [--test] [--backfill] ', &
298299
' list [--list] ', &
299-
' run [NAME(s)] [--release] [--list] [-- ARGS] ', &
300-
' test [NAME(s)] [--release] [--list] [-- ARGS] ', &
300+
' run [NAME(s)] [--release] [--runner "CMD"] [--list] [-- ARGS] ', &
301+
' test [NAME(s)] [--release] [--runner "CMD"] [--list] [-- ARGS] ', &
301302
' ']
302303
help_usage=[character(len=80) :: &
303304
'' ]
@@ -334,10 +335,10 @@ subroutine set_help()
334335
' new NAME [--lib|--src] [--app] [--test] [--backfill] ', &
335336
' Create a new Fortran package directory ', &
336337
' with sample files ', &
337-
' run [NAME(s)] [--release] [--list] [-- ARGS] ', &
338+
' run [NAME(s)] [--release] [--list] [--runner "CMD"][-- ARGS] ', &
338339
' Run the local package binaries. defaults to all ', &
339340
' binaries for that release. ', &
340-
' test [NAME(s)] [--release] [--list] [-- ARGS] ', &
341+
' test [NAME(s)] [--release] [--list] [--runner "CMD"] [-- ARGS] ', &
341342
' Run the tests ', &
342343
' help [NAME(s)] Alternate method for displaying subcommand help ', &
343344
' list [--list] Display brief descriptions of all subcommands. ', &
@@ -350,6 +351,7 @@ subroutine set_help()
350351
' optimization flags are used. ', &
351352
' --list List candidates instead of building or running them. On ', &
352353
' the fpm(1) command this shows a brief list of subcommands.', &
354+
' --runner A command to prefix the program execution paths with. ', &
353355
' -- ARGS Arguments to pass to executables. ', &
354356
' --help Show help text and exit. Valid for all subcommands. ', &
355357
' --version Show version information and exit. Valid for all ', &
@@ -398,7 +400,7 @@ subroutine set_help()
398400
' run(1) - the fpm(1) subcommand to run project applications ', &
399401
' ', &
400402
'SYNOPSIS ', &
401-
' fpm run [NAME(s)] [--release] [-- ARGS] ', &
403+
' fpm run [NAME(s)] [--release] [--runner "CMD"] [-- ARGS] ', &
402404
' ', &
403405
' fpm run --help|--version ', &
404406
' ', &
@@ -412,12 +414,17 @@ subroutine set_help()
412414
' --release selects the optimized build instead of the debug ', &
413415
' build. ', &
414416
' --list list candidates instead of building or running them ', &
417+
' --runner A command to prefix the program execution paths with. ', &
418+
' For use with utilities like valgrind(1), time(1), and ', &
419+
' other utilities that launch executables; commands that ', &
420+
' inspect the files like ldd(1), file(1), and ls(1); and ', &
421+
' that copy or change the files like strip(1) and install(1).', &
415422
' -- ARGS optional arguments to pass to the program(s). ', &
416423
' The same arguments are passed to all names ', &
417424
' specified. ', &
418425
' ', &
419426
'EXAMPLES ', &
420-
' run fpm(1) project applications ', &
427+
' fpm(1) "run" project applications ', &
421428
' ', &
422429
' # run default programs in /app or as specified in "fpm.toml" ', &
423430
' fpm run ', &
@@ -428,6 +435,9 @@ subroutine set_help()
428435
' # run production version of two applications ', &
429436
' fpm run prg1 prg2 --release ', &
430437
' ', &
438+
' # install executables in directory (assuming install(1) exists) ', &
439+
' fpm run -c ''install -b -m 0711 -p -t /usr/local/bin'' ', &
440+
' ', &
431441
'SEE ALSO ', &
432442
' The fpm(1) home page at https://github.com/fortran-lang/fpm ', &
433443
'' ]
@@ -589,7 +599,7 @@ subroutine set_help()
589599
' test(1) - the fpm(1) subcommand to run project tests ', &
590600
' ', &
591601
'SYNOPSIS ', &
592-
' fpm test [NAME(s)] [--release] [--list] [-- ARGS] ', &
602+
' fpm test [NAME(s)] [--release] [--list] [--runner "CMD"] [-- ARGS] ', &
593603
' ', &
594604
' fpm test --help|--version ', &
595605
' ', &
@@ -603,6 +613,11 @@ subroutine set_help()
603613
' --release selects the optimized build instead of the debug ', &
604614
' build. ', &
605615
' --list list candidates instead of building or running them ', &
616+
' --runner A command to prefix the program execution paths with. ', &
617+
' For use with utilities like valgrind(1), time(1), and ', &
618+
' other utilities that launch executables; commands that ', &
619+
' inspect the files like ldd(1), file(1), and ls(1); and that', &
620+
' copy or change the files like strip(1) and install(1). ', &
606621
' -- ARGS optional arguments to pass to the test program(s). ', &
607622
' The same arguments are passed to all test names ', &
608623
' specified. ', &

0 commit comments

Comments
 (0)