使用cabal v2-install构建可执行文件时冻结所有依赖项

时间:2019-08-24 13:07:39

标签: haskell cabal cabal-install cabal-new

我正在构建一个Docker映像,我想在其中捆绑多个可执行文件。每个可执行文件在不同的包中定义,在我的情况下为pandocpandoc-citeprocpandoc-crossref。构建应在基于Debian / Ubuntu的系统上尽可能合理地再现。

我想做的是使用 cabal.project.freeze 文件(类似文件)来确保所有后续构建都将使用相同的软件包。

我知道我可以修复可执行文件的版本:

cabal v2-install pandoc-2.7.3 pandoc-citeproc-0.16.2 pandoc-crossref-0.3.4.1

但是,这不能修复传递依赖的版本,因此在不同时间进行重建可能会导致生成结果略有不同。我可以在此设置中以某种方式创建和使用 freeze 文件吗?在这里使用v2-freeze似乎毫无用处:

$ cabal new-freeze pandoc-2.7.3 pandoc-citeproc-0.16.2 pandoc-crossref-0.3.4.1
cabal: 'freeze' doesn't take any extra arguments: pandoc-2.7.3
pandoc-citeproc-0.16.2 pandoc-crossref-0.3.4.1

1 个答案:

答案 0 :(得分:2)

好的,也许可以使用更好的内置方法来完成这种事情,但是在真正的阴谋专家出现之前,这里有一个hacky的解决方法可能适合您。

基本计划是这样的:使用您关心的三个软件包临时创建一个项目-足够长的时间来获取冻结文件-然后使用一些简单的文本编辑器宏将冻结文件转换为{{ 1}}命令。所以:

v2-install

糟糕,最后一个是一口。它说:

% cabal unpack pandoc-2.7.3 pandoc-citeproc-0.16.2 pandoc-crossref-0.3.4.1
% echo >cabal.project packages: pandoc-2.7.3 pandoc-citeproc-0.16.2 pandoc-crossref-0.3.4.1
% cabal v2-freeze
% sed "s/^constraints: /cabal v2-install pandoc-2.7.3 pandoc-citeproc-0.16.2 pandoc-crossref-0.3.4.1 --constraint '/;s/^ \+/--constraint '/;s/,\$/' \\\\/;\$s/\$/'/" cabal.project.freeze >cabal-v2-install.sh

如果需要,也可以在编辑器中手动执行这些操作。在此过程结束时,您可以在一个临时目录中运行以简化之后的清理工作,您应该拥有一个名为# Replace the starting "constraints" stanza with the v2-install command we want to # run. The first line of the stanza includes a constraint, so prefix it with # --constraint and start a quote. s/^constraints: /cabal v2-install pandoc-2.7.3 pandoc-citeproc-0.16.2 pandoc-crossref-0.3.4.1 --constraint '/ # The line we just produced doesn't start with spaces, so this only fires on the # remaining lines. On those lines, it prefixes --constraint and starts a quote. s/^ \+/--constraint '/ # Close the quote begun on each line, and replace cabal's line-continuation # character (,) with a shell's line-continuation character (\). The $ and \ are # escaped because we are inside the current shell's ""-quoted string. s/,\$/' \\\\/ # The last line doesn't have a line-continuation character, but still needs its # quote closed. The two occurrences of $ are escaped because we are inside the # current shell's ""-quoted string. \$s/\$/'/ 的文件,该文件的命令将为涉及的所有程序包(包括依赖项)选择完全相同的版本和标志。

相关问题