Skip to content

Fix submodule shaking #704

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

Merged
merged 3 commits into from
Jun 12, 2022
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
2 changes: 0 additions & 2 deletions ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ test ! -e ./build/gfortran_*/submodule_tree_shake/src_parent_unused.f90.o
test ! -e ./build/gfortran_*/submodule_tree_shake/src_parent_unused.f90.o.log
test ! -e ./build/gfortran_*/submodule_tree_shake/src_child_unused.f90.o
test ! -e ./build/gfortran_*/submodule_tree_shake/src_child_unused.f90.o.log
test ! -e ./build/gfortran_*/submodule_tree_shake/src_grandchild.f90.o
test ! -e ./build/gfortran_*/submodule_tree_shake/src_grandchild.f90.o.log
popd

pushd version_file
Expand Down
2 changes: 1 addition & 1 deletion example_packages/submodule_tree_shake/src/child1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ end function my_fun
contains

module procedure my_sub1
a = 1
a = my_fun()
end procedure my_sub1

end submodule child1
1 change: 1 addition & 0 deletions src/fpm_source_parsing.f90
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ function parse_sequence(string,t1,t2,t3,t4) result(found)
select case(token_n)
case(1)
incr = len(t1)
if (pos+incr-1>n) return
match = string(pos:pos+incr-1) == t1
case(2)
if (.not.present(t2)) exit
Expand Down
34 changes: 18 additions & 16 deletions src/fpm_targets.f90
Original file line number Diff line number Diff line change
Expand Up @@ -615,25 +615,27 @@ recursive subroutine collect_used_modules(target)
end if

if (allocated(target%source)) then
do j=1,size(target%source%modules_used)

if (.not.(target%source%modules_used(j)%s .in. modules_used)) then

modules_used = [modules_used, target%source%modules_used(j)]

! Recurse into child submodules
do k=1,size(targets)
if (allocated(targets(k)%ptr%source)) then
if (targets(k)%ptr%source%unit_type == FPM_UNIT_SUBMODULE) then
if (target%source%modules_used(j)%s .in. targets(k)%ptr%source%parent_modules) then
call collect_used_modules(targets(k)%ptr)
end if
end if
end if
end do

! Add modules from this target and from any of it's children submodules
do j=1,size(target%source%modules_provided)

if (.not.(target%source%modules_provided(j)%s .in. modules_used)) then

modules_used = [modules_used, target%source%modules_provided(j)]

end if

! Recurse into child submodules
do k=1,size(targets)
if (allocated(targets(k)%ptr%source)) then
if (targets(k)%ptr%source%unit_type == FPM_UNIT_SUBMODULE) then
if (target%source%modules_provided(j)%s .in. targets(k)%ptr%source%parent_modules) then
call collect_used_modules(targets(k)%ptr)
end if
end if
end if
end do

end do
end if

Expand Down