“引导”与阴谋集团

发布于 2025-01-07 01:03:08 字数 710 浏览 0 评论 0原文

想象一个像下面这样的 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。

问题如下:

  1. 我怎样才能完全在 Cabal 内完成上述工作?我应该只用钩子来做这个吗? (例如这个。) 如果挂钩必须依赖于要构建的包中的另一个程序怎么办?
  2. 如果 setup.hs 变得足够复杂以至于需要自己的怎么办 依赖管理?
  3. 有没有一个可以做类似事情的 cabalized 包?如果 Happy 包含一个依赖于 Happy 调用的阴谋测试程序,那将是一个完美的例子。

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:

  1. 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?
  2. What if Setup.hs becomes complicated enough that it requires its own
    dependency management?
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌伤ぢ 2025-01-14 01:03:08

当涉及到这样的情况时,阴谋集团是很棘手的。

正如您所说,如果您可以将所有内容都压缩到 Setup.hs 中,那么您就会将遇到的麻烦降到最低。

如果您有非常复杂的预处理器,我建议这样做:

  1. 为每个预处理器制作一个 cabal 包,并具有其自己的依赖项等。因此,对于 stage0,您会有一个像这样的 cabal 文件:

    <前><代码>名称:
    mypackage-stage0
    版本:
    0.1
    ——……

    可执行的 mpk-stage0
    默认语言:
    哈斯克尔2010
    主要是:
    阶段0.hs
    ——……

  2. For stage1,您需要生成源代码,因此在您的 Setup.hs 中为 mypackage-stage1 添加一个 preBuild 挂钩运行mpk-stage0 可执行文件:

    <前><代码>主要=
    defaultMainWithHooks simpleUserHooks
    { 预构建 =
    -- ...涉及`系统“mpk-stage1 Stage1.hs”`的东西
    -- 注意 shell 重定向 `>; bla.hs` 不一定有效
    -- 在所有平台上,因此使您的“mpk-stage1”可执行文件采用
    -- 输出文件参数
    }

    然后,您可以在前一阶段添加构建工具依赖项:

    可执行文件 mpk-stage1
      ——……
      主要是:
        阶段1.hs
      构建工具:
        mypackage-stage0
    

    这应该适用于最近的阴谋集团版本;否则,您可能需要添加 Build-depends: 依赖项。

  3. 每次进行级联更改时,您需要依次重建每个包(这是必要的,因为 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:

  1. Make one cabal package for each preprocessor, with its own dependencies etc. So, for stage0, you would have a cabal file like this:

    Name:
      mypackage-stage0
    Version:
      0.1
    -- ...
    
    Executable mpk-stage0
      Default-language:
        Haskell2010
      Main-is:
        Stage0.hs
      -- ...
    
  2. For stage1, you need to generate the source code, so add a preBuild hook in your Setup.hs for mypackage-stage1 that runs the mpk-stage0 executable:

    main =
      defaultMainWithHooks simpleUserHooks
      { preBuild =
          -- ... something involving `system "mpk-stage1 Stage1.hs"`
          -- Note that shell redirection `> bla.hs` doesn't necessarily work
          -- on all platforms, so make your `mpk-stage1` executable take an
          -- output file argument
      }
    

    You'd then add a build-tool dependency on the previous stage:

    Executable mpk-stage1
      -- ...
      Main-is:
        Stage1.hs
      Build-tools:
        mypackage-stage0
    

    This should work in recent cabal versions; otherwise, you might have to add a Build-depends: dependency instead.

  3. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文