Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 58 additions & 53 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -718,51 +718,54 @@ rebuildInstallPlan
progsearchpath <- liftIO getSystemSearchPath
let projectConfigMonitored = projectConfig{projectConfigBuildOnly = mempty}

-- The overall improved plan is cached
rerunIfChanged
verbosity
fileMonitorImprovedPlan
-- react to changes in the project config,
-- the package .cabal files and the path
(projectConfigMonitored, localPackages, progsearchpath)
$ do
-- And so is the elaborated plan that the improved plan based on
(elaboratedPlan, elaboratedShared, totalIndexState, activeRepos) <-
rerunIfChanged
verbosity
fileMonitorElaboratedPlan
( projectConfigMonitored
, localPackages
, progsearchpath
)
$ do
compilerEtc <- phaseConfigureCompiler projectConfig
_ <- phaseConfigurePrograms projectConfig compilerEtc
(solverPlan, pkgConfigDB, totalIndexState, activeRepos) <-
phaseRunSolver
projectConfig
compilerEtc
localPackages
(fromMaybe mempty mbInstalledPackages)
( elaboratedPlan
, elaboratedShared
) <-
phaseElaboratePlan
projectConfig
compilerEtc
pkgConfigDB
solverPlan
localPackages

phaseMaintainPlanOutputs elaboratedPlan elaboratedShared
return (elaboratedPlan, elaboratedShared, totalIndexState, activeRepos)

-- The improved plan changes each time we install something, whereas
-- the underlying elaborated plan only changes when input config
-- changes, so it's worth caching them separately.
improvedPlan <- phaseImprovePlan elaboratedPlan elaboratedShared

return (improvedPlan, elaboratedPlan, elaboratedShared, totalIndexState, activeRepos)
-- The elaborated plan is cached
(elaboratedPlan, elaboratedShared, totalIndexState, activeRepos) <-
rerunIfChanged
verbosity
fileMonitorElaboratedPlan
-- react to changes in the project config,
-- the package .cabal files and the path
( projectConfigMonitored
, localPackages
, progsearchpath
)
$ do
compilerEtc <- phaseConfigureCompiler projectConfig
_ <- phaseConfigurePrograms projectConfig compilerEtc
(solverPlan, pkgConfigDB, totalIndexState, activeRepos) <-
phaseRunSolver
projectConfig
compilerEtc
localPackages
(fromMaybe mempty mbInstalledPackages)
( elaboratedPlan
, elaboratedShared
) <-
phaseElaboratePlan
projectConfig
compilerEtc
pkgConfigDB
solverPlan
localPackages

phaseMaintainPlanOutputs elaboratedPlan elaboratedShared
return (elaboratedPlan, elaboratedShared, totalIndexState, activeRepos)

-- The improved plan changes each time we install something, whereas
-- the underlying elaborated plan only changes when input config
-- changes. So what is cached for the improved plan is only which of
-- the plan's units are in the store, not a second copy of the plan.
Comment on lines +756 to +757

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- changes. So what is cached for the improved plan is only which of
-- the plan's units are in the store, not a second copy of the plan.
-- changes. So, we only cache whether
-- each of the plan's units are in the store, rather than an entire second copy of the plan.

Maybe something like this is a bit clearer?

let planUnits =
Set.fromList
[ installedUnitId pkg
| InstallPlan.Configured pkg <- InstallPlan.toList elaboratedPlan
]
storeUnits <-
rerunIfChanged verbosity fileMonitorImprovedPlan planUnits $
phaseImprovePlan elaboratedPlan elaboratedShared planUnits
let improvedPlan = improveInstallPlanWithInstalledPackages storeUnits elaboratedPlan

return (improvedPlan, elaboratedPlan, elaboratedShared, totalIndexState, activeRepos)
where
fileMonitorSolverPlan = newFileMonitorInCacheDir "solver-plan"
fileMonitorSourceHashes = newFileMonitorInCacheDir "source-hashes"
Expand Down Expand Up @@ -1012,23 +1015,25 @@ rebuildInstallPlan
-- this improvement phase when the db changes -- including as a result of
-- executing a plan and installing things.
--
-- The result is the plan's units that are in the store.
phaseImprovePlan
:: ElaboratedInstallPlan
-> ElaboratedSharedConfig
-> Rebuild ElaboratedInstallPlan
phaseImprovePlan elaboratedPlan elaboratedShared = do
-> Set UnitId
-> Rebuild (Set UnitId)
phaseImprovePlan elaboratedPlan elaboratedShared planUnits = do
liftIO $ debug verbosity "Improving the install plan..."
storePkgIdSet <- getStoreEntries cabalStoreDirLayout compiler
let improvedPlan =
improveInstallPlanWithInstalledPackages
storePkgIdSet
elaboratedPlan
liftIO $ debugNoWrap verbosity (showElaboratedInstallPlan improvedPlan)
let storeUnits = Set.intersection planUnits storePkgIdSet
liftIO $
debugNoWrap verbosity $
showElaboratedInstallPlan $
improveInstallPlanWithInstalledPackages storeUnits elaboratedPlan
-- TODO: [nice to have] having checked which packages from the store
-- we're using, it may be sensible to sanity check those packages
-- by loading up the compiler package db and checking everything
-- matches up as expected, e.g. no dangling deps, files deleted.
return improvedPlan
return storeUnits
where
compiler = pkgConfigCompiler elaboratedShared

Expand Down
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/StoreUnitRemoved/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main :: IO ()
main = return ()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
14 changes: 14 additions & 0 deletions cabal-testsuite/PackageTests/StoreUnitRemoved/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Test.Cabal.Prelude

import System.Directory (removeDirectoryRecursive)

-- With the project unchanged, a dependency is planned until it is in the
-- store and planned again once it is removed from there.
main = cabalTest $ recordMode DoNotRecord $ withShorterPathForNewBuildStore $ withRepo "repo" $ do
dryRun >>= assertOutputContains "remote-1 (lib)"
cabal "v2-build" ["current"]
dryRun >>= assertOutputDoesNotContain "remote-1 (lib)"
findDependencyInStore "remote" >>= liftIO . removeDirectoryRecursive
dryRun >>= assertOutputContains "remote-1 (lib)"
where
dryRun = cabal' "v2-build" ["current", "--dry-run"]
8 changes: 8 additions & 0 deletions cabal-testsuite/PackageTests/StoreUnitRemoved/current.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cabal-version: 3.0
name: current
version: 1

executable current
main-is: Main.hs
build-depends: base, remote
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module P where
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cabal-version: 3.0
name: remote
version: 1

library
exposed-modules: P
build-depends: base
default-language: Haskell2010
9 changes: 9 additions & 0 deletions changelog.d/pr-12572.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
synopsis: Cache one copy of the install plan
packages: [cabal-install]
prs: 12572
issues: 12463
---

The `improved-plan` cache file no longer holds two more copies of the install
plan, only which of the plan's packages are in the store.
Comment on lines +8 to +9

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This describes implementation changes. Changelog entries IMO should describe user facing changes instead

4 changes: 2 additions & 2 deletions doc/nix-local-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ this folder (the most important two are first):
``compiler`` (binary)
The configuration of the compiler being used to build the project.
``improved-plan`` (binary)
Like ``solver-plan``, but with all non-inplace packages improved
into pre-existing copies from the store.
Which non-inplace packages of the plan have pre-existing copies in the
store.
``plan.json`` (JSON)
A JSON serialization of the computed install plan intended
for integrating ``cabal`` with external tooling.
Expand Down
Loading