diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 4a0b8d621c..0b7fc8e057 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -59,12 +59,36 @@ pushd with_examples popd pushd many_examples -"$fpm" build + "$fpm" run --example --all test -e demo1.txt test -e demo2.txt popd +# Test building individual targets +pushd many_targets +cases=( "1" "2" "3" ) +targets=( "run" "example" "test" ) +cmdrun=( "run --target" "run --example" "test --target" ) +for j in {0..2} +do + for i in {0..2} + do + rm -f *.txt + this=${cases[$i]} + others=${cases[@]/$this} + filename=${targets[$j]}$this + echo "$filename" + "$fpm" ${cmdrun[$j]} $filename + test -e $filename.txt + for k in ${others[@]} + do + test ! -e ${targets[$k]}$k.txt + done + done +done +popd + pushd auto_discovery_off "$fpm" build "$fpm" run --target auto_discovery_off diff --git a/example_packages/many_targets/.gitignore b/example_packages/many_targets/.gitignore new file mode 100644 index 0000000000..a007feab07 --- /dev/null +++ b/example_packages/many_targets/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/example_packages/many_targets/app/run1.f90 b/example_packages/many_targets/app/run1.f90 new file mode 100644 index 0000000000..7033d98755 --- /dev/null +++ b/example_packages/many_targets/app/run1.f90 @@ -0,0 +1,6 @@ +program run1 + use file_mod + implicit none + call print_file("run",1) + stop 0 +end program run1 diff --git a/example_packages/many_targets/app/run2.f90 b/example_packages/many_targets/app/run2.f90 new file mode 100644 index 0000000000..d8eaaef29a --- /dev/null +++ b/example_packages/many_targets/app/run2.f90 @@ -0,0 +1,6 @@ +program run2 + use file_mod + implicit none + call print_file("run",2) + stop 0 +end program run2 diff --git a/example_packages/many_targets/app/run3.f90 b/example_packages/many_targets/app/run3.f90 new file mode 100644 index 0000000000..a3da040f99 --- /dev/null +++ b/example_packages/many_targets/app/run3.f90 @@ -0,0 +1,6 @@ +program run3 + use file_mod + implicit none + call print_file("run",3) + stop 0 +end program run3 diff --git a/example_packages/many_targets/example/example1.f90 b/example_packages/many_targets/example/example1.f90 new file mode 100644 index 0000000000..f8416702ce --- /dev/null +++ b/example_packages/many_targets/example/example1.f90 @@ -0,0 +1,6 @@ +program example1 + use file_mod + implicit none + call print_file("example",1) + stop 0 +end program example1 diff --git a/example_packages/many_targets/example/example2.f90 b/example_packages/many_targets/example/example2.f90 new file mode 100644 index 0000000000..ce97407da4 --- /dev/null +++ b/example_packages/many_targets/example/example2.f90 @@ -0,0 +1,6 @@ +program example2 + use file_mod + implicit none + call print_file("example",2) + stop 0 +end program example2 diff --git a/example_packages/many_targets/example/example3.f90 b/example_packages/many_targets/example/example3.f90 new file mode 100644 index 0000000000..b36a4465c3 --- /dev/null +++ b/example_packages/many_targets/example/example3.f90 @@ -0,0 +1,6 @@ +program example3 + use file_mod + implicit none + call print_file("example",3) + stop 0 +end program example3 diff --git a/example_packages/many_targets/fpm.toml b/example_packages/many_targets/fpm.toml new file mode 100644 index 0000000000..88aa8cc1e0 --- /dev/null +++ b/example_packages/many_targets/fpm.toml @@ -0,0 +1 @@ +name = "many_targets" diff --git a/example_packages/many_targets/src/file_mod.f90 b/example_packages/many_targets/src/file_mod.f90 new file mode 100644 index 0000000000..fd4368e5d9 --- /dev/null +++ b/example_packages/many_targets/src/file_mod.f90 @@ -0,0 +1,17 @@ +module file_mod + implicit none + public + contains + subroutine print_file(name,id) + character(*), intent(in) :: name + integer, intent(in) :: id + integer :: i + character(len(name)+1) :: nm + write(nm,1)name,id + open(newunit=i,file=nm//'.txt',form="formatted",action="write") + write(i, '(a)') nm + close(i) + 1 format(a,i1) + end subroutine print_file +end module file_mod + diff --git a/example_packages/many_targets/test/test1.f90 b/example_packages/many_targets/test/test1.f90 new file mode 100644 index 0000000000..cc7226b033 --- /dev/null +++ b/example_packages/many_targets/test/test1.f90 @@ -0,0 +1,6 @@ +program test1 + use file_mod + implicit none + call print_file("test",1) + stop 0 +end program test1 diff --git a/example_packages/many_targets/test/test2.f90 b/example_packages/many_targets/test/test2.f90 new file mode 100644 index 0000000000..d43252907d --- /dev/null +++ b/example_packages/many_targets/test/test2.f90 @@ -0,0 +1,6 @@ +program test2 + use file_mod + implicit none + call print_file("test",2) + stop 0 +end program test2 diff --git a/example_packages/many_targets/test/test3.f90 b/example_packages/many_targets/test/test3.f90 new file mode 100644 index 0000000000..af4a44cbfd --- /dev/null +++ b/example_packages/many_targets/test/test3.f90 @@ -0,0 +1,6 @@ +program test3 + use file_mod + implicit none + call print_file("test",3) + stop 0 +end program test3 diff --git a/src/fpm.f90 b/src/fpm.f90 index 7e3d070d5e..b162ff2827 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -769,9 +769,14 @@ logical function should_be_run(settings,run_scope,exe_target) associate(exe_source => exe_target%dependencies(1)%ptr%source) - if (size(settings%name) == 0 .or. .not.settings%list) then + if (exe_source%unit_scope/=run_scope) then + + ! Other scope + should_be_run = .false. + + elseif (size(settings%name) == 0 .or. settings%list) then - ! No list of targets + ! Run all or list all should_be_run = .true. else