cabal icon indicating copy to clipboard operation
cabal copied to clipboard

`cabal install pkg-x.y.z` fails unless `--ignore-project` is given

Open andreasabel opened this issue 3 years ago • 3 comments

If you sit in a local project directory and cabal install a remote package, you cannot give its version suffix unless you also pass --ignore-project.

Reproducer:

  1. change to a cabal project root
  2. cabal install fix-whitespace-0.0.8 fails:
    Error: 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.
    
  3. cabal install fix-whitespace succeeds
  4. cabal install --ignore-project fix-whitespace-0.0.8 also succeeds

In the wild: https://github.com/haskell/cabal/runs/7509048343?check_suite_focus=true#step:6:1

Run cabal install --install-method=copy --installdir=$HOME/.local/bin fix-whitespace-0.0.8 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.

andreasabel avatar Jul 26 '22 08:07 andreasabel

I think there were suggestions in some other tickets to make cabal install foo ignore the current project file. As it stands, it fully takes the file into account (e.g., using flags and constraints from the file), which probably also manifests in the strange way you mention.

Mikolaj avatar Jul 26 '22 08:07 Mikolaj

Hmm, there is another factor, the command fails if there is no .cabal files in the project root dir (the layout of cabal repo itself) but

  • mkdir test && cd test && cabal init -n && cabal install haskell-say-1.0.0.0 works
  • in the cabal repo cd cabal-install && cabal install haskell-say-1.0.0.0 also works

As stated in that issue cabal install foo should be affected by project configuration cause you could have a constraint: foo > 1.1 in your cabal.project. That is the case if package foo contains a library used in your project but it also contains an executable which you might use. And that is a design decision (which could be revisited of course)

jneira avatar Jul 26 '22 15:07 jneira

What is surprising to me is that $PACKAGE-$VERSION can be a local target. What is the use of that? Intuitively, I would always associate a remote target with the form $PACKAGE-$VERSION. But clearly, the OP points out a bug: that $PACKAGE is recognized as remote target but $PACKAGE-$VERSION is not.

andreasabel avatar Jul 26 '22 15:07 andreasabel