Created
June 5, 2012 17:07
-
-
Save creswick/2876277 to your computer and use it in GitHub Desktop.
Cabal Setup.hs to copy scripts during postInst:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad ( unless ) | |
import Distribution.Simple | |
import Distribution.Simple.Program.Types ( Program(..), simpleProgram ) | |
import Distribution.PackageDescription ( PackageDescription(..), executables, | |
hsSourceDirs, exeName, buildInfo ) | |
import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..), buildDir, bindir | |
, substPathTemplate, absoluteInstallDirs ) | |
import Distribution.Simple.Setup ( InstallFlags(..), BuildFlags, Flag, fromFlag | |
, buildVerbose, CopyFlags(..), defaultCopyFlags ) | |
import Distribution.Simple.Utils ( rawSystemExit, findProgramVersion) | |
import Distribution.Verbosity ( Verbosity ) | |
import System.Directory ( doesDirectoryExist, copyFile ) | |
import System.FilePath ( (</>) ) | |
main = defaultMainWithHooks $ | |
simpleUserHooks { hookedPrograms = [cabalInstallProgram] | |
, postInst = postInstCp (postInst simpleUserHooks) | |
} | |
type PostInstHook = Args -> InstallFlags -> PackageDescription -> LocalBuildInfo -> IO () | |
postInstCp :: PostInstHook -> Args -> InstallFlags -> PackageDescription -> LocalBuildInfo -> IO () | |
postInstCp oldHook args iflags pDesc lbi = do | |
let -- The filename to copy from. This assumes 'srcFileName.sh' is adjacent to Setup.hs: | |
inFile :: FilePath | |
inFile = "srcFileName.sh" | |
-- The filename to copy to: | |
outFile :: FilePath | |
outFile = "destFileName.sh" | |
prefix = fromFlag $ installDistPref iflags | |
-- Make a concrete binDir from the LocalBuildInfo & PackageDescription: | |
instBinDir :: FilePath | |
instBinDir = bindir $ absoluteInstallDirs pDesc lbi | |
(fromFlag $ copyDest defaultCopyFlags) | |
-- layer of indirection, in case we wanted to get a specific | |
-- src directory from the cabal file: | |
src :: FilePath | |
src = inFile | |
-- qualify the destination. | |
dest :: FilePath | |
dest = instBinDir </> outFile | |
-- Do the copy, creating outFile in the bin dir: | |
copyFile src dest | |
-- now invoke the old hook: | |
oldHook args iflags pDesc lbi | |
cabalInstallProgram :: Program | |
cabalInstallProgram = (simpleProgram "cabal") { | |
programFindVersion = findProgramVersion "--numeric-version" id | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment