Skip to content

Commit 4a1f73c

Browse files
committed
Show abbreviated mixed versions with suffix
- Use independent package name in doctest - Add changelog entry - Still use showOption when linked - Typo, package is cabal-install-solver - Rename showIsOrVs to showOptions - Add linked doctests for showOptions
1 parent 4a8a7c5 commit 4a1f73c

File tree

3 files changed

+42
-49
lines changed
  • cabal-install-solver/src/Distribution/Solver/Modular
  • cabal-install/tests/UnitTests/Distribution/Solver/Modular
  • changelog.d

3 files changed

+42
-49
lines changed

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

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ module Distribution.Solver.Modular.Message (
77
showMessages
88
) where
99

10-
import Data.Maybe (isJust)
1110
import qualified Data.List as L
1211
import Data.Map (Map)
1312
import qualified Data.Map as M
1413
import Data.Set (Set)
1514
import qualified Data.Set as S
16-
import Data.Maybe (catMaybes, mapMaybe)
15+
import Data.Maybe (catMaybes, mapMaybe, isJust)
1716
import Prelude hiding (pi)
1817

1918
import Distribution.Pretty (prettyShow) -- from Cabal
@@ -236,61 +235,41 @@ blurbOption :: ProgressAction -> QPN -> POption -> String
236235
blurbOption a q p = blurb a ++ showOption q p
237236

238237
blurbOptions :: ProgressAction -> QPN -> [POption] -> String
239-
blurbOptions a q ps = blurb a ++ showIsOrVs q (tryVs ps)
238+
blurbOptions a q ps = blurb a ++ showOptions q ps
240239

241240
showOption :: QPN -> POption -> String
242241
showOption qpn@(Q _pp pn) (POption i linkedTo) =
243242
case linkedTo of
244243
Nothing -> showPI (PI qpn i) -- Consistent with prior to POption
245244
Just pp' -> showQPN qpn ++ "~>" ++ showPI (PI (Q pp' pn) i)
246245

247-
-- | A list of versions, or a list of instances.
248-
data IsOrVs = Is [POption] | Vs [Ver] deriving Show
249-
250-
-- | Try to convert a list of options to a list of versions, or a list of
251-
-- instances if any of the options is linked or installed. Singleton lists or
252-
-- empty lists are always converted to Is.
253-
-- >>> tryVs [v0, v1]
254-
-- Vs [mkVersion [0],mkVersion [1]]
255-
-- >>> tryVs [v0]
256-
-- Is [POption (I (mkVersion [0]) InRepo) Nothing]
257-
-- >>> tryVs [i0, i1]
258-
-- Is [POption (I (mkVersion [0]) (Inst (UnitId "foo-bar-0-inplace"))) Nothing,POption (I (mkVersion [1]) (Inst (UnitId "foo-bar-1-inplace"))) Nothing]
259-
-- >>> tryVs [i0, v1]
260-
-- Is [POption (I (mkVersion [0]) (Inst (UnitId "foo-bar-0-inplace"))) Nothing,POption (I (mkVersion [1]) InRepo) Nothing]
261-
-- >>> tryVs [v0, i1]
262-
-- Is [POption (I (mkVersion [0]) InRepo) Nothing,POption (I (mkVersion [1]) (Inst (UnitId "foo-bar-1-inplace"))) Nothing]
263-
-- >>> tryVs [i0]
264-
-- Is [POption (I (mkVersion [0]) (Inst (UnitId "foo-bar-0-inplace"))) Nothing]
265-
-- >>> tryVs []
266-
-- Is []
267-
tryVs :: [POption] -> IsOrVs
268-
tryVs xs@[] = Is xs
269-
tryVs xs@[_] = Is xs
270-
tryVs xs
271-
| any (\(POption (instI -> b0) (isJust -> b1)) -> b0 || b1) xs = Is xs
272-
| otherwise =
273-
let (vs, is) = L.partition ((== InRepo) . snd) [(v, l) | POption i _ <- xs, let I v l = i]
274-
in if null is then Vs (fst `map` vs) else Is xs
275-
276-
-- | Shows a list of versions in a human-friendly way, abbreviated. Shows a list
277-
-- of instances in full.
278-
-- >>> showIsOrVs foobarQPN $ tryVs [v0, v1]
246+
-- | Shows a mixed list of instances and versions in a human-friendly way,
247+
-- abbreviated.
248+
-- >>> showOptions foobarQPN [v0, v1]
279249
-- "foo-bar; 0, 1"
280-
-- >>> showIsOrVs foobarQPN $ tryVs [v0]
250+
-- >>> showOptions foobarQPN [v0]
281251
-- "foo-bar-0"
282-
-- >>> showIsOrVs foobarQPN $ tryVs [i0, i1]
283-
-- "foo-bar-0/installed-inplace, foo-bar-1/installed-inplace"
284-
-- >>> showIsOrVs foobarQPN $ tryVs [i0, v1]
285-
-- "foo-bar-0/installed-inplace, foo-bar-1"
286-
-- >>> showIsOrVs foobarQPN $ tryVs [v0, i1]
287-
-- "foo-bar-0, foo-bar-1/installed-inplace"
288-
-- >>> showIsOrVs foobarQPN $ tryVs []
252+
-- >>> showOptions foobarQPN [i0, i1]
253+
-- "foo-bar; 0/installed-inplace, 1/installed-inplace"
254+
-- >>> showOptions foobarQPN [i0, v1]
255+
-- "foo-bar; 0/installed-inplace, 1"
256+
-- >>> showOptions foobarQPN [v0, i1]
257+
-- "foo-bar; 0, 1/installed-inplace"
258+
-- >>> showOptions foobarQPN []
289259
-- "unexpected empty list of versions"
290-
showIsOrVs :: QPN -> IsOrVs -> String
291-
showIsOrVs _ (Is []) = "unexpected empty list of versions"
292-
showIsOrVs q (Is xs) = L.intercalate ", " (showOption q `map` xs)
293-
showIsOrVs q (Vs xs) = showQPN q ++ "; " ++ L.intercalate ", " (showVer `map` xs)
260+
-- >>> showOptions foobarQPN [k1, k2]
261+
-- "foo-bar; foo-bar~>bazqux.foo-bar-1, foo-bar~>bazqux.foo-bar-2"
262+
-- >>> showOptions foobarQPN [v0, i1, k2]
263+
-- "foo-bar; 0, 1/installed-inplace, foo-bar~>bazqux.foo-bar-2"
264+
showOptions :: QPN -> [POption] -> String
265+
showOptions _ [] = "unexpected empty list of versions"
266+
showOptions q [x] = showOption q x
267+
showOptions q xs = showQPN q ++ "; " ++ (L.intercalate ", "
268+
[if isJust linkedTo
269+
then showOption q x
270+
else showI i -- Don't show the package, just the version
271+
| x@(POption i linkedTo) <- xs
272+
])
294273

295274
showGR :: QGoalReason -> String
296275
showGR UserGoal = " (user goal)"
@@ -356,8 +335,12 @@ showConflictingDep (ConflictingDep dr (PkgComponent qpn comp) ci) =
356335
-- >>> import Distribution.Solver.Types.PackagePath
357336
-- >>> import Distribution.Types.Version
358337
-- >>> import Distribution.Types.UnitId
359-
-- >>> let foobarQPN = Q (PackagePath DefaultNamespace QualToplevel) (mkPackageName "foo-bar")
338+
-- >>> let foobarPN = PackagePath DefaultNamespace QualToplevel
339+
-- >>> let bazquxPN = PackagePath (Independent $ mkPackageName "bazqux") QualToplevel
340+
-- >>> let foobarQPN = Q foobarPN (mkPackageName "foo-bar")
360341
-- >>> let v0 = POption (I (mkVersion [0]) InRepo) Nothing
361342
-- >>> let v1 = POption (I (mkVersion [1]) InRepo) Nothing
362343
-- >>> let i0 = POption (I (mkVersion [0]) (Inst $ mkUnitId "foo-bar-0-inplace")) Nothing
363344
-- >>> let i1 = POption (I (mkVersion [1]) (Inst $ mkUnitId "foo-bar-1-inplace")) Nothing
345+
-- >>> let k1 = POption (I (mkVersion [1]) InRepo) (Just bazquxPN)
346+
-- >>> let k2 = POption (I (mkVersion [2]) InRepo) (Just bazquxPN)

cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ tests =
961961
, Right $ exAv "B" 1 [ExFix "A" 4]
962962
]
963963
rejecting = "rejecting: A-3.0.0/installed-3.0.0"
964-
skipping = "skipping: A-2.0.0/installed-2.0.0, A-1.0.0/installed-1.0.0"
964+
skipping = "skipping: A; 2.0.0/installed-2.0.0, 1.0.0/installed-1.0.0"
965965
in mkTest db "show skipping versions list, installed" ["B"] $
966966
solverFailure (\msg -> rejecting `isInfixOf` msg && skipping `isInfixOf` msg)
967967
]

changelog.d/pr-9824

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
synopsis: Abbrevate solver rejection messages with installed versions
2+
packages: cabal-install-solver
3+
prs: #9824
4+
issues: #9823
5+
6+
description: {
7+
8+
Abbreviate solver rejection messages even in the presence of installed versions.
9+
10+
}

0 commit comments

Comments
 (0)