Skip to content

Commit

Permalink
Share implement of duplicate and cyclical messages
Browse files Browse the repository at this point in the history
  • Loading branch information
philderbeast committed Oct 22, 2024
1 parent 483c9f4 commit 1cea80f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,20 @@ docProjectConfigPaths :: [ProjectConfigPath] -> Doc
docProjectConfigPaths ps = vcat
[ text "-" <+> text p | ProjectConfigPath (p :| _) <- ps ]

-- | A message for a cyclical import, assuming the head of the path is the
-- duplicate.
cyclicalImportMsg :: ProjectConfigPath -> Doc
cyclicalImportMsg path@(ProjectConfigPath (duplicate :| _)) =
vcat
[ text "cyclical import of" <+> text duplicate <> semi
, nest 2 (docProjectConfigPath path)
]
-- | A message for a cyclical import, a "cyclical import of".
cyclicalImportMsg :: ProjectConfigPath -> [(FilePath, ProjectConfigPath)] -> Doc
cyclicalImportMsg path@(ProjectConfigPath (duplicate :| _)) = seenImportMsg "cyclical" duplicate path

-- | A message for a duplicate import. If a check for cyclical imports has
-- already been made then this would report a duplicate import by two different
-- paths.
-- | A message for a duplicate import, a "duplicate import of". If a check for
-- cyclical imports has already been made then this would report a duplicate
-- import by two different paths.
duplicateImportMsg :: FilePath -> ProjectConfigPath -> [(FilePath, ProjectConfigPath)] -> Doc
duplicateImportMsg duplicate path seenImportsBy =
duplicateImportMsg = seenImportMsg "duplicate"

seenImportMsg :: String -> FilePath -> ProjectConfigPath -> [(FilePath, ProjectConfigPath)] -> Doc
seenImportMsg seen duplicate path seenImportsBy =
vcat
[ text "duplicate import of" <+> text duplicate <> semi
[ text seen <+> text "import of" <+> text duplicate <> semi
, nest 2 (docProjectConfigPath path)
, nest 2 $
vcat
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ parseProjectSkeleton cacheDir httpTransport verbosity importsBy projectDir sourc

if
| isCyclicConfigPath normLocPath ->
pure . parseFail $ ParseUtils.FromString (render $ duplicateImportMsg "cyclical (duplicate)" uniqueImport normLocPath seenImportsBy) Nothing
pure . parseFail $ ParseUtils.FromString (render $ cyclicalImportMsg normLocPath seenImportsBy) Nothing
| uniqueImport `elem` seenImports -> do
pure . parseFail $ ParseUtils.FromString (render $ duplicateImportMsg "duplicate" uniqueImport normLocPath seenImportsBy) Nothing
pure . parseFail $ ParseUtils.FromString (render $ duplicateImportMsg uniqueImport normLocPath seenImportsBy) Nothing
| otherwise -> do
normSource <- canonicalizeConfigPath projectDir source
let fs = (\z -> CondNode z [normLocPath] mempty) <$> fieldsToConfig normSource (reverse acc)
Expand Down
18 changes: 9 additions & 9 deletions cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ Warning: The directory <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>/incoming
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-0-self.project:
cyclical (duplicate) import of cyclical-0-self.project;
cyclical import of cyclical-0-self.project;
cyclical-0-self.project
imported by: cyclical-0-self.project
cyclical-0-self.project
# checking cyclical with hops; out and back
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-1-out-back.project:
cyclical (duplicate) import of cyclical-1-out-back.project;
cyclical import of cyclical-1-out-back.project;
cyclical-1-out-back.project
imported by: cyclical-1-out-back.config
imported by: cyclical-1-out-back.project
Expand All @@ -31,7 +31,7 @@ cyclical (duplicate) import of cyclical-1-out-back.project;
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-1-out-self.project:
cyclical (duplicate) import of cyclical-1-out-self.config;
cyclical import of cyclical-1-out-self.config;
cyclical-1-out-self.config
imported by: cyclical-1-out-self.config
imported by: cyclical-1-out-self.project
Expand All @@ -41,7 +41,7 @@ cyclical (duplicate) import of cyclical-1-out-self.config;
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-2-out-out-backback.project:
cyclical (duplicate) import of cyclical-2-out-out-backback.project;
cyclical import of cyclical-2-out-out-backback.project;
cyclical-2-out-out-backback.project
imported by: cyclical-2-out-out-backback-b.config
imported by: cyclical-2-out-out-backback-a.config
Expand All @@ -51,7 +51,7 @@ cyclical (duplicate) import of cyclical-2-out-out-backback.project;
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-2-out-out-back.project:
cyclical (duplicate) import of cyclical-2-out-out-back-a.config;
cyclical import of cyclical-2-out-out-back-a.config;
cyclical-2-out-out-back-a.config
imported by: cyclical-2-out-out-back-b.config
imported by: cyclical-2-out-out-back-a.config
Expand All @@ -62,7 +62,7 @@ cyclical (duplicate) import of cyclical-2-out-out-back-a.config;
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-2-out-out-self.project:
cyclical (duplicate) import of cyclical-2-out-out-self-b.config;
cyclical import of cyclical-2-out-out-self-b.config;
cyclical-2-out-out-self-b.config
imported by: cyclical-2-out-out-self-b.config
imported by: cyclical-2-out-out-self-a.config
Expand All @@ -86,7 +86,7 @@ Up to date
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-same-filename-out-out-self.project:
cyclical (duplicate) import of same-filename/cyclical-same-filename-out-out-self.config;
cyclical import of same-filename/cyclical-same-filename-out-out-self.config;
same-filename/cyclical-same-filename-out-out-self.config
imported by: same-filename/cyclical-same-filename-out-out-self.config
imported by: cyclical-same-filename-out-out-self.config
Expand All @@ -98,7 +98,7 @@ cyclical (duplicate) import of same-filename/cyclical-same-filename-out-out-self
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-same-filename-out-out-backback.project:
cyclical (duplicate) import of cyclical-same-filename-out-out-backback.project;
cyclical import of cyclical-same-filename-out-out-backback.project;
cyclical-same-filename-out-out-backback.project
imported by: same-filename/cyclical-same-filename-out-out-backback.config
imported by: cyclical-same-filename-out-out-backback.config
Expand All @@ -108,7 +108,7 @@ cyclical (duplicate) import of cyclical-same-filename-out-out-backback.project;
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-same-filename-out-out-back.project:
cyclical (duplicate) import of cyclical-same-filename-out-out-back.config;
cyclical import of cyclical-same-filename-out-out-back.config;
cyclical-same-filename-out-out-back.config
imported by: same-filename/cyclical-same-filename-out-out-back.config
imported by: cyclical-same-filename-out-out-back.config
Expand Down

0 comments on commit 1cea80f

Please sign in to comment.