Description
It would be good in many ways if Cabal resolved some project, package and component from anywhere on the file system. To name a few:
- Annoying errors such as this would go away:
% cabal repl cabal: No targets given and there is no package in the current directory. Use the target 'all' for all packages in the project or specify packages or components by name or location. See 'cabal build --help' for more details on target options.
- A default project, package and component would provide a default environment for using
ghci
as a calculator. One can add their favourite dependencies and language extensions, andcabal repl
would respect that.
There are two ways to accomplish this.
The strong way.
The strong way is to wire into Cabal how to resolve a project, package and component from anywhere in the file system. Properties:
- Backwards compatibility. The assignment of a project, package and component is an extension of the partial assignment that we already have.
- Totality. From any place in the file system, there is a unique assignment of a project, package and component.
This assumes that a default project is always there. Cabal would initialize it as needed.
The weak way.
The weak way is to make Cabal respect an environment variable pointing to a default project but otherwise behave the same. We still require backwards compatibility, but not totality. Currently, there are two ways to resolve a project, in the order of precedence:
- The command line option
--project-file
. - The presence of
cabal.project
or*.cabal
anywhere in or above the current working directory.
We add another way:
- The presence of an environment variable.
So, due to its lower precedence, Cabal will ignore the environment variable if already in a project or a package.
Cabal will not uniquely resolve a package or a component if there are several of them in the project pointed at, so annoying errors stay. This way only covers the calculator use case. The user is responsible for setting the project up and wiring it into Cabal via the environment variable.
We can also combine both ways: have hard wired defaulting and allow overriding the default project, package and component by an environment variable. This would allow one to swap the default project at will.
This has been previously discussed in #6481.
I can write the code.