cabal icon indicating copy to clipboard operation
cabal copied to clipboard

`cabal v2-install --ignore-project` crashes when project file is present

Open andreasabel opened this issue 3 years ago • 7 comments

Reproducer:

DIR=$(mktemp -d)
cd $DIR
${CABAL:-cabal} init -n --exe --application-dir=app
echo "optimization: False" > cabal.project.local
${CABAL:-cabal} install --ignore-project

This crashes with (current master):

...
Error: cabal: Invalid package ID: .
"<eitherParsec>" (line 1, column 2):
unexpected all digits or a dot in a portion of package name
expecting "-"

Same problem with cabal.project instead of cabal.project.local.

Behavior of previous versions of cabal-install:

cabal-3.0: unrecognized 'install' option `--ignore-project'
cabal-3.2: Invalid package ID: .

From 3.4 it is the same error as today.

What is my interest in cabal v2-install --ignore-project?

I'd like to develop with -O0 (via optimization: False in a project file), but deploy to my system with default optimization (-O1). Originally, I would have expected that cabal v2-install ignores the project files by default, because it behaves as if it installs from the sdisted tarball, which does (in my case) not contain any cabal.project* files. But this does not seem to be the case. There is a long discussion of the complex at:

  • #7297

In https://github.com/haskell/cabal/issues/7297#issuecomment-1048797853 it is suggested to use --ignore-project to this end, but it does not work as expected...

andreasabel avatar Apr 09 '22 20:04 andreasabel

In https://github.com/haskell/cabal/issues/7297#issuecomment-1048797853 it is suggested to use --ignore-project to this end, but it does not work as expected...

sorry i did not make it clear in the comment but that was in the context of a hypothetical fix for the bug and that would be a feature to be added to allow opting out the behaviour that fix would set

jneira avatar Apr 10 '22 18:04 jneira

Maybe then the concrete fix would be to remove --ignore-project from the options of cabal install? Or does it have some use for remote installation?

andreasabel avatar Apr 11 '22 10:04 andreasabel

Related issues:

  • https://github.com/haskell/cabal/issues/7057 asking to add --ignore-project to v2-build. I think some v2 commands honour --ignore-project, like v2-run, v2-repl, v2-exec?.
    • Not sure what is the status of that but v2-sdist does not have suppor for: https://github.com/haskell/cabal/issues/7965
  • https://github.com/haskell/cabal/issues/6942 afaics describing the behaviour for older cabal versions (so maybe we could close it)

jneira avatar Apr 11 '22 12:04 jneira

I was looking into what it would take to fix #7965 and make the --ignore-project flag in the v2-sdist command work as intended but I'm not sure what the intended functionality is and the code seems to contradict itself.

It looks like there are two ideas competing against each other with the --ignore-project flag. Should the flag: A) Ignore the cabal.project file in the current directory and look for a project file in the parent directories. B) Ignore project files all together and create the project config from only the defaults and whatever is set from command line flags.

I assume looking in the parent directories is what it means by "GlobalConfig" in the withProjectOrGlobalConfig function in ProjectConfig.hs but I'm not sure what the intended functionality actually is.

I wasn't sure whether to add this comment to this issue or #7965 but this seemed more appropriate because it's being talked about and still has to do with the --ignore-project flag and the functionality seems to be the same whatever the given command is that supports it.

erinclemmer avatar Apr 12 '22 02:04 erinclemmer

the globalConfig is not a project file in parent directories -- that's still a "project" config, just one found in another directory. The global config referred to in that function is, as I understand it, the ~/.cabal/config file.

gbaz avatar Apr 12 '22 03:04 gbaz

@gbaz ok, the reason I said that is that it looks like if you run cabal sdist --ignore-project on a subdirectory of your project (such as the cabal-install directory of the cabal project) it will load the global config from ~/.cabal but if you do it on the same directory as the cabal.project file it will use that project file. That seems like a bug to me, and I assume the intended functionality is that it --ignore-project would always ignore the local cabal.project file and always use the global one, right?

erinclemmer avatar Apr 12 '22 15:04 erinclemmer

That sounds correct to me.

gbaz avatar Apr 12 '22 16:04 gbaz