【问题标题】:Cabal after build command (Haskell build system)构建命令后的 Cabal(Haskell 构建系统)
【发布时间】:2013-07-11 10:24:56
【问题描述】:

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

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

【问题讨论】:

  • 这是针对最终用户还是仅针对您自己?总是有可能(如果 hackish)简单地将 cabal whatever 包装在一个脚本中,该脚本自己执行操作并调用 cabal。它也很容易将参数直接传递给 cabal
  • 我会撒谎为最终用户做“生产就绪方式”。这样的脚本对最终用户来说也不错 - 但正如我所看到的(基于@RanjitJhala 的回答) - 默认情况下是可能的:)

标签: haskell build compilation cabal post-processing


【解决方案1】:

是的。看看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 } 

【讨论】:

  • 这带有一个很大的警告,即 Distribution.Simple.UserHooks 可能会改变/破坏东西,但它可能是你得到的最好的。
  • 我知道这些东西发给Setup.hs?
  • @jozefg 我真的很害怕你所说的:(
  • @danilo2 这让我最近很头疼,我认为无论是包维护者还是 cabal 开发人员都没有完全理解这个问题:因为你不能基于 Cabal lib 版本进行 CPP 条件编译,这意味着当 Cabal 更改您正在使用的某些 API(就像他们为 Distribution.Simple.* 所做的那样)时,包维护者必须要么限制对旧 Cabal 的依赖,要么使用新版本并破坏与旧 Cabal 的所有兼容性。见:github.com/haskell/cabal/issues/18
猜你喜欢
  • 2013-02-04
  • 1970-01-01
  • 1970-01-01
  • 2013-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多