Skip to content

Only consider version constraints with --reject-unconstrained-dependencies - #12191

Open
philderbeast wants to merge 3 commits into
haskell:masterfrom
cabalism:fix/flag-as-version
Open

Only consider version constraints with --reject-unconstrained-dependencies#12191
philderbeast wants to merge 3 commits into
haskell:masterfrom
cabalism:fix/flag-as-version

Conversation

@philderbeast

@philderbeast philderbeast commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Fixes #12190.

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

Manual QA Notes

Compare running the included package test with the version of cabal-install:exe:cabal from this branch and with a released version, such as cabal-3.16.1.0.

Run the test locally manually, it should pass.

$ ghc --numeric-version
9.14.1

$ cabal build all --enable-tests

$ cabal run cabal-testsuite:cabal-tests -- \
  --with-cabal=./dist-newstyle/build/x86_64-linux/ghc-9.14.1/cabal-install-3.19.0.0/x/cabal/build/cabal/cabal \
  cabal-testsuite/PackageTests/RequireExplicit/FlagNotVersion/cabal.test.hs --accept
  
$ echo $status
0

Run the test with a released version of cabal and it should fail:

$ cabal run cabal-testsuite:cabal-tests -- \
   --with-cabal=/home/.../.ghcup/bin/cabal \
   cabal-testsuite/PackageTests/RequireExplicit/FlagNotVersion/cabal.test.hs --accept
  
$ echo $status
1

Modify the test so that it will succeed for versions of cabal without this fix.

Tip

You may need to delete the named tests too that were added (appended) after these instructions.

$ diff --git a/cabal-testsuite/PackageTests/RequireExplicit/FlagNotVersion/cabal.test.hs b/cabal-testsuite/PackageTests/RequireExplicit/FlagNotVersion/cabal.test.hs
index 01f7429c1..4a617d2b1 100644
--- a/cabal-testsuite/PackageTests/RequireExplicit/FlagNotVersion/cabal.test.hs
+++ b/cabal-testsuite/PackageTests/RequireExplicit/FlagNotVersion/cabal.test.hs
@@ -1,4 +1,3 @@
 import Test.Cabal.Prelude
 main = cabalTest . recordMode RecordMarked $ withRepo "repo" $ do
-  res <- fails $ cabal' "v2-build" ["all", "--dry-run"]
-  assertOutputContains "not a user-provided goal" res
+  cabal "v2-build" ["all", "--dry-run"]

Run the test with a released version of cabal and observe the change in output:

$ cabal run cabal-testsuite:cabal-tests -- \
   --with-cabal=/home/.../.ghcup/bin/cabal \
   cabal-testsuite/PackageTests/RequireExplicit/FlagNotVersion/cabal.test.hs --accept

The change of output:

$ git diff
diff --git a/cabal-testsuite/PackageTests/RequireExplicit/FlagNotVersion/cabal.out b/cabal-testsuite/PackageTests/RequireExplicit/FlagNotVersion/cabal.out
index a3a5898e7..215cadb23 100644
--- a/cabal-testsuite/PackageTests/RequireExplicit/FlagNotVersion/cabal.out
+++ b/cabal-testsuite/PackageTests/RequireExplicit/FlagNotVersion/cabal.out
@@ -5,10 +5,7 @@
 Downloading the latest package list from test-local-repo
 # cabal v2-build
 Resolving dependencies...
-Error: [Cabal-7107]
-Could not resolve dependencies:
-[__0] trying: a-0 (user goal)
-[__1] next goal: some-lib (dependency of a)
-[__1] fail (not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies was set)
-[__1] fail (backjumping, conflict set: a, some-lib)
-After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: a (2), some-lib (1)
+Build profile: -w ghc-<GHCVER> -O1
+In order, the following would be built:
+ - some-lib-1.0 (lib) (requires build)
+ - a-0 (lib) (first run)

Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:

@philderbeast
philderbeast force-pushed the fix/flag-as-version branch 5 times, most recently from 0f6a94b to 34cb954 Compare July 31, 2026 12:49
@philderbeast
philderbeast force-pushed the fix/flag-as-version branch from 77e147b to 94893f6 Compare July 31, 2026 13:11
@philderbeast
philderbeast requested review from sebright and sheaf July 31, 2026 13:27
@philderbeast
philderbeast force-pushed the fix/flag-as-version branch 2 times, most recently from 6e0fb8f to a5e4567 Compare August 1, 2026 11:20
@philderbeast
philderbeast force-pushed the fix/flag-as-version branch 2 times, most recently from 610ec30 to 28e5432 Compare August 13, 2026 17:34
@philderbeast philderbeast added merge me Tell Mergify Bot to merge and removed attention: needs-review labels Aug 13, 2026
@philderbeast philderbeast changed the title Only consider version constraints with --reject-unconstrained-dependenies Only consider version constraints with --reject-unconstrained-dependencies Aug 13, 2026
- Add test for mistaking flag for version
- Add tests for -any and -none
- Add doctests to isNoVersion && isSpecificVersion
- Update tests for rejecting -none and <0
- Reject -none and <0 as version constrained
- Add =all and shorten the failure message
- Minor correction of haddock rendering
@philderbeast
philderbeast force-pushed the fix/flag-as-version branch 3 times, most recently from cd6a4f3 to 51b9ec2 Compare August 14, 2026 17:06
- Add a stanza constraint too
- Split tests into two groups
- Literal rejections
@mergify mergify Bot added the ready and waiting Mergify is waiting out the cooldown period label Aug 14, 2026
@philderbeast philderbeast removed merge me Tell Mergify Bot to merge ready and waiting Mergify is waiting out the cooldown period labels Aug 15, 2026
@philderbeast

Copy link
Copy Markdown
Collaborator Author

I don't know how, but I missed a couple of failing tests. I've fixed the test expectations now without changing the implementation:

  • cabal-testsuite/PackageTests/RequireExplicit/MultiPkg/cabal.test.hs the -any constraints are not enough any more so the expectation changed for these tests to fail and I added other tests with ==1.0 constraints that pass, as before. I updated the test comments too.

  • cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs I split the "reject-unconstrained" test group into two for each test set of the example package database, added way more tests with more explicit expectations. Also added this comment:

  , -- reject-unconstrained-dependencies=all requires all non-goals to be
    -- version constrained. Goals don't need constraints and flag constraints
    -- are not enough.

After the test update:

:main -p "reject-unconstrained"
Unit Tests
  UnitTests.Distribution.Solver.Modular.Solver
    reject-unconstrained
      [A, B]
        accept backtracking finds all goals closed set:          OK (0.03s)
        accept non-goal 'B' version-constrained:                 OK (0.03s)
        reject non-goal 'B' flag-constrained:                    OK (0.03s)
        reject non-goal 'C' unconstrained:                       OK (0.03s)
      [base, syb, E]
        accept all goals, no other dependencies:                 OK (0.03s)
        accept non-goal 'base' version-constrained:              OK (0.03s)
        accept non-goal 'syb' version-constrained:               OK (0.03s)
        accept non-goals 'base' and 'syb' version-unconstrained: OK (0.03s)
        reject non-goal 'base' unconstrained:                    OK (0.03s)
        reject non-goal 'syb' unconstrained:                     OK (0.03s)
        reject non-goal 'base' only flag-constrained:            OK (0.03s)
        reject non-goal 'base' only stanza-constrained:          OK (0.03s)

All 12 tests passed (0.05s)

Beforehand:

:main -p "reject-unconstrained"
Unit Tests
  UnitTests.Distribution.Solver.Modular.Solver
    reject-unconstrained
      missing syb:     OK (0.03s)
      all goals:       OK (0.03s)
      backtracking:    OK (0.03s)
      failure message: OK (0.03s)

All 4 tests passed (0.05s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--reject-unconstrained-dependencies is satisfied by flag constraints

3 participants