cabal-install: Clarify the semantics of package-db flag
commitd626ef872a9a424706c945d15ae6b9ecfdb14e2a
authorMatthew Pickering <matthewtpickering@gmail.com>
Wed, 31 Jan 2024 16:53:43 +0000 (31 16:53 +0000)
committerMikolaj <281893+Mikolaj@users.noreply.github.com>
Sun, 25 Feb 2024 09:24:24 +0000 (25 09:24 +0000)
treeac7a5d3646bfbd8a8f7f96abacbe8e6fd8981014
parentfb3f4d47d261f7401e4ea717ffab31af5d5470fb
cabal-install: Clarify the semantics of package-db flag

In this PR we make the `--package-db` flag apply only to the default
immutable initial package stack rather than also applying to the store
package database.

There are two special package databases which cabal install knows about
and treats specially.

* The store directory, a global cache of installed packages where cabal
  builds and installs packages into.
* The inplace directory, a local build folder for packages, where cabal
  builds local packages in.

It is very important that cabal registers packages it builds into one of
these two locations as there are many assumptions that packages will end
up here.

With the current design of the `--package-db` flag, you are apparently
allowed to override the store location which should have the effect of
making the last package database in the package stack the "store"
directory. Perhaps this works out in theory but practically this
behaviour was broken and things were always registered into the store
directory that cabal knew about. (The assertion in
`ProjectBuilding.UnpackedPackage` was failing (see added test)).

With `--package-db` not being able to modify the location of the store
directory then the interaction of `--package-db`, `--store-dir` and
`--dist-dir` flags become easy to understand.

* `--package-db` modify the initial package database stack, these
  package database will not be mutated by cabal and provide the initial
  package environment which is used by cabal.
* `--store-dir` modify the location of the store directory
* `--dist-dir` modify the location of the dist directory (and hence
  inplace package database)

Treating the flags in this way also fix an assertion failure when
building packages.

Fixes #9678
18 files changed:
cabal-install/src/Distribution/Client/CmdInstall.hs
cabal-install/src/Distribution/Client/DistDirLayout.hs
cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs
cabal-install/src/Distribution/Client/ProjectOrchestration.hs
cabal-install/src/Distribution/Client/ProjectPlanning.hs
cabal-testsuite/PackageTests/PackageDB/t9678/cabal.test.hs [new file with mode: 0644]
cabal-testsuite/PackageTests/PackageDB/t9678/p1/CHANGELOG.md [new file with mode: 0644]
cabal-testsuite/PackageTests/PackageDB/t9678/p1/p1.cabal [new file with mode: 0644]
cabal-testsuite/PackageTests/PackageDB/t9678/p1/src/MyLib.hs [new file with mode: 0644]
cabal-testsuite/PackageTests/PackageDB/t9678/p2/CHANGELOG.md [new file with mode: 0644]
cabal-testsuite/PackageTests/PackageDB/t9678/p2/cabal.project [new file with mode: 0644]
cabal-testsuite/PackageTests/PackageDB/t9678/p2/p2.cabal [new file with mode: 0644]
cabal-testsuite/PackageTests/PackageDB/t9678/p2/src/MyLib.hs [new file with mode: 0644]
cabal-testsuite/PackageTests/PackageDB/t9678/repo/p3-0.1.0.0/CHANGELOG.md [new file with mode: 0644]
cabal-testsuite/PackageTests/PackageDB/t9678/repo/p3-0.1.0.0/p3.cabal [new file with mode: 0644]
cabal-testsuite/PackageTests/PackageDB/t9678/repo/p3-0.1.0.0/src/MyLib.hs [new file with mode: 0644]
changelog.d/issue-9678 [new file with mode: 0644]
doc/cabal-project-description-file.rst