haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.61k stars 691 forks source link

`cabal exec ghc --` vs. `cabal exec -- ghc` vs. `cabal --ghc` #6843

Open jrp2014 opened 4 years ago

jrp2014 commented 4 years ago

This is probably just a documentation issue, but I am struggling to understand what the difference is between these (particularly the first two) cases.

cabal <cabal args> exec ghc -- <ghc args>
cabal <cabal args> exec -- ghc <ghc args>
cabal --ghc <cabal args> exec ... 

I have a couple of cases, with which I am wrestling. The following is aa fragment from a test harness that runs a ghc plugin over some test cases by compiling them:

   62 -- | Use `cabal exec` to run the compilation, so that the smuggler plugin is
   63 -- picked up from the local database.  GHC alone would use the global one.
   64 compile :: FilePath -> Options -> IO ()
   65 compile testcase opts = runProcess_ cabalConfig
   66   where
   67     cabalConfig :: ProcessConfig () () ()
   68     cabalConfig = proc cabalCmd cabalArgs
   69 
   70     cabalCmd :: FilePath
   71     cabalCmd = "cabal"
   72 
   73     cabalArgs :: [String]
   74     cabalArgs =
   75       -- * no sure why it is necessary to mention the smuggler package explicitly,
   76       -- but it appears to be hidden otherwise.
   77       -- * This puts the .imports files that smuggler generates somewhere they
   78       -- can easily be found
   79       ["exec", "ghc", "--",  "-package smuggler", "-v0", "-dumpdir=" ++ testDir, "-fno-code", "-fplugin=Smuggler.Plugin"]
   80         ++ map
   81           ("-fplugin-opt=Smuggler.Plugin:" ++)
   82           ( let ia = importAction opts
   83                 ea = exportAction opts
   84                 p = [show ia, show ea]
   85              in case newExtension opts of
   86                   Nothing -> mkExt ia ea : p -- provide a default extension
   87                   Just e -> e : p
   88           )
   89         ++ [testcase]

Thanks!

fgaz commented 4 years ago

If I remember correctly it does not matter if you put the executable name before or after the --, since the -- just stops cabal's flag parser. For example you could also do cabal <cabal args> exec ghc SomeFile.hs -- <ghc args> (don't actually do this).

The second one may require a custom setup, like cabal-testsuite does. Or you could use a test argument.

By the way another way of getting ghc to pick up the package, instead of using cabal exec, could be to generate an environment file, with some variation of either cabal somecommand --write-ghc-environment-files or cabal install --lib --env

jrp2014 commented 4 years ago

Thanks for this. I'll have a further play,and look up ghc environment files. It would certainly make things faster to avoid the call to cabal just to launch ghx any pointers / references welcome.

Mikolaj commented 3 years ago

Could we turn this discussion and experimentation into documentation improvement? @jrp2014, what do you think?

fgaz commented 3 years ago

By the way the syntax is the same for cabal run (i think there's a similar ticket about it too..) so the docs could be unified.

jrp2014 commented 3 years ago

That'd be great, if we have a valid answer.

Mikolaj commented 3 years ago

Thanks for this. I'll have a further play,and look up ghc environment files. It would certainly make things faster to avoid the call to cabal just to launch ghx any pointers / references welcome.

@jrp2014: any news? anything we can help with?

jrp2014 commented 3 years ago

Didn't realise the ball was in my court. I thought that whoever owns the documentation might refine it.

Mikolaj commented 3 years ago

Huh, if we own it, we'd love to sell it, even for 1$. :) But I didn't intend to trick you into taking ownership. I just thought you are going to try out some hypotheses and then, once we have something that works, we (meaning @fgaz and you:) can together think how to describe it better. I'm afraid we don't have the bandwidth to investigate the problem, document it and only then ask you to verify if that works for you. Your toil is very much needed to move this ticket along at all.