Skip to content

Commit 0ddde8d

Browse files
committed
Show flag setting in FailReason
1 parent 7c50909 commit 0ddde8d

7 files changed

Lines changed: 25 additions & 16 deletions

File tree

cabal-install-solver/src/Distribution/Solver/Modular/Message.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import Distribution.Types.UnqualComponentName
5656
( unUnqualComponentName )
5757

5858
import Text.PrettyPrint ( nest, render )
59+
import Distribution.Solver.Types.Settings (OnlyConstrained(..))
5960

6061
-- A data type to hold log information from the modular solver.
6162
data Message =
@@ -311,7 +312,7 @@ showFR _ (PackageRequiresMissingComponent qpn comp) = " (requires " ++ showExpos
311312
showFR _ (PackageRequiresPrivateComponent qpn comp) = " (requires " ++ showExposedComponent comp ++ " from " ++ showQPN qpn ++ ", but the component is private)"
312313
showFR _ (PackageRequiresUnbuildableComponent qpn comp) = " (requires " ++ showExposedComponent comp ++ " from " ++ showQPN qpn ++ ", but the component is not buildable in the current environment)"
313314
showFR _ CannotReinstall = " (avoiding to reinstall a package with same version but new dependencies)"
314-
showFR _ NotExplicit = " (not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies was set)"
315+
showFR _ (NotExplicit oc) = showNotExplicit oc
315316
showFR _ Shadowed = " (shadowed by another installed package with same version)"
316317
showFR _ (Broken u) = " (package is broken, missing dependency " ++ prettyShow u ++ ")"
317318
showFR _ UnknownPackage = " (unknown package)"
@@ -334,6 +335,11 @@ showFR _ (MalformedFlagChoice qfn) = " (INTERNAL ERROR: MALFORMED FLAG CH
334335
showFR _ (MalformedStanzaChoice qsn) = " (INTERNAL ERROR: MALFORMED STANZA CHOICE: " ++ showQSN qsn ++ ")"
335336
showFR _ EmptyGoalChoice = " (INTERNAL ERROR: EMPTY GOAL CHOICE)"
336337

338+
showNotExplicit :: OnlyConstrained -> String
339+
showNotExplicit oc = if oc == OnlyConstrainedNone
340+
then " (INTERNAL ERROR: NOT EXPLICIT when reject-unconstrained-dependencies=" ++ prettyShow oc ++ " was set)"
341+
else " (not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies=" ++ prettyShow oc ++ " was set)"
342+
337343
showExposedComponent :: ExposedComponent -> String
338344
showExposedComponent (ExposedLib LMainLibName) = "library"
339345
showExposedComponent (ExposedLib (LSubLibName name)) = "library '" ++ unUnqualComponentName name ++ "'"

cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import Distribution.Solver.Modular.Tree
4343
import Distribution.Solver.Modular.Version
4444
import qualified Distribution.Solver.Modular.ConflictSet as CS
4545
import qualified Distribution.Solver.Modular.WeightedPSQ as W
46+
import Distribution.Solver.Types.Settings (OnlyConstrained(..))
4647

4748
-- | Update the weights of children under 'PChoice' nodes. 'addWeights' takes a
4849
-- list of weight-calculating functions in order to avoid sorting the package
@@ -351,13 +352,13 @@ avoidReinstalls p = go
351352
go x = x
352353

353354
-- | Require all packages to be mentioned in a constraint or as a goal.
354-
onlyConstrained :: (PN -> Bool) -> EndoTreeTrav d QGoalReason
355-
onlyConstrained p = go
355+
onlyConstrained :: OnlyConstrained -> (PN -> Bool) -> EndoTreeTrav d QGoalReason
356+
onlyConstrained oc p = go
356357
where
357358
go (PChoiceF v@(Q _ pn) _ gr _) | not (p pn)
358359
= FailF
359360
(varToConflictSet (P v) `CS.union` goalReasonToConflictSetWithConflict v gr)
360-
NotExplicit
361+
(NotExplicit oc)
361362
go x
362363
= x
363364

cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE LambdaCase #-}
23
#ifdef DEBUG_TRACETREE
34
{-# LANGUAGE FlexibleInstances #-}
45
{-# OPTIONS_GHC -Wno-orphans #-}
@@ -11,6 +12,7 @@ module Distribution.Solver.Modular.Solver
1112

1213
import Distribution.Solver.Compat.Prelude
1314
import Prelude ()
15+
import Data.Function ((&))
1416

1517
import qualified Data.Map as M
1618
import qualified Data.List as L
@@ -141,9 +143,9 @@ solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals =
141143
validateLinking idx .
142144
validateTree cinfo idx pkgConfigDB
143145
prunePhase = (if asBool (avoidReinstalls sc) then P.avoidReinstalls (const True) else id) .
144-
(case onlyConstrained sc of
145-
OnlyConstrainedEq -> P.onlyConstrained (`S.member` allExplicitEq)
146-
OnlyConstrainedAll -> P.onlyConstrained (`S.member` allExplicit)
146+
(let oc = onlyConstrained sc in oc & \case
147+
OnlyConstrainedEq -> P.onlyConstrained oc (`S.member` allExplicitEq)
148+
OnlyConstrainedAll -> P.onlyConstrained oc (`S.member` allExplicit)
147149
OnlyConstrainedNone -> id)
148150
buildPhase = buildTree idx (independentGoals sc) (S.toList userGoals)
149151

cabal-install-solver/src/Distribution/Solver/Modular/Tree.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import Distribution.Solver.Types.PackagePath
3636
import Distribution.Types.PkgconfigVersionRange
3737
import Distribution.Types.UnitId (UnitId)
3838
import Language.Haskell.Extension (Extension, Language)
39+
import Distribution.Solver.Types.Settings (OnlyConstrained(..))
3940

4041
type Weight = Double
4142

@@ -112,7 +113,7 @@ data FailReason = UnsupportedExtension Extension
112113
| PackageRequiresPrivateComponent QPN ExposedComponent
113114
| PackageRequiresUnbuildableComponent QPN ExposedComponent
114115
| CannotReinstall
115-
| NotExplicit
116+
| NotExplicit OnlyConstrained
116117
| Shadowed
117118
| Broken UnitId
118119
| UnknownPackage

cabal-testsuite/PackageTests/RequireExplicit/MultiPkg/cabal.multipkg-all.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Error: [Cabal-7107]
66
Could not resolve dependencies:
77
[__0] trying: b-0 (user goal)
88
[__1] next goal: other-lib (dependency of b)
9-
[__1] fail (not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies was set)
9+
[__1] fail (not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies=all was set)
1010
[__1] fail (backjumping, conflict set: b, other-lib)
1111
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: b (2), other-lib (1)
1212
# cabal build
@@ -15,7 +15,7 @@ Error: [Cabal-7107]
1515
Could not resolve dependencies:
1616
[__0] trying: b-0 (user goal)
1717
[__1] next goal: b:some-exe:exe.some-exe (dependency of b)
18-
[__1] fail (not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies was set)
18+
[__1] fail (not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies=all was set)
1919
[__1] fail (backjumping, conflict set: b, b:some-exe:exe.some-exe)
2020
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: b (2), b:some-exe:exe.some-exe (1)
2121
# cabal build

cabal-testsuite/PackageTests/RequireExplicit/MultiPkg/cabal.multipkg-eq.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ Error: [Cabal-7107]
2424
Could not resolve dependencies:
2525
[__0] trying: a-0 (user goal)
2626
[__1] next goal: some-lib (dependency of a)
27-
[__1] fail (not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies was set)
27+
[__1] fail (not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies=eq was set)
2828
[__1] fail (backjumping, conflict set: a, some-lib)
2929
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: a (2), some-lib (1)

cabal-testsuite/PackageTests/RequireExplicit/MultiPkg/cabal.test.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Test.Cabal.Prelude
22

33
-- See #4332, dep solving output is not deterministic
44

5-
assertErr = assertOutputContains "not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies was set"
5+
assertErr x = assertOutputContains ("not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies=" ++ x ++ " was set")
66

77
constraint x = "--constraint=" ++ x
88

@@ -15,12 +15,11 @@ main = do
1515

1616
-- other-lib is a dependency of b, but it's not listed in cabal.project
1717
res <- fails $ cabal' "build" ("all" : opts ++ [constraint "some-exe -any"])
18-
assertErr res
18+
assertErr "all" res
1919

2020
-- and some-exe is a build-tool dependency of b, again not listed
2121
res <- fails $ cabal' "build" ("all" : opts ++ [constraint "other-lib -any"])
22-
assertErr res
23-
22+
assertErr "all" res
2423
-- everything's listed, good to go
2524
cabal "build" $
2625
"all"
@@ -65,4 +64,4 @@ main = do
6564
++ [ constraint "some-lib >0"
6665
, constraint "some-lib <2"
6766
]
68-
assertErr res
67+
assertErr "eq" res

0 commit comments

Comments
 (0)