Skip to content

Commit 5f7e4e5

Browse files
committed
Update: module resolution to ignore same file dependency
If a module dependency is satisfied in the same file, it is not added to file_dependencies. Use two-pass procedure to count the number of actual file_dependencies required for module resolution.
1 parent 0f0a191 commit 5f7e4e5

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

fpm/src/fpm_sources.f90

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -556,23 +556,42 @@ subroutine resolve_module_dependencies(sources)
556556
!
557557
type(srcfile_t), intent(inout), target :: sources(:)
558558

559-
integer :: n_depend, i, j
559+
type(srcfile_ptr) :: dep
560+
561+
integer :: n_depend, i, pass, j
560562

561563
do i=1,size(sources)
562564

563-
n_depend = size(sources(i)%modules_used)
565+
do pass=1,2
566+
567+
n_depend = 0
568+
569+
do j=1,size(sources(i)%modules_used)
570+
571+
if (sources(i)%modules_used(j)%s .in. sources(i)%modules_provided) then
572+
! Dependency satisfied in same file, skip
573+
cycle
574+
end if
564575

565-
allocate(sources(i)%file_dependencies(n_depend))
576+
dep%ptr => find_module_dependency(sources,sources(i)%modules_used(j)%s)
566577

567-
do j=1,n_depend
578+
if (.not.associated(dep%ptr)) then
579+
write(*,*) '(!) Unable to find source for module dependency: ', &
580+
sources(i)%modules_used(j)%s
581+
write(*,*) ' for file ',sources(i)%file_name
582+
! stop
583+
end if
584+
585+
n_depend = n_depend + 1
586+
587+
if (pass == 2) then
588+
sources(i)%file_dependencies(n_depend) = dep
589+
end if
568590

569-
sources(i)%file_dependencies(j)%ptr => &
570-
find_module_dependency(sources,sources(i)%modules_used(j)%s)
591+
end do
571592

572-
if (.not.associated(sources(i)%file_dependencies(j)%ptr)) then
573-
write(*,*) '(!) Unable to find source for module dependency: ',sources(i)%modules_used(j)%s
574-
write(*,*) ' for file ',sources(i)%file_name
575-
! stop
593+
if (pass == 1) then
594+
allocate(sources(i)%file_dependencies(n_depend))
576595
end if
577596

578597
end do

0 commit comments

Comments
 (0)