4

是否可以在构建应用程序后告诉 Cabal 运行某些命令?

例如,我想用脚本生成一些.hs文件,并在构建后将一些其他文件复制到dist/build/app目录。

4

1 回答 1

3

是的。看看postInst和相关的类型/操作。

Distribution.Simple.UserHooks

这是一个简单的示例,您可以通过 hoogle 相关操作来了解更多信息。这会在 cabal 构建之后执行各种 .sh 脚本、复制文件等。 absoluteInstallDirs告诉你 cabal 将其他文件放在哪里,如果你需要的话。

希望这可以帮助!

import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import System.Process
import System.Exit

main = defaultMainWithHooks fixpointHooks

fixpointHooks  = simpleUserHooks { postInst = buildAndCopyFixpoint } 

buildAndCopyFixpoint _ _ pkg lbi 
  = do putStrLn $ "Post Install: " ++ show binDir -- , libDir)
       executeShellCommand "./configure"
       executeShellCommand "./build.sh"
       executeShellCommand $ "chmod a+x external/fixpoint/fixpoint.native "
       executeShellCommand $ "cp external/fixpoint/fixpoint.native " ++ binDir
       executeShellCommand $ "cp external/z3/lib/libz3.* " ++ binDir
  where 
    allDirs     = absoluteInstallDirs pkg lbi NoCopyDest
    binDir      = bindir allDirs ++ "/"

executeShellCommand cmd   = putStrLn ("EXEC: " ++ cmd) >> system cmd >>= check
  where 
    check (ExitSuccess)   = return ()
    check (ExitFailure n) = error $ "cmd: " ++ cmd ++ " failure code " ++ show n
fixpointHooks  = simpleUserHooks { postInst = buildAndCopyFixpoint } 
于 2013-07-12T20:32:45.887 回答