haskell / haskell/cabal

Packages are resolved w.r.t to project-file path when absolute, but not when relative

Open
#7,695 25 comments 0 reactions 1 assignee Claimed by @gbaz View on GitHub
attention: pr-welcome cabal-install: other documentation re: project root re: project-file type: bug type: user-question
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

**Describe the bug**
When a project-file is passed as an absolute path that is not in the current directory. cabal seems to be resolving the packages location relative to where the file is located. This doesn't happen if the file path is relative.
Is this a bug or correct behaviour?

**To Reproduce**
Steps to reproduce the behavior:

```
[nix-shell:~/src/tmp]$ mkdir foo

[nix-shell:~/src/tmp]$ cd foo/

[nix-shell:~/src/tmp/foo]$ cabal init
Guessing dependencies...

Generating LICENSE...
Warning: unknown license type, you must put a copy in LICENSE yourself.
Generating CHANGELOG.md...
Generating app/Main.hs...
Generating foo.cabal...

Warning: no synopsis given. You should edit the .cabal file and add one.
You may want to edit the .cabal file and add a Description field.

[nix-shell:~/src/tmp/foo]$ cd ..

[nix-shell:~/src/tmp]$ echo "packages: foo" > ../cabal.project

[nix-shell:~/src/tmp]$ cabal v2-clean; cabal v2-build all --project-file ../cabal.project
Resolving dependencies...
Build profile: -w ghc-8.10.4 -O1
In order, the following will be built (use -v for more details):
- foo-0.1.0.0 (exe:foo) (first run)
Configuring executable 'foo' for foo-0.1.0.0..
Preprocessing executable 'foo' for foo-0.1.0.0..
Building executable 'foo' for foo-0.1.0.0..
[1 of 1] Compiling Main ( app/Main.hs, /home/pranaysashank/src/tmp/dist-newstyle/build/x86_64-linux/ghc-8.10.4/foo-0.1.0.0/x/foo/build/foo/foo-tmp/Main.o )
Linking /home/pranaysashank/src/tmp/dist-newstyle/build/x86_64-linux/ghc-8.10.4/foo-0.1.0.0/x/foo/build/foo/foo ...

[nix-shell:~/src/tmp]$ cabal v2-clean; cabal v2-build all --project-file /home/pranaysashank/src/cabal.project
When using configuration(s) from /home/pranaysashank/src/cabal.project, the following errors occurred:
The package location 'foo' does not exist.

[nix-shell:~/src/tmp]$
```

**Expected behavior**
Expect cabal to resolve the packages field relative to where I run cabal file or have a consistent behaviour with both relative and absolute file paths.

**System information**
- Operating system: nixos - 21.05
- `cabal`, `ghc` versions: 3.4, 8.10.4

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.