Redesign 'cabal path' command to account for projects (#9583)
commit4a8a7c5d2aae9ee7eaed0541457ff792fed26395
authorfendor <fendor@users.noreply.github.com>
Sun, 14 Apr 2024 21:05:15 +0000 (14 23:05 +0200)
committerGitHub <noreply@github.com>
Sun, 14 Apr 2024 21:05:15 +0000 (14 21:05 +0000)
tree9a10a2faad9db6d30a1e180e7f9a9af097f34621
parent6ad80360c241a8bc5d39835ff443a6272f5f5bb7
Redesign 'cabal path' command to account for projects (#9583)

* Redesign 'cabal path' command to account for projects

Previously, `cabal path` was only able to query from the global
configuration file, e.g., `~/.cabal/config` or the XDG equivalent.
Adding support for cabal project is a huge boost to usability.

We take the foundations and turn them into `cabal v2-path` which takes
project configuration, such as `cabal.project` into account.
Note, the command is still named `cabal path`, but for the sake of
disambiguation, we refer to this new iteration of the command as `cabal
v2-path`.

In addition, we add support for multiple output formats, such as
key-value pairs and json.

The key-value pair output prints a line for each queried key and its
respective value:

    key1: value2
    key2: value2

If only a single key is queried, we print only the
value, for example:

    value1

The json output format is versioned by the cabal-install version which
is part of the json object.
Thus, all result objects contain at least the key "cabal-install-version".

We expand the `cabal v2-path` to also produce information of the
compiler that is going to be used in a `cabal build` or `cabal repl` invocation.
To do that, we rebuild the install plan and query for the configured
compiler program.
This is helpful for downstream tools, such as HLS, to figure out the GHC
version required to compile a project with.

We also add an exhaustive test suite for 'cabal path' cmd

We test that each query honours cabal.project files, cli parameters, and
is composable with the other query flags.

We extend the test output normalisers for ghc compiler location and
cabal-install version, as the 'cabal path' command outputs the exact ghc
and ghc-pkg location. In addition, the json output format is versioned
on the cabal-install version.

Currently, we query the cabal-install version on each test normalisation
run. This might be unnecessary expensive, and could be avoided by
introducing a 'cabalProgram' that specifies how the program version can
be found. This way, we can cache the version query.

Add '--cache-home' flag thats shows the cabal's cache root

Rename '--cache-dir' to the more correct '--remote-repo-dir'.

* Update 'cabal path' documentation

* Add changelog.d entry

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
23 files changed:
cabal-install/cabal-install.cabal
cabal-install/src/Distribution/Client/CmdPath.hs [new file with mode: 0644]
cabal-install/src/Distribution/Client/Config.hs
cabal-install/src/Distribution/Client/Errors.hs
cabal-install/src/Distribution/Client/Main.hs
cabal-install/src/Distribution/Client/ScriptUtils.hs
cabal-install/src/Distribution/Client/Setup.hs
cabal-testsuite/PackageTests/Path/All/cabal.out
cabal-testsuite/PackageTests/Path/All/cabal.test.hs
cabal-testsuite/PackageTests/Path/Compiler/cabal.out [new file with mode: 0644]
cabal-testsuite/PackageTests/Path/Compiler/cabal.test.hs [new file with mode: 0644]
cabal-testsuite/PackageTests/Path/Config/cabal.out [new file with mode: 0644]
cabal-testsuite/PackageTests/Path/Config/cabal.test.hs [new file with mode: 0644]
cabal-testsuite/PackageTests/Path/Config/config.cabal [new file with mode: 0644]
cabal-testsuite/PackageTests/Path/Config/fake-cabal.config [new file with mode: 0644]
cabal-testsuite/PackageTests/Path/Config/fake.cabal.project [new file with mode: 0644]
cabal-testsuite/PackageTests/Path/Single/cabal.out [deleted file]
cabal-testsuite/PackageTests/Path/Single/cabal.test.hs [deleted file]
cabal-testsuite/src/Test/Cabal/Monad.hs
cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs
cabal-testsuite/src/Test/Cabal/Prelude.hs
changelog.d/pr-9583 [new file with mode: 0644]
doc/cabal-commands.rst