cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Add --ignore-project to v2-build

Open phadej opened this issue 5 years ago • 7 comments

E.g. to prevent looking cabal.project somewhere up in the directory tree

phadej avatar Sep 11 '20 12:09 phadej

This is great. Would be nice for other cabal subcommands as well, i.e. cabal v2-haddock

cohomology avatar Sep 16 '20 19:09 cohomology

I'll throw in another vote of support for this feature.

mightybyte avatar Nov 17 '21 17:11 mightybyte

+1

chessai avatar Apr 14 '23 21:04 chessai

I looked a little bit into it. Quick notes.

  • currently cabal build --ignore-project says unsupported option because this option is explicitly disabled here:

    https://github.com/haskell/cabal/blob/dbfce818242544ff6d4d24faf694393544030651/cabal-install/src/Distribution/Client/CmdBuild.hs#L77-L78

  • cabal build already uses withContextAndSelectors, which, in turn, uses withProjectOrGlobalConfig, which is aware about --ignore-project (it has a separate parameter for it).

So, it'd seem like an interesting experiment to remove the removeIgnoreProjectOption from the options definition. Well, if you try it, then cabal build --ignore-project gives you a baffling:

Error: cabal: There is no <pkgname>.cabal package file or cabal.project file.
To build packages locally you need at minimum a <pkgname>.cabal file. You can
use 'cabal init' to create one.

in a directory with both a cabal file and a project file. It seems like withContextAndSelectors builds a too simplistic of a context for the --ignore-project branch. It does it with establishDummyProjectBaseContext. Comments around the latter say that it's used to

-- | Create a dummy project context, without a .cabal or a .cabal.project file

No wonder we get the error about no .cabal file (see above). I guess, there has to be a less-dummy project context constructor...

ulysses4ever avatar Apr 18 '23 01:04 ulysses4ever

@bacchanalia this code (https://github.com/haskell/cabal/issues/7057#issuecomment-1512316344) intersects with the parts you wrote in the scripts revamp (https://github.com/haskell/cabal/pull/7851). Do you think you could look into supporting --ignore-project for cabal build. I think, properly fixing it may also help in supporting project files for scripts -- something that some people think was a good thing before the revamp.

ulysses4ever avatar Apr 18 '23 14:04 ulysses4ever

@ulysses4ever what do you mean by supporting project files for scripts?

bacchanalia avatar Apr 25 '23 21:04 bacchanalia

@bacchanalia see https://github.com/haskell/cabal/issues/8562#issuecomment-1318269088 and the following discussion

ulysses4ever avatar Apr 25 '23 22:04 ulysses4ever

A possible workaround is to use --project-dir=. as described in #10556.

philderbeast avatar Nov 19 '24 14:11 philderbeast

@philderbeast It only works if you don't have a project file in the current directory, which you often do. But that's a fair point.

ulysses4ever avatar Nov 19 '24 14:11 ulysses4ever