`cabal install parsec` error inconsistent inside and outside project
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
**Describe the bug**
Running `cabal install P` where `P` is a package without executables should fail, and it does. However, it fails in different ways outside and inside a project.
Inside a project, it prints:
```
Error: [Cabal-7127]
Cannot build the executables in the package parsec because it does not contain any executables. Check the .cabal file for the package and make sure that it properly declares the components that you expect.
```
Outside a project, it prints:
```
Warning:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: Installation might not be completed as desired! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The command "cabal install [TARGETS]" doesn't expose libraries.
* You might have wanted to add them as dependencies to your package. In this
case add "parsec" to the build-depends field(s) of your package's .cabal file.
* You might have wanted to add them to a GHC environment. In this case use
"cabal install --lib parsec". The "--lib" flag is provisional: see
https://github.com/haskell/cabal/issues/6481 for more information.
Warning:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: Installation might not be completed as desired! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The command "cabal install [TARGETS]" doesn't expose libraries.
* You might have wanted to add them as dependencies to your package. In this
case add "parsec" to the build-depends field(s) of your package's .cabal file.
* You might have wanted to add them to a GHC environment. In this case use
"cabal install --lib parsec". The "--lib" flag is provisional: see
https://github.com/haskell/cabal/issues/6481 for more information.
```
Note that the warning is printed twice in the latter case.
Related to #9706, issue created as prompted by @andreabedini.
**To Reproduce**
Steps to reproduce the behavior:
Long terminal log
```
09:55:08 ~/tmp$ mkdir test-cabal-9706
09:55:15 ~/tmp$ cd test-cabal-9706
09:56:20 ~/t/test-cabal-9706$ cabal init --simple --minimal --lib --non-interactive --tests
[Log] Using cabal specification: 3.0
[Warning] unknown license type, you must put a copy in LICENSE yourself.
[Log] Creating fresh file CHANGELOG.md...
[Log] Creating fresh directory ./src...
[Log] Creating fresh file src/MyLib.hs...
[Log] Creating fresh directory ./test...
[Log] Creating fresh file test/Main.hs...
[Log] Creating fresh file test-cabal9706.cabal...
[Warning] No synopsis given. You should edit the .cabal file and add one.
[Info] You may want to edit the .cabal file and add a Description field.
09:56:23 ~/t/test-cabal-9706$ l
total 24K
drwxr-xr-x 4 tom tom 4.0K Mar 25 09:56 ./
drwxr-xr-x 24 tom tom 4.0K Mar 25 09:54 ../
-rw-r--r-- 1 tom tom 117 Mar 25 09:56 CHANGELOG.md
drwxr-xr-x 2 tom tom 4.0K Mar 25 09:56 src/
drwxr-xr-x 2 tom tom 4.0K Mar 25 09:56 test/
-rw-r--r-- 1 tom tom 624 Mar 25 09:56 test-cabal9706.cabal
09:56:56 ~/t/test-cabal-9706$ ~/git/cabal/cabal install parsec
Warning: this is a debug build of cabal-install with assertions enabled.
Warning: Parsing the index cache failed (Data.Binary.Get.runGet at position
16: Non-matching structured hashes: f46da61e7afa58a5e8fd1d2b6fb79899;
expected: d81bdd513f41b5d7ee4cd28455adadbe). Trying to regenerate the index
cache...
Resolving dependencies...
Error: [Cabal-7127]
Cannot build the executables in the package parsec because it does not contain any executables. Check the .cabal file for the package and make sure that it properly declares the components that you expect.
09:57:13 (9.4s) (1) ~/t/test-cabal-9706$ ~/git/cabal/cabal install parsec --lib
Warning: this is a debug build of cabal-install with assertions enabled.
Resolving dependencies...
09:57:20 ~/t/test-cabal-9706$ cat ~/.ghc/x86_64-linux-9.4.7/environments/default
clear-package-db
global-package-db
package-db /home/tom/.cabal/store/ghc-9.4.7/package.db
package-id base-4.17.2.0
package-id parsec-3.1.17.0-09da8bcf938e9e6c3b3dbc7570a886a002dc211c36d4d5ece77134a1ce44795f
09:57:24 ~/t/test-cabal-9706$ rm ~/.ghc/x86_64-linux-9.4.7/environments/default
09:57:25 ~/t/test-cabal-9706$ cd
09:57:28 ~$ ~/git/cabal/cabal install parsec
Warning: this is a debug build of cabal-install with assertions enabled.
Resolving dependencies...
Warning:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: Installation might not be completed as desired! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The command "cabal install [TARGETS]" doesn't expose libraries.
* You might have wanted to add them as dependencies to your package. In this
case add "parsec" to the build-depends field(s) of your package's .cabal file.
* You might have wanted to add them to a GHC environment. In this case use
"cabal install --lib parsec". The "--lib" flag is provisional: see
https://github.com/haskell/cabal/issues/6481 for more information.
Warning:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: Installation might not be completed as desired! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The command "cabal install [TARGETS]" doesn't expose libraries.
* You might have wanted to add them as dependencies to your package. In this
case add "parsec" to the build-depends field(s) of your package's .cabal file.
* You might have wanted to add them to a GHC environment. In this case use
"cabal install --lib parsec". The "--lib" flag is provisional: see
https://github.com/haskell/cabal/issues/6481 for more information.
09:57:35 ~$ ls ~/.ghc/x86_64-linux-9.4.7/environments/default
ls: cannot access '/home/tom/.ghc/x86_64-linux-9.4.7/environments/default': No such file or directory
09:57:47 (2) ~$ ~/git/cabal/cabal install parsec --lib
Warning: this is a debug build of cabal-install with assertions enabled.
Resolving dependencies...
09:57:56 ~$ cat ~/.ghc/x86_64-linux-9.4.7/environments/default
clear-package-db
global-package-db
package-db /home/tom/.cabal/store/ghc-9.4.7/package.db
package-id base-4.17.2.0
package-id parsec-3.1.17.0-09da8bcf938e9e6c3b3dbc7570a886a002dc211c36d4d5ece77134a1ce44795f
09:57:59 ~$ rm ~/.ghc/x86_64-linux-9.4.7/environments/default
09:58:27 ~$
```
**Expected behavior**
`cabal install parsec` is a global operation that is unrelated to any project in the current directory, and hence I would expect that it does not take settings from any such local project. Thus I expect the behaviour to be identical inside and outside a project.
Furthermore, it's suspicious that outside a project, the warning is printed twice.
**System information**
- Arch Linux
- `cabal`: `master` at the time of writing: [1c1230ca2](https://github.com/haskell/cabal/commit/1c1230ca228cc03a9ee68166243af358ab3992fc).
- `ghc`: 9.4.7
Contributor guide
Assessment
This issue has not been assessed yet.