构建应用程序后,是否可以告诉Cabal运行一些命令?构建命令(Haskell构建系统)后的Cabal
我想要例如使用脚本生成一些.hs
文件,并在构建后将一些其他文件复制到dist/build/app
目录。
构建应用程序后,是否可以告诉Cabal运行一些命令?构建命令(Haskell构建系统)后的Cabal
我想要例如使用脚本生成一些.hs
文件,并在构建后将一些其他文件复制到dist/build/app
目录。
是的。看看postInst
和相关类型/操作。
这里有一个简单的例子,你可以hoogle相关操作,以找出更多。 这会执行各种.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可能会更改/中断某些东西,但它可能是你得到的最好的。 – jozefg
我明白这东西去'Setup.hs'? –
@jozefg我真的很害怕你所说的话:( –
这是供最终用户使用还是仅供您自己使用?它总是可能的(如果hackish)简单地将'cabal'包装在一个脚本中并且自己调用cabal。让它直接传达给cabal也是相当容易的 – jozefg
我会撒谎,为最终用户提供“生产就绪方式”。这样的脚本对最终用户也不错 - 但正如我所看到的(基于@RanjitJhala的答案) - 默认情况下是可能的:) –