@@ -65,12 +65,6 @@ import Distribution.Version
65
65
-- * The freeze command
66
66
-- ------------------------------------------------------------
67
67
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
-
74
68
-- | Freeze all of the dependencies by writing a constraints section
75
69
-- constraining each dependency to an exact version.
76
70
--
@@ -113,10 +107,13 @@ freeze verbosity packageDBs repos comp platform conf mSandboxPkgInfo
113
107
where
114
108
dryRun = fromFlag (freezeDryRun freezeFlags)
115
109
116
- sanityCheck pkgSpecifiers =
110
+ sanityCheck pkgSpecifiers = do
117
111
when (not . null $ [n | n@ (NamedPackage _ _) <- pkgSpecifiers]) $
118
112
die $ " internal error: 'resolveUserTargets' returned "
119
113
++ " unexpected named package specifiers!"
114
+ when (length pkgSpecifiers /= 1 ) $
115
+ die $ " internal error: 'resolveUserTargets' returned "
116
+ ++ " unexpected source package specifiers!"
120
117
121
118
planPackages :: Verbosity
122
119
-> Compiler
@@ -184,21 +181,28 @@ planPackages verbosity comp platform mSandboxPkgInfo freezeFlags
184
181
185
182
-- | Remove all unneeded packages from an install plan.
186
183
--
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.
191
191
pruneInstallPlan :: InstallPlan. InstallPlan
192
192
-> [PackageSpecifier SourcePackage ]
193
193
-> Either [PlanPackage ] [(PlanPackage , [PackageIdentifier ])]
194
194
pruneInstallPlan installPlan pkgSpecifiers =
195
- mapLeft PackageIndex. allPackages $
195
+ mapLeft (removeSelf pkgIds . PackageIndex. allPackages) $
196
196
PackageIndex. dependencyClosure pkgIdx pkgIds
197
197
where
198
198
pkgIdx = PackageIndex. fromList $ InstallPlan. toList installPlan
199
199
pkgIds = [ packageId pkg | SpecificSourcePackage pkg <- pkgSpecifiers ]
200
200
mapLeft f (Left v) = Left $ f v
201
201
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!"
202
206
203
207
204
208
freezePackages :: Package pkg => Verbosity -> [pkg ] -> IO ()
0 commit comments