“引导”与阴谋集团
想象一个像下面这样的 Makefile:
stage1 : Stage1.hs
ghc -o stage1 Stage1.hs
Stage1.hs : stage0
stage0 > Stage1.hs
stage0 : Stage0.hs
ghc -o stage0 Stage0.hs
当前目录首先包含 Makefile 和 Stage0.hs,并生成 stage1。
问题如下:
Imagine an Makefile like the following:
stage1 : Stage1.hs
ghc -o stage1 Stage1.hs
Stage1.hs : stage0
stage0 > Stage1.hs
stage0 : Stage0.hs
ghc -o stage0 Stage0.hs
The current directory would contain Makefile and Stage0.hs at first,and produce stage1.
Here are the questions:
- How can I do the above entirely within Cabal? Am I supposed to do this only with hooks?
(like this or this.)
What if the hook must depend on another program in the package to be built? - What if Setup.hs becomes complicated enough that it requires its own
dependency management? - Is there a cabalized package that does similar things? If Happy included a cabalized test program that depended on Happy invocation, that would have been a perfect example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当涉及到这样的情况时,阴谋集团是很棘手的。
正如您所说,如果您可以将所有内容都压缩到
Setup.hs
中,那么您就会将遇到的麻烦降到最低。如果您有非常复杂的预处理器,我建议这样做:
为每个预处理器制作一个 cabal 包,并具有其自己的依赖项等。因此,对于
stage0
,您会有一个像这样的 cabal 文件:<前><代码>名称:
mypackage-stage0
版本:
0.1
——……
可执行的 mpk-stage0
默认语言:
哈斯克尔2010
主要是:
阶段0.hs
——……
For
stage1
,您需要生成源代码,因此在您的Setup.hs
中为mypackage-stage1
添加一个preBuild
挂钩运行mpk-stage0
可执行文件:<前><代码>主要=
defaultMainWithHooks simpleUserHooks
{ 预构建 =
-- ...涉及`系统“mpk-stage1 Stage1.hs”`的东西
-- 注意 shell 重定向 `>; bla.hs` 不一定有效
-- 在所有平台上,因此使您的“mpk-stage1”可执行文件采用
-- 输出文件参数
}
然后,您可以在前一阶段添加构建工具依赖项:
这应该适用于最近的阴谋集团版本;否则,您可能需要添加
Build-depends:
依赖项。每次进行级联更改时,您将需要依次重建每个包(这是必要的,因为 cabal 不管理跨项目依赖项更改),因此您需要一个脚本
对于 mypackage-stage0 mypackage-stage1 中的项目; do (cd $project; cabal install);完成
或类似的东西。Cabal 从来就不是为此类项目构建的,因此如果您想做这样的事情,将会很棘手。如果您想以更连贯的方式生成代码,您应该考虑使用 Template Haskell。
Cabal is tricky when it comes to situations like these.
As you said, if you can squeeze everything into
Setup.hs
, you'll keep the number of headaches you'll get to a minimum.If you have really complicated preprocessors, I would suggest doing this:
Make one cabal package for each preprocessor, with its own dependencies etc. So, for
stage0
, you would have a cabal file like this:For
stage1
, you need to generate the source code, so add apreBuild
hook in yourSetup.hs
formypackage-stage1
that runs thempk-stage0
executable:You'd then add a build-tool dependency on the previous stage:
This should work in recent cabal versions; otherwise, you might have to add a
Build-depends:
dependency instead.You will need to rebuild each package in turn every time you do a cascading change (This is necessary because cabal doesn't manage cross-project dependency changes), so you need a script that does
for project in mypackage-stage0 mypackage-stage1; do (cd $project; cabal install); done
or something similar.Cabal was never built for this kind of project, so it will be tricky if you want to do something like this. You should look into using Template Haskell instead if you want to generate code in a more coherent way.