-
Notifications
You must be signed in to change notification settings - Fork 714
handle conditionals in duplicate module checks #7616
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,7 @@ checkPackage gpkg mpkg = | |
++ checkUnicodeXFields gpkg | ||
++ checkPathsModuleExtensions pkg | ||
++ checkSetupVersions gpkg | ||
++ checkDuplicateModules gpkg | ||
where | ||
pkg = fromMaybe (flattenPackageDescription gpkg) mpkg | ||
|
||
|
@@ -241,13 +242,8 @@ checkLibrary :: PackageDescription -> Library -> [PackageCheck] | |
checkLibrary pkg lib = | ||
catMaybes [ | ||
|
||
check (not (null moduleDuplicates)) $ | ||
PackageBuildImpossible $ | ||
"Duplicate modules in library: " | ||
++ commaSep (map prettyShow moduleDuplicates) | ||
|
||
-- TODO: This check is bogus if a required-signature was passed through | ||
, check (null (explicitLibModules lib) && null (reexportedModules lib)) $ | ||
check (null (explicitLibModules lib) && null (reexportedModules lib)) $ | ||
PackageDistSuspiciousWarn $ | ||
showLibraryName (libName lib) ++ " does not expose any modules" | ||
|
||
|
@@ -278,10 +274,6 @@ checkLibrary pkg lib = | |
| specVersion pkg >= ver = Nothing | ||
| otherwise = check cond pc | ||
|
||
-- TODO: not sure if this check is always right in Backpack | ||
moduleDuplicates = dups (explicitLibModules lib ++ | ||
map moduleReexportName (reexportedModules lib)) | ||
|
||
allExplicitIncludes :: L.HasBuildInfo a => a -> [FilePath] | ||
allExplicitIncludes x = view L.includes x ++ view L.installIncludes x | ||
|
||
|
@@ -307,11 +299,6 @@ checkExecutable pkg exe = | |
"The package uses a C/C++/obj-C source file for the 'main-is' field. " | ||
++ "To use this feature you must specify 'cabal-version: >= 1.18'." | ||
|
||
, check (not (null moduleDuplicates)) $ | ||
PackageBuildImpossible $ | ||
"Duplicate modules in executable '" ++ prettyShow (exeName exe) ++ "': " | ||
++ commaSep (map prettyShow moduleDuplicates) | ||
|
||
-- check that all autogen-modules appear on other-modules | ||
, check | ||
(not $ and $ map (flip elem (exeModules exe)) (exeModulesAutogen exe)) $ | ||
|
@@ -324,8 +311,6 @@ checkExecutable pkg exe = | |
(not $ and $ map (flip elem (view L.includes exe)) (view L.autogenIncludes exe)) $ | ||
PackageBuildImpossible "An include in 'autogen-includes' is not in 'includes'." | ||
] | ||
where | ||
moduleDuplicates = dups (exeModules exe) | ||
|
||
checkTestSuite :: PackageDescription -> TestSuite -> [PackageCheck] | ||
checkTestSuite pkg test = | ||
|
@@ -345,11 +330,6 @@ checkTestSuite pkg test = | |
++ commaSep (map prettyShow knownTestTypes) | ||
_ -> Nothing | ||
|
||
, check (not $ null moduleDuplicates) $ | ||
PackageBuildImpossible $ | ||
"Duplicate modules in test suite '" ++ prettyShow (testName test) ++ "': " | ||
++ commaSep (map prettyShow moduleDuplicates) | ||
|
||
, check mainIsWrongExt $ | ||
PackageBuildImpossible $ | ||
"The 'main-is' field must specify a '.hs' or '.lhs' file " | ||
|
@@ -374,8 +354,6 @@ checkTestSuite pkg test = | |
PackageBuildImpossible "An include in 'autogen-includes' is not in 'includes'." | ||
] | ||
where | ||
moduleDuplicates = dups $ testModules test | ||
|
||
mainIsWrongExt = case testInterface test of | ||
TestSuiteExeV10 _ f -> not $ fileExtensionSupportedLanguage f | ||
_ -> False | ||
|
@@ -402,11 +380,6 @@ checkBenchmark _pkg bm = | |
++ commaSep (map prettyShow knownBenchmarkTypes) | ||
_ -> Nothing | ||
|
||
, check (not $ null moduleDuplicates) $ | ||
PackageBuildImpossible $ | ||
"Duplicate modules in benchmark '" ++ prettyShow (benchmarkName bm) ++ "': " | ||
++ commaSep (map prettyShow moduleDuplicates) | ||
|
||
, check mainIsWrongExt $ | ||
PackageBuildImpossible $ | ||
"The 'main-is' field must specify a '.hs' or '.lhs' file " | ||
|
@@ -425,8 +398,6 @@ checkBenchmark _pkg bm = | |
PackageBuildImpossible "An include in 'autogen-includes' is not in 'includes'." | ||
] | ||
where | ||
moduleDuplicates = dups $ benchmarkModules bm | ||
|
||
mainIsWrongExt = case benchmarkInterface bm of | ||
BenchmarkExeV10 _ f -> takeExtension f `notElem` [".hs", ".lhs"] | ||
_ -> False | ||
|
@@ -2158,6 +2129,29 @@ checkSetupVersions pkg = | |
++ "not sure what upper bound to use then use the next major " | ||
++ "version." | ||
|
||
checkDuplicateModules :: GenericPackageDescription -> [PackageCheck] | ||
checkDuplicateModules pkg = | ||
concatMap checkLib (maybe id (:) (condLibrary pkg) . map snd $ condSubLibraries pkg) | ||
++ concatMap checkExe (map snd $ condExecutables pkg) | ||
++ concatMap checkTest (map snd $ condTestSuites pkg) | ||
++ concatMap checkBench (map snd $ condBenchmarks pkg) | ||
where | ||
-- the duplicate modules check is has not been thoroughly vetted for backpack | ||
checkLib = checkDups "library" (\l -> explicitLibModules l ++ map moduleReexportName (reexportedModules l)) | ||
checkExe = checkDups "executable" exeModules | ||
checkTest = checkDups "test suite" testModules | ||
checkBench = checkDups "benchmark" benchmarkModules | ||
checkDups s getModules t = | ||
let libMap = foldCondTree Map.empty | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why such an enormous indent? (Also, two spaces after arrow on the line below, but only one space before comments (feel free to ignore).) |
||
(\(_,v) -> Map.fromListWith (+) . map (\x -> (x,(1::Int))) $ getModules v ) | ||
(Map.unionWith (+)) -- if a module may occur in nonexclusive branches count it twice | ||
(Map.unionWith max) -- a module occurs the max of times it might appear in exclusive branches | ||
t | ||
dupLibs = Map.keys $ Map.filter (>1) libMap | ||
in if null dupLibs | ||
then [] | ||
else [PackageBuildImpossible $ "Duplicate modules in " ++ s ++ ": " ++ commaSep (map prettyShow dupLibs)] | ||
|
||
-- ------------------------------------------------------------ | ||
-- * Utils | ||
-- ------------------------------------------------------------ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
synopsis: Handle conditionals in duplicate module checks | ||
packages: Cabal | ||
prs: #7616 | ||
issues: #4629 #7525 | ||
|
||
description: { | ||
|
||
Improves `cabal check` logic for duplicate modules to take into account conditional branches. If a module appears on both sides of an `if/else` clause in a cabal file, it is now correctly not reported as a duplicate. | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We can leave a TODO for that in the issues list if anyone wants to check it out.
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.
this was me migrating the old comment -- the current logic is no worse than before, but i didn't want to lose a potential warning here :-)