Skip to content

Cabal does some work behind the back of hooks #283

bos opened this Issue May 24, 2012 · 4 comments

2 participants

Haskell member
bos commented May 24, 2012

(Imported from Trac #290, reported by @igloo on 2008-06-08)

Cabal does some work behind the back of hooks, e.g. with q.cabal:

name: q
version: 1
exposed-modules: Bar
build-type: Custom
and Setup.hs:

module Main (main) where
import Distribution.Simple
import Distribution.Simple.Setup
import System.Cmd
main :: IO ()
main = defaultMainWithHooks myHooks
myHooks :: UserHooks
myHooks = simpleUserHooks {
confHook = \x flags -> do
let flags' = flags { configDistPref = Flag "foo" }
lbi <- (confHook simpleUserHooks) x flags'
system "ls"
return lbi,
postConf = \args flags pd lbi -> do
system "ls"
let flags' = flags { configDistPref = Flag "foo" }
(postConf simpleUserHooks) args flags' pd lbi
return ()
a dist directory magically appears between the configure hook and the postconf hook:

$ ./Setup configure
Configuring q-1...
Setup Setup.hi Setup.hs Setup.o foo q.cabal
Setup Setup.hi Setup.hs Setup.o dist foo q.cabal
$ ls -l dist
-rw-r--r-- 1 ian ian 6411 Jun 8 12:02 setup-config
The reason I want to do this is so that Setup.hs can take care of building itself in multiple ways, using different dist directories.

Haskell member
bos commented May 24, 2012

(Imported comment by @dcoutts on 2008-06-08)

This is the bit:

  localbuildinfo0 <- confHook hooks epkg_descr flags
let localbuildinfo = localbuildinfo0{ pkgDescrFile = mb_pd_file }
writePersistBuildConfig distPref localbuildinfo
let pkg_descr = localPkgDescr localbuildinfo
postConf hooks args flags pkg_descr localbuildinfo
writePersistBuildConfig writes the configuration file which creates the dist dir.

To be honest, I'm not so sure Setup.hs itself should be building in multiple ways and changing the dist dir. It'll make for a very weird package that's not installable in the standard way.

Can't you do it externally? That is have the external script build the package multiple times with different dist dirs and config options?

Haskell member
bos commented May 24, 2012

(Imported comment by @igloo on 2008-06-08)

Why not make the default postConf do the writePersistBuildConfig? And I don't know what's going on with mb_pd_file in that snippet, but could that be moved into a hook too? I'm sure that anything happening outside of a hook is going to bite us at some point.

Haskell member
bos commented May 24, 2012

(Imported comment by @dcoutts on 2008-06-08)

The hooks needs replacing. I don't particularly plan to change anything before then.

Adding important code to postConf is a bit dodgy since old Setup.hs scripts do not know that if they override it they have to call the old one. While I admit that I've recently added code to postConf so it's no longer return (), that is only checking code, so it's no great loss if it is not run. It doesn't break anything.

Haskell member
tibbe commented May 5, 2014

Closing as there's been no activity in years.

We're cleaning up the bug tracker to make it useful again and are thus closing bugs that haven't seen any activity in a long time. Please re-open (or file a new bug) if the problem reappears.

@tibbe tibbe closed this May 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.