Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: --target option should only run the desired target #1038

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions example_packages/many_targets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/*
6 changes: 6 additions & 0 deletions example_packages/many_targets/app/run1.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
program run1
use file_mod
implicit none
call print_file("run",1)
stop 0
end program run1
6 changes: 6 additions & 0 deletions example_packages/many_targets/app/run2.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
program run2
use file_mod
implicit none
call print_file("run",2)
stop 0
end program run2
6 changes: 6 additions & 0 deletions example_packages/many_targets/app/run3.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
program run3
use file_mod
implicit none
call print_file("run",3)
stop 0
end program run3
6 changes: 6 additions & 0 deletions example_packages/many_targets/example/example1.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
program example1
use file_mod
implicit none
call print_file("example",1)
stop 0
end program example1
6 changes: 6 additions & 0 deletions example_packages/many_targets/example/example2.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
program example2
use file_mod
implicit none
call print_file("example",2)
stop 0
end program example2
6 changes: 6 additions & 0 deletions example_packages/many_targets/example/example3.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
program example3
use file_mod
implicit none
call print_file("example",3)
stop 0
end program example3
1 change: 1 addition & 0 deletions example_packages/many_targets/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name = "many_targets"
17 changes: 17 additions & 0 deletions example_packages/many_targets/src/file_mod.f90
Original file line number Diff line number Diff line change
@@ -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

6 changes: 6 additions & 0 deletions example_packages/many_targets/test/test1.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
program test1
use file_mod
implicit none
call print_file("test",1)
stop 0
end program test1
6 changes: 6 additions & 0 deletions example_packages/many_targets/test/test2.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
program test2
use file_mod
implicit none
call print_file("test",2)
stop 0
end program test2
6 changes: 6 additions & 0 deletions example_packages/many_targets/test/test3.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
program test3
use file_mod
implicit none
call print_file("test",3)
stop 0
end program test3
9 changes: 7 additions & 2 deletions src/fpm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading