是否可以在构建应用程序后告诉 Cabal 运行某些命令?
例如,我想使用脚本生成一些 .hs
文件,并在构建后将一些其他文件复制到 dist/build/app
目录。
最佳答案
是的。查看 postInst
和相关类型/操作。
这是一个简单的示例,您可以搜索相关操作以了解更多信息。
这会在 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 }
关于haskell - 构建命令后的 Cabal(Haskell 构建系统),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17622331/