Skip to content

Commit

Permalink
Soften the error down to a warning
Browse files Browse the repository at this point in the history
- Use with-ghc.config trick
  • Loading branch information
philderbeast committed Dec 12, 2024
1 parent 75c583f commit a589538
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ cyclicalImportMsg path@(ProjectConfigPath (duplicate :| _)) =
]

-- | A message for an import that has leading or trailing spaces.
untrimmedUriImportMsg :: ProjectConfigPath -> Doc
untrimmedUriImportMsg path =
untrimmedUriImportMsg :: Doc -> ProjectConfigPath -> Doc
untrimmedUriImportMsg intro path =
vcat
[ text "import has whitespace" <> semi
[ intro <+> text "import has leading or trailing whitespace" <> semi
, nest 2 (docProjectConfigPath path)
]

Expand Down
23 changes: 12 additions & 11 deletions cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ import Distribution.Simple.Setup
import Distribution.Simple.Utils
( debug
, lowercase
, noticeDoc
)
import Distribution.Types.CondTree
( CondBranch (..)
Expand Down Expand Up @@ -273,17 +274,17 @@ parseProjectSkeleton cacheDir httpTransport verbosity projectDir source (Project

debug verbosity $ "\nimport path, normalized\n=======================\n" ++ render (docProjectConfigPath normLocPath)

if
| isUntrimmedUriConfigPath importLocPath ->
pure . parseFail $ ParseUtils.FromString (render $ untrimmedUriImportMsg importLocPath) Nothing
| isCyclicConfigPath normLocPath ->
pure . parseFail $ ParseUtils.FromString (render $ cyclicalImportMsg normLocPath) Nothing
| otherwise -> do
normSource <- canonicalizeConfigPath projectDir source
let fs = (\z -> CondNode z [normLocPath] mempty) <$> fieldsToConfig normSource (reverse acc)
res <- parseProjectSkeleton cacheDir httpTransport verbosity projectDir importLocPath . ProjectConfigToParse =<< fetchImportConfig normLocPath
rest <- go [] xs
pure . fmap mconcat . sequence $ [fs, res, rest]
if isCyclicConfigPath normLocPath
then pure . parseFail $ ParseUtils.FromString (render $ cyclicalImportMsg normLocPath) Nothing
else do
when
(isUntrimmedUriConfigPath importLocPath)
(noticeDoc verbosity $ untrimmedUriImportMsg (Disp.text "Warning:") importLocPath)
normSource <- canonicalizeConfigPath projectDir source
let fs = (\z -> CondNode z [normLocPath] mempty) <$> fieldsToConfig normSource (reverse acc)
res <- parseProjectSkeleton cacheDir httpTransport verbosity projectDir importLocPath . ProjectConfigToParse =<< fetchImportConfig normLocPath
rest <- go [] xs
pure . fmap mconcat . sequence $ [fs, res, rest]
(ParseUtils.Section l "if" p xs') -> do
subpcs <- go [] xs'
let fs = singletonProjectConfigSkeleton <$> fieldsToConfig source (reverse acc)
Expand Down
28 changes: 22 additions & 6 deletions cabal-testsuite/PackageTests/UntrimmedImport/cabal.out
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
# checking project import with trailing space
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/trailing-space.project:
import has whitespace;
Warning: import has leading or trailing whitespace;
'https://www.stackage.org/nightly-2024-12-05/cabal.config '
imported by: trailing-space.project
Configuration is affected by the following files:
- https://www.stackage.org/nightly-2024-12-05/cabal.config
imported by: trailing-space.project
- trailing-space.project
- with-ghc.config
imported by: trailing-space.project
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- my-0.1 (lib:my) (first run)
# checking project import with tabs and spaces
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/tabs-and-spaces.project:
import has whitespace;
Warning: import has leading or trailing whitespace;
'https://www.stackage.org/nightly-2024-12-05/cabal.config '
imported by: tabs-and-spaces.project
Configuration is affected by the following files:
- https://www.stackage.org/nightly-2024-12-05/cabal.config
imported by: tabs-and-spaces.project
- tabs-and-spaces.project
- with-ghc.config
imported by: tabs-and-spaces.project
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- my-0.1 (lib:my) (first run)
8 changes: 5 additions & 3 deletions cabal-testsuite/PackageTests/UntrimmedImport/cabal.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ main = cabalTest . recordMode RecordMarked $ do
let log = recordHeader . pure

log "checking project import with trailing space"
trailing <- fails $ cabal' "v2-build" [ "--project-file=trailing-space.project" ]
assertOutputContains "import has whitespace" trailing
trailing <- cabal' "v2-build" [ "--dry-run", "--project-file=trailing-space.project" ]
assertOutputContains "import has leading or trailing whitespace" trailing
assertOutputContains "'https://www.stackage.org/nightly-2024-12-05/cabal.config '" trailing

log "checking project import with tabs and spaces"
fails $ cabal "v2-build" [ "--project-file=tabs-and-spaces.project" ]
cabal "v2-build" [ "--dry-run", "--project-file=tabs-and-spaces.project" ]

return ()
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/UntrimmedImport/my.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: my
version: 0.1
license: BSD3
cabal-version: >= 1.2
build-type: Simple

library
exposed-modules: Foo
build-depends: base
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
optional-packages: .
packages: .
import: https://www.stackage.org/nightly-2024-12-05/cabal.config
import: with-ghc.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
optional-packages: .
packages: .
import: https://www.stackage.org/nightly-2024-12-05/cabal.config
import: with-ghc.config
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/UntrimmedImport/with-ghc.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- WARNING: Override the `with-compiler: ghc-x.y.z` of the stackage import, of
-- https://www.stackage.org/nightly-yyyy-mm-dd/cabal.config. Otherwise tests
-- will fail with:
-- -Error: [Cabal-5490]
-- -Cannot find the program 'ghc'. User-specified path 'ghc-x.y.z' does not
-- refer to an executable and the program is not on the system path.
with-compiler: ghc

0 comments on commit a589538

Please sign in to comment.