haskell / haskell/cabal

Resolve project, package and component from anywhere.

Open
#7,471 13 comments 1 reaction 0 assignees View on GitHub
type: discussion type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

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, and `cabal 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.

[extension]: https://en.wikipedia.org/wiki/Function_(mathematics)#Restriction_and_extension

## 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:

1. The command line option `--project-file`.
2. The presence of `cabal.project` or `*.cabal` anywhere in or above the current working directory.

We add another way:

3. 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.

Contributor guide

Open the contributing guide

Research direction

Start with the prior discussion in #6481 and review Cabal's current project-resolution precedence: --project-file, cabal.project or *.cabal above the working directory, and the proposed environment variable. Done means an agreed approach resolves the intended project, package, and component for cabal repl from outside a project, while preserving existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system, cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.