-
Notifications
You must be signed in to change notification settings - Fork 116
Fix for Issue #396 - Duplicate module definitions #412
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 for Issue #396 - Duplicate module definitions #412
Conversation
milancurcic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kubajj! I left a few suggestions.
LKedward
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff, thanks Jakub @kubajj, in addition to Milan's comments I spotted a few more things (see my comments).
|
During the monthly call, you were talking about rebasing and squashing. Should I do it? |
|
Should this PR include a test case with definition of duplicate modules? @LKedward |
|
Looking good so far @kubajj! I don't think there's any pressing need to rebase this branch currently.
Agreed yes we should put some unit tests in for this. @kubajj do you want to have a look at |
Co-authored-by: Laurence Kedward <[email protected]>
@LKedward For creating the different scenarios, should I add source files that would have duplicate modules and load them as in subroutine test_library_module_use or is there another way how to do it? |
|
No need to write actual fortran source files for these tests, just like the other tests in Here's an example unit test to use: subroutine test_package_module_duplicates(error)
type(error_t), allocatable, intent(out) :: error
type(fpm_model_t) :: model
logical :: duplicates_found
allocate(model%packages(1))
allocate(model%packages(1)%sources(2))
model%packages(1)%sources(1) = new_test_source(FPM_UNIT_MODULE,file_name="src/my_mod_1.f90", &
scope = FPM_SCOPE_LIB, provides=[string_t('my_mod_1')])
model%packages(1)%sources(2) = new_test_source(FPM_UNIT_MODULE,file_name="src/subdir/my_mod_1.f90", &
scope = FPM_SCOPE_LIB, provides=[string_t('my_mod_1')])
call check_modules_for_duplicates(model, duplicates_found)
if (duplicates_found) then
call test_failed(error,'Duplicate modules found')
return
end if
end subroutine test_package_module_duplicates(The filename here doesn't matter, the file doesn't need to exist, it is used for other tests.) Then you just need to add |
…Warning, add a message to error stop
|
@LKedward Oh, this is brilliant. What did you mean by different source types in the list of possible scenarios? |
LKedward
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work Jakub @kubajj. This all looks good 👍 I've left two minor comments, once those are addressed I think this will be good to merge!
What did you mean by different source types in the list of possible scenarios?
I think I meant like FPM_UNIT_MODULE/FPM_UNIT_PROGRAM etc. but don't worry I don't think that matters for these changes. The tests added here look good as they are.
fpm/src/fpm.f90
Outdated
| if (allocated(model%packages(k)%sources(l)%modules_provided)) then | ||
| do m=1,size(model%packages(k)%sources(l)%modules_provided) | ||
| if (model%packages(k)%sources(l)%modules_provided(m)%s.in.modules(:modi-1)) then | ||
| write(error_unit, *) "Warning: Module ",model%packages(k)%sources(l)%modules_provided(m)%s," is a duplicate" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be useful to also print out which file the duplicate has been found in here
(model%packages(k)%sources(l)%file_name)
| & new_unittest("package-with-duplicates-in-same-source", & | ||
| test_package_module_duplicates_same_source, should_fail=.true.), & |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| & new_unittest("package-with-duplicates-in-same-source", & | |
| test_package_module_duplicates_same_source, should_fail=.true.), & |
I think these lines have been copy-pasted accidentally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
|
I'll go ahead and merge before we start pruning the Haskell version from this repository. |
Create a new subroutine called right at the end of the build model subroutine. This subroutine loops through modules provided by each source file and checks for duplicates.