Skip to content

Commit bc17d07

Browse files
committed
Changed behavior for run subcommand per @lkedwards suggestions
--target NAME(s) list of specific application names to execute. No name is required if only one application exists. If no name is supplied and more than one candidate exists or a name has no match a list is produced and fpm(1) exits. Simple "globbing" is supported where "?" represents any single character and "*" represents any string. Therefore a quoted asterisk '*' runs all programs.
1 parent 317a09a commit bc17d07

File tree

3 files changed

+365
-22
lines changed

3 files changed

+365
-22
lines changed

fpm/src/fpm.f90

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module fpm
2-
use fpm_strings, only: string_t, operator(.in.)
2+
use fpm_strings, only: string_t, operator(.in.), glob
33
use fpm_backend, only: build_package
44
use fpm_command_line, only: fpm_build_settings, fpm_new_settings, &
55
fpm_run_settings, fpm_install_settings, fpm_test_settings
@@ -266,7 +266,8 @@ subroutine cmd_run(settings,test)
266266

267267
do j=1,size(settings%name)
268268

269-
if (trim(settings%name(j))==exe_source%exe_name) then
269+
!*!if (trim(settings%name(j))==exe_source%exe_name) then
270+
if (glob(trim(exe_source%exe_name),trim(settings%name(j)))) then
270271

271272
found(j) = .true.
272273
exe_cmd%s = exe_target%output_file
@@ -295,14 +296,19 @@ subroutine cmd_run(settings,test)
295296
end if
296297

297298
! Check all names are valid
298-
if (any(.not.found)) then
299-
300-
write(stderr,'(A)',advance="no")'fpm::run<ERROR> specified names '
301-
do j=1,size(settings%name)
302-
if (.not.found(j)) write(stderr,'(A)',advance="no") '"'//trim(settings%name(j))//'" '
303-
end do
304-
write(stderr,'(A)') 'not found.'
305-
write(stderr,*)
299+
! or no name and found more than one file
300+
if ( any(.not.found) .or. (size(settings%name).eq.0 .and. size(executables).gt.1 .and. .not.test) ) then
301+
if(any(.not.found))then
302+
write(stderr,'(A)',advance="no")'fpm::run<ERROR> specified names '
303+
do j=1,size(settings%name)
304+
if (.not.found(j)) write(stderr,'(A)',advance="no") '"'//trim(settings%name(j))//'" '
305+
end do
306+
write(stderr,'(A)') 'not found.'
307+
write(stderr,*)
308+
else if(settings%verbose)then
309+
write(stderr,'(A)',advance="yes")'<INFO>when more than one executable is available'
310+
write(stderr,'(A)',advance="yes")' program names must be specified.'
311+
endif
306312

307313
j = 1
308314
nCol = LINE_WIDTH/col_width

fpm/src/fpm_command_line.f90

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,14 @@ subroutine set_help()
698698
' "example" can be used with this subcommand. ', &
699699
' ', &
700700
'OPTIONS ', &
701-
' --target NAME(s) optional list of specific names to execute. ', &
702-
' The default is to run all the applications in app/ ', &
703-
' or the programs listed in the "fpm.toml" file. ', &
701+
' --target NAME(s) list of specific application names to execute. ', &
702+
' No name is required if only one application exists. ', &
703+
' If no name is supplied and more than one candidate ', &
704+
' exists or a name has no match a list is produced ', &
705+
' and fpm(1) exits. ', &
706+
' Simple "globbing" is supported where "?" represents ', &
707+
' any single character and "*" represents any string. ', &
708+
' Therefore a quoted asterisk ''*'' runs all programs. ', &
704709
' --example run example programs instead of applications ', &
705710
' --release selects the optimized build instead of the debug ', &
706711
' build. ', &
@@ -717,16 +722,16 @@ subroutine set_help()
717722
'EXAMPLES ', &
718723
' fpm(1) "run" project applications ', &
719724
' ', &
720-
' # run default programs in /app or as specified in "fpm.toml" ', &
721-
' fpm run ', &
725+
' # run all default programs in /app or as specified in "fpm.toml" ', &
726+
' fpm run ''*'' ', &
722727
' ', &
723-
' # run default programs in /app or as specified in "fpm.toml" ', &
724-
' # using the compiler command "f90". ', &
728+
' # run default program using the compiler command "f90". If more ', &
729+
' # than one app exists a list displays and names must be specified. ', &
725730
' fpm run --compiler f90 ', &
726731
' ', &
727-
' # run example and demonstration programs instead of the default ', &
728-
' # application programs (specified in "fpm.toml") ', &
729-
' fpm run --example ', &
732+
' # run example demonstration programs instead of the application ', &
733+
' # programs ( defaults can be overridden in "fpm.toml"). ', &
734+
' fpm run --example ''*'' ', &
730735
' ', &
731736
' # run a specific program and pass arguments to the command ', &
732737
' fpm run mytest -- -x 10 -y 20 --title "my title line" ', &
@@ -756,7 +761,7 @@ subroutine set_help()
756761
' o src/ for modules and procedure source ', &
757762
' o app/ main program(s) for applications ', &
758763
' o test/ main program(s) and support files for project tests ', &
759-
' o example/ main program(s) for examples and demonstrations ', &
764+
' o example/ main program(s) for example programs ', &
760765
' Changed or new files found are rebuilt. The results are placed in ', &
761766
' the build/ directory. ', &
762767
' ', &

0 commit comments

Comments
 (0)