是否可以在构建应用程序后告诉 Cabal 运行某些命令?
例如,我想用脚本生成一些.hs
文件,并在构建后将一些其他文件复制到dist/build/app
目录。
是否可以在构建应用程序后告诉 Cabal 运行某些命令?
例如,我想用脚本生成一些.hs
文件,并在构建后将一些其他文件复制到dist/build/app
目录。
是的。看看postInst
和相关的类型/操作。
这是一个简单的示例,您可以通过 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 }