简体   繁体   English

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

[英]Cabal after build command (Haskell build system)

Is it possible to tell Cabal to run some command after building the application? 是否有可能在构建应用程序后告诉Cabal运行某些命令?

I want for example to generate with a script some .hs files and after building to copy some other files to dist/build/app directory. 我希望例如使用脚本生成一些.hs文件,并在构建之后将其他一些文件复制到dist/build/app目录。

Yes. 是。 Take a look at postInst and related types/operations. 看一下postInst和相关的类型/操作。

Distribution.Simple.UserHooks Distribution.Simple.UserHooks

Here's a quick example, you can hoogle the relevant operations to figure out more. 这是一个快速示例,您可以通过相关操作来了解更多信息。 This executes the various .sh scripts, copies files etc. AFTER the cabal build. 这将执行各种.sh脚本,复制文件等。在cabal构建之后。 absoluteInstallDirs tells you where cabal is putting the other files, should you need it. 如果需要, absoluteInstallDirs告诉您cabal放置其他文件的位置。

Hope this helps! 希望这可以帮助!

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 } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM