Skip to content

Commit 285925c

Browse files
committed
Create method check_modules to check for duplicate modules
1 parent 8cbbd80 commit 285925c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

fpm/src/fpm.f90

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,45 @@ subroutine build_model(model, settings, package, error)
154154
end do
155155
if (allocated(error)) return
156156

157+
! Check for duplicate modules
158+
call check_modules(model)
157159
end subroutine build_model
158160

161+
! Check for duplicate modules
162+
subroutine check_modules(model)
163+
type(fpm_model_t), intent(in) :: model
164+
integer :: maxsize
165+
integer :: i,j,k,modi
166+
type(string_t), allocatable :: modules(:)
167+
! Initialise the size of array
168+
maxsize = 0
169+
! Get number of modules provided by each source file
170+
do i=1,size(model%packages(1)%sources)
171+
if (allocated(model%packages(1)%sources(j)%modules_provided)) then
172+
maxsize = maxsize + size(model%packages(1)%sources(i)%modules_provided)
173+
end if
174+
end do
175+
! Allocate array to contain distinct names of modules
176+
allocate(modules(1:maxsize))
177+
178+
! Initialise index to point at start of the newly allocated array
179+
modi = 1
180+
181+
! Loop through modules provided by each source file
182+
! Add it to the array if it is not already there
183+
! Otherwise print out warning about duplicates
184+
do j=1,size(model%packages(1)%sources)
185+
if (allocated(model%packages(1)%sources(j)%modules_provided)) then
186+
do k=1,size(model%packages(1)%sources(j)%modules_provided)
187+
if (model%packages(1)%sources(j)%modules_provided(k)%s.in.modules) then
188+
print *,"Warning: Module ",model%packages(1)%sources(j)%modules_provided(k)%s," is duplicate"
189+
else
190+
modules(modi) = model%packages(1)%sources(j)%modules_provided(k)
191+
end if
192+
end do
193+
end if
194+
end do
195+
end subroutine check_modules
159196

160197
subroutine cmd_build(settings)
161198
type(fpm_build_settings), intent(in) :: settings

0 commit comments

Comments
 (0)