haskell - 构建命令后的 Cabal(Haskell 构建系统)

标签 haskell build compilation cabal post-processing

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

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

最佳答案

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

Distribution.Simple.UserHooks

这是一个简单的示例,您可以搜索相关操作以了解更多信息。 这会在 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/

相关文章:

java - 如何构建android UIAutomator 项目?

java - 未知的编译错误java

Haskell笛卡尔积递归

Haskell:需要了解 Functor 的签名

haskell - 使用 HSpec 和 QuickCheck 验证 Data.Monoid 属性

java - 是否可以在运行时使用 Java 切换类版本?

maven - 如何修复 Maven Mulesoft 代码的构建错误

java - Java 构建工具如何停止重建所有内容?

c++ - 我从使用编译器 c++11 的 uva online judge 那里收到一条错误消息……我不知道为什么会产生这个错误

performance - 带有惰性求值的差分列表的好处