Skip to content

Commit 430cc97

Browse files
committed
Merge pull request #1990 from benarmston/freeze-doesnt-include-self
Self-constraint not included in frozen constraints
2 parents bd5f7c2 + 8ed42ce commit 430cc97

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

cabal-install/Distribution/Client/Freeze.hs

+16-12
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ import Distribution.Version
6565
-- * The freeze command
6666
-- ------------------------------------------------------------
6767

68-
--TODO:
69-
-- * Don't overwrite all of `cabal.config`, just the constraints section.
70-
-- * Should the package represented by `UserTargetLocalDir "."` be
71-
-- constrained too? What about `base`?
72-
73-
7468
-- | Freeze all of the dependencies by writing a constraints section
7569
-- constraining each dependency to an exact version.
7670
--
@@ -113,10 +107,13 @@ freeze verbosity packageDBs repos comp platform conf mSandboxPkgInfo
113107
where
114108
dryRun = fromFlag (freezeDryRun freezeFlags)
115109

116-
sanityCheck pkgSpecifiers =
110+
sanityCheck pkgSpecifiers = do
117111
when (not . null $ [n | n@(NamedPackage _ _) <- pkgSpecifiers]) $
118112
die $ "internal error: 'resolveUserTargets' returned "
119113
++ "unexpected named package specifiers!"
114+
when (length pkgSpecifiers /= 1) $
115+
die $ "internal error: 'resolveUserTargets' returned "
116+
++ "unexpected source package specifiers!"
120117

121118
planPackages :: Verbosity
122119
-> Compiler
@@ -184,21 +181,28 @@ planPackages verbosity comp platform mSandboxPkgInfo freezeFlags
184181

185182
-- | Remove all unneeded packages from an install plan.
186183
--
187-
-- A package is unneeded if it is not a dependency (directly or
188-
-- transitively) of any of the 'PackageSpecifier SourcePackage's. This is
189-
-- useful for removing previously installed packages which are no longer
190-
-- required from the install plan.
184+
-- A package is unneeded if it is either
185+
--
186+
-- 1) the package that we are freezing, or
187+
--
188+
-- 2) not a dependency (directly or transitively) of the package we are
189+
-- freezing. This is useful for removing previously installed packages
190+
-- which are no longer required from the install plan.
191191
pruneInstallPlan :: InstallPlan.InstallPlan
192192
-> [PackageSpecifier SourcePackage]
193193
-> Either [PlanPackage] [(PlanPackage, [PackageIdentifier])]
194194
pruneInstallPlan installPlan pkgSpecifiers =
195-
mapLeft PackageIndex.allPackages $
195+
mapLeft (removeSelf pkgIds . PackageIndex.allPackages) $
196196
PackageIndex.dependencyClosure pkgIdx pkgIds
197197
where
198198
pkgIdx = PackageIndex.fromList $ InstallPlan.toList installPlan
199199
pkgIds = [ packageId pkg | SpecificSourcePackage pkg <- pkgSpecifiers ]
200200
mapLeft f (Left v) = Left $ f v
201201
mapLeft _ (Right v) = Right v
202+
removeSelf [thisPkg] = filter (\pp -> packageId pp /= thisPkg)
203+
removeSelf _ =
204+
error $ "internal error: 'pruneInstallPlan' given "
205+
++ "unexpected package specifiers!"
202206

203207

204208
freezePackages :: Package pkg => Verbosity -> [pkg] -> IO ()

cabal-install/tests/PackageTests/Freeze/Check.hs

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ tests cabalPath =
5252
assertBool ("should not have frozen exceptions\n" ++ c) $ not $
5353
" exceptions ==" `isInfixOf` (intercalate " " $ lines $ c)
5454

55+
, testCase "does not include a constraint for the package being frozen" $ do
56+
removeCabalConfig
57+
result <- cabal_freeze dir [] cabalPath
58+
assertFreezeSucceeded result
59+
c <- readCabalConfig
60+
assertBool ("should not have frozen self\n" ++ c) $ not $
61+
" my ==" `isInfixOf` (intercalate " " $ lines $ c)
62+
5563
, testCase "--dry-run does not modify the cabal.config file" $ do
5664
removeCabalConfig
5765
result <- cabal_freeze dir ["--dry-run"] cabalPath

0 commit comments

Comments
 (0)