Combine post install commands in 'postInst' and add 'postCopy' hook.
The creation of the 'git-annex-shell' symlink was in 'postInst' hook. I combined it with the man-page installation in a 'postInst' hook and a 'postCopy' hook. I don't understand how to use the `cabal copy` command, but the examples I looked at defined both hooks. Relevant comments from the source: * man-page installation: See http://www.haskell.org/haskellwiki/Cabal/Developer-FAQ#Installing_manpages. Based on pandoc's and lhs2tex's 'Setup.installManpages' and 'postInst' hooks. My understanding: 'postCopy' is run for `cabal copy`, 'postInst' is run for `cabal inst`, and copy is not a generalized install, so you have to write two nearly identical hooks. Summary of hooks: http://www.haskell.org/cabal/release/cabal-latest/doc/API/Cabal/Distribution-Simple-UserHooks.htm-- Other people are also confused: * Bug: 'postCopy' and 'postInst' are confusing: http://hackage.haskell.org/trac/hackage/ticket/718 * A cabal maintainer suggests using 'postCopy' instead of 'postInst', because `cabal install` is `cabal copy` followed by `cabal register`: http://www.haskell.org/pipermail/libraries/2008-March/009416.html Although that sounds desirable, it's not true, as the reply and experiments indicate. * the `cabal copy` command: ???: Not sure how you're supposed to use this. E.g., when I do cabal install --prefix=/tmp/git-annex-install cabal copy --deistdir=/tmp/git-annex-copy I get the copy under /tmp/git-annex-copy/tmp/git-annex-install Also, `cabal install` fails when given a relative --prefix.
This commit is contained in:
parent
7eb649612a
commit
6c8507ee1b
1 changed files with 66 additions and 29 deletions
91
Setup.hs
91
Setup.hs
|
@ -1,55 +1,92 @@
|
||||||
|
{-# LANGUAGE NamedFieldPuns #-}
|
||||||
{- cabal setup file -}
|
{- cabal setup file -}
|
||||||
|
|
||||||
import Distribution.Simple
|
import Distribution.Simple
|
||||||
import Distribution.Simple.LocalBuildInfo
|
import Distribution.Simple.LocalBuildInfo
|
||||||
import Distribution.Simple.Setup
|
import Distribution.Simple.Setup
|
||||||
import Distribution.Simple.Utils (installOrdinaryFiles)
|
import Distribution.Simple.Utils (installOrdinaryFiles, rawSystemExit)
|
||||||
import Distribution.PackageDescription (PackageDescription(..))
|
import Distribution.PackageDescription (PackageDescription(..))
|
||||||
import Distribution.Verbosity (Verbosity)
|
import Distribution.Verbosity (Verbosity)
|
||||||
import System.Cmd
|
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
|
|
||||||
import qualified Build.Configure as Configure
|
import qualified Build.Configure as Configure
|
||||||
|
|
||||||
main = defaultMainWithHooks simpleUserHooks
|
main = defaultMainWithHooks simpleUserHooks
|
||||||
{ preConf = configure
|
{ preConf = configure
|
||||||
, instHook = install
|
, postInst = myPostInst
|
||||||
, postInst = const installManpages
|
, postCopy = myPostCopy
|
||||||
}
|
}
|
||||||
|
|
||||||
configure _ _ = do
|
configure _ _ = do
|
||||||
Configure.run Configure.tests
|
Configure.run Configure.tests
|
||||||
return (Nothing, [])
|
return (Nothing, [])
|
||||||
|
|
||||||
install pkg_descr lbi userhooks flags = do
|
myPostInst :: Args -> InstallFlags -> PackageDescription
|
||||||
r <- (instHook simpleUserHooks) pkg_descr lbi userhooks flags
|
-> LocalBuildInfo -> IO ()
|
||||||
_ <- rawSystem "ln" ["-sf", "git-annex",
|
myPostInst _ (InstallFlags { installVerbosity }) pkg lbi = do
|
||||||
bindir installDirs </> "git-annex-shell"]
|
installGitAnnexShell dest verbosity pkg lbi
|
||||||
return r
|
installManpages dest verbosity pkg lbi
|
||||||
where
|
where
|
||||||
installDirs = absoluteInstallDirs pkg_descr lbi $
|
dest = NoCopyDest
|
||||||
fromFlag (copyDest defaultCopyFlags)
|
verbosity = fromFlag installVerbosity
|
||||||
|
|
||||||
|
-- ???: Not sure how you're supposed to use this. E.g., when I do
|
||||||
|
--
|
||||||
|
-- cabal install --prefix=/tmp/git-annex-install
|
||||||
|
-- cabal copy --deistdir=/tmp/git-annex-copy
|
||||||
|
--
|
||||||
|
-- I get the copy under
|
||||||
|
--
|
||||||
|
-- /tmp/git-annex-copy/tmp/git-annex-install
|
||||||
|
--
|
||||||
|
-- Also, `cabal install` fails when given a relative --prefix.
|
||||||
|
myPostCopy :: Args -> CopyFlags -> PackageDescription
|
||||||
|
-> LocalBuildInfo -> IO ()
|
||||||
|
myPostCopy _ (CopyFlags { copyDest, copyVerbosity }) pkg lbi = do
|
||||||
|
installGitAnnexShell dest verbosity pkg lbi
|
||||||
|
installManpages dest verbosity pkg lbi
|
||||||
|
where
|
||||||
|
dest = fromFlag copyDest
|
||||||
|
verbosity = fromFlag copyVerbosity
|
||||||
|
|
||||||
|
installGitAnnexShell :: CopyDest -> Verbosity -> PackageDescription
|
||||||
|
-> LocalBuildInfo -> IO ()
|
||||||
|
installGitAnnexShell copyDest verbosity pkg lbi =
|
||||||
|
rawSystemExit verbosity "ln"
|
||||||
|
["-sf", "git-annex", dstBinDir </> "git-annex-shell"]
|
||||||
|
where
|
||||||
|
dstBinDir = bindir $ absoluteInstallDirs pkg lbi copyDest
|
||||||
|
|
||||||
-- See http://www.haskell.org/haskellwiki/Cabal/Developer-FAQ#Installing_manpages.
|
-- See http://www.haskell.org/haskellwiki/Cabal/Developer-FAQ#Installing_manpages.
|
||||||
--
|
--
|
||||||
-- Based on pandoc's 'Setup.installManpages' and 'postInst' hook.
|
-- Based on pandoc's and lhs2tex's 'Setup.installManpages' and
|
||||||
-- Would be easier to just use 'rawSystem' as above.
|
-- 'postInst' hooks.
|
||||||
--
|
--
|
||||||
-- XXX: lhs2tex installs man pages with the 'postCopy' hook.
|
-- My understanding: 'postCopy' is run for `cabal copy`, 'postInst' is
|
||||||
-- I chose 'postInst'. Pandoc uses both :P So, probably
|
-- run for `cabal inst`, and copy is not a generalized install, so you
|
||||||
-- to use the 'postCopy' hook.
|
-- have to write two nearly identical hooks.
|
||||||
|
--
|
||||||
|
-- Summary of hooks:
|
||||||
|
-- http://www.haskell.org/cabal/release/cabal-latest/doc/API/Cabal/Distribution-Simple-UserHooks.htm--
|
||||||
|
-- Other people are also confused:
|
||||||
|
--
|
||||||
|
-- * Bug: 'postCopy' and 'postInst' are confusing:
|
||||||
|
-- http://hackage.haskell.org/trac/hackage/ticket/718
|
||||||
|
--
|
||||||
|
-- * A cabal maintainer suggests using 'postCopy' instead of
|
||||||
|
-- 'postInst', because `cabal install` is `cabal copy` followed by
|
||||||
|
-- `cabal register`:
|
||||||
|
-- http://www.haskell.org/pipermail/libraries/2008-March/009416.html
|
||||||
|
-- Although that sounds desirable, it's not true, as the reply and
|
||||||
|
-- experiments indicate.
|
||||||
--
|
--
|
||||||
-- XXX: fix tabs!
|
-- XXX: fix tabs!
|
||||||
installManpages :: InstallFlags -> PackageDescription -> LocalBuildInfo -> IO ()
|
installManpages :: CopyDest -> Verbosity -> PackageDescription
|
||||||
installManpages flags pkg lbi =
|
-> LocalBuildInfo -> IO ()
|
||||||
installOrdinaryFiles verbosity dstManDir manpages
|
installManpages copyDest verbosity pkg lbi =
|
||||||
|
installOrdinaryFiles verbosity dstManDir srcManpages
|
||||||
where
|
where
|
||||||
|
dstManDir = mandir (absoluteInstallDirs pkg lbi copyDest) </> "man1"
|
||||||
|
srcManpages = zip (repeat srcManDir) manpages
|
||||||
srcManDir = ""
|
srcManDir = ""
|
||||||
-- The 'NoCopyDest' means "don't add an additional path prefix".
|
manpages = ["git-annex.1", "git-annex-shell.1"]
|
||||||
-- The pandoc Setup.hs uses 'NoCopyDest' in the post install hook
|
|
||||||
-- and the 'CopyDest' from the copy flags in the post copy hook.
|
|
||||||
dstManDir = mandir (absoluteInstallDirs pkg lbi NoCopyDest) </> "man1"
|
|
||||||
manpages = zip (repeat srcManDir)
|
|
||||||
[ "git-annex.1"
|
|
||||||
, "git-annex-shell.1" ]
|
|
||||||
verbosity = fromFlag $ installVerbosity flags
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue