From 5f7e4e5ec4fe10b7cca8aeaadb98ab376cdedfaf Mon Sep 17 00:00:00 2001 From: LKedward Date: Sat, 19 Sep 2020 11:23:10 +0100 Subject: 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. --- fpm/src/fpm_sources.f90 | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/fpm/src/fpm_sources.f90 b/fpm/src/fpm_sources.f90 index 2c15b8c..89e0849 100644 --- a/fpm/src/fpm_sources.f90 +++ b/fpm/src/fpm_sources.f90 @@ -556,23 +556,42 @@ subroutine resolve_module_dependencies(sources) ! type(srcfile_t), intent(inout), target :: sources(:) - integer :: n_depend, i, j + type(srcfile_ptr) :: dep + + integer :: n_depend, i, pass, j do i=1,size(sources) - n_depend = size(sources(i)%modules_used) + do pass=1,2 + + n_depend = 0 + + do j=1,size(sources(i)%modules_used) + + if (sources(i)%modules_used(j)%s .in. sources(i)%modules_provided) then + ! Dependency satisfied in same file, skip + cycle + end if - allocate(sources(i)%file_dependencies(n_depend)) + dep%ptr => find_module_dependency(sources,sources(i)%modules_used(j)%s) - do j=1,n_depend + if (.not.associated(dep%ptr)) then + write(*,*) '(!) Unable to find source for module dependency: ', & + sources(i)%modules_used(j)%s + write(*,*) ' for file ',sources(i)%file_name + ! stop + end if + + n_depend = n_depend + 1 + + if (pass == 2) then + sources(i)%file_dependencies(n_depend) = dep + end if - sources(i)%file_dependencies(j)%ptr => & - find_module_dependency(sources,sources(i)%modules_used(j)%s) + end do - if (.not.associated(sources(i)%file_dependencies(j)%ptr)) then - write(*,*) '(!) Unable to find source for module dependency: ',sources(i)%modules_used(j)%s - write(*,*) ' for file ',sources(i)%file_name - ! stop + if (pass == 1) then + allocate(sources(i)%file_dependencies(n_depend)) end if end do -- cgit v1.2.3