Skip to content

Refactor/before import warning#11773

Open
philderbeast wants to merge 13 commits intohaskell:masterfrom
cabalism:refactor/before-import-warning
Open

Refactor/before import warning#11773
philderbeast wants to merge 13 commits intohaskell:masterfrom
cabalism:refactor/before-import-warning

Conversation

@philderbeast
Copy link
Copy Markdown
Collaborator

@philderbeast philderbeast commented Apr 30, 2026

Split from #10933, the refactoring and the sorting changes without the duplicate import by alternate paths detection, as requested by @ulysses4ever.

  • Add a new module cabal-install/src/Distribution/Client/ProjectConfig/Import.hs and move some stuff there from cabal-install-solver/src/Distribution/Solver/Types/ProjectConfigPath.hs that was only ever used in cabal-install.

For messages, I added some doctests and ended up with two ways of comparing ProjectConfigPath.

-- | A comparison that puts projects first, URLs last and sorts the other paths
-- lexically.
compareLexicographically :: ProjectConfigPath -> ProjectConfigPath -> Ordering

-- | A comparison that puts projects first, URLs last and sorts the other paths
-- by putting longer paths after shorter ones as measured by the number of path
-- segments. If still equal, then sorting is lexical.
compareSegmentally:: ProjectConfigPath -> ProjectConfigPath -> Ordering

I'll squash commits before applying the merge label if this pull request is approved.


Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:

Copy link
Copy Markdown
Collaborator

@ulysses4ever ulysses4ever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for splitting it --- it helped reviewing a lot! A couple nitpicks inline.

Comment thread cabal.validate.project
-- The +legacy-comparison flag is to set the default project file parser to compare
-- the result of the legacy and parsec parser and fail if they are not equal.
package cabal-install
flags: +git-rev +legacy-comparison
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary? I dislike unrelated changes even if they are good changes on their own. But I won't block on this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is. With +legacy-comparison both legacy and parsec parsers are emitting the untrimmedUriImportMsg message. This leads to a test failure:

UNEXPECTED FAIL: PackageTests/ProjectImport/UntrimmedImport/cabal.test.hs

The test expects only one instance of this error for each build:

# cabal v2-build
Warning: import has leading or trailing whitespace;
'https://www.stackage.org/nightly-2024-12-05/cabal.config '
imported by: trailing-space.project

Here's the test diff with the warning repeated:

$ cabal build all --enable-tests -j --semaphore --ghc-options="-Werror" \
  --project-file=cabal.validate.project

$ cabal run cabal-testsuite:cabal-tests -- \
  --with-cabal=./dist-newstyle/build/x86_64-linux/ghc-9.14.1/cabal-install-3.17.0.0/x/cabal/build/cabal/cabal \
  cabal-testsuite/PackageTests/ProjectImport/UntrimmedImport/cabal.test.hs
...
Actual output differs from expected:

# STDERR:
--- /tmp/cabal-testsuite-712126/cabal.dist/cabal.out.normalized 2026-05-04 14:40:41.311315596 -0400
+++ /tmp/cabal-testsuite-712126/cabal.dist/cabal.comp.out.normalized    2026-05-04 14:40:41.311270635 -0400
@@ -3,6 +3,9 @@
 Warning: import has leading or trailing whitespace;
   'https://www.stackage.org/nightly-2024-12-05/cabal.config '
     imported by: trailing-space.project
+Warning: import has leading or trailing whitespace;
+  'https://www.stackage.org/nightly-2024-12-05/cabal.config '
+    imported by: trailing-space.project
 Resolving dependencies...
 Build profile: -w ghc-<GHCVER> -O1
 In order, the following would be built:
@@ -12,6 +15,9 @@
 Warning: import has leading or trailing whitespace;
   'https://www.stackage.org/nightly-2024-12-05/cabal.config               '
     imported by: tabs-and-spaces.project
+Warning: import has leading or trailing whitespace;
+  'https://www.stackage.org/nightly-2024-12-05/cabal.config               '
+    imported by: tabs-and-spaces.project
 Resolving dependencies...
 Build profile: -w ghc-<GHCVER> -O1
 In order, the following would be built:
cabal.test.hs: Uncaught exception ghc-internal:GHC.Internal.Exception.ErrorCall:

FAIL

HasCallStack backtrace:
  throwIO, called at src/Test/Cabal/Monad.hs:533:24 in cabal-testsuite-3-inplace:Test.Cabal.Monad

Comment thread cabal-install/src/Distribution/Client/ProjectConfig/Import.hs Outdated
@philderbeast philderbeast force-pushed the refactor/before-import-warning branch from 83257e1 to 0874d33 Compare May 4, 2026 17:36
@philderbeast philderbeast force-pushed the refactor/before-import-warning branch from 00be280 to 7310351 Compare May 10, 2026 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants