簡體   English   中英

使用cabal v2-install構建可執行文件時凍結所有依賴項

[英]Freezing all dependencies when building executables with `cabal v2-install`

我正在構建一個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

但這不能修復傳遞依賴的版本,因此在不同時間進行重建可能會導致生成結果略有不同。 我可以在此設置中以某種方式創建和使用凍結文件嗎? 在這里使用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

好的,也許會有更好的內置方法來執行此類操作,但是在真正的陰謀專家出現之前,這里有一個駭人的解決方法可能適合您。

基本計划是這樣的:使用您關心的三個軟件包臨時創建一個項目-足夠長的時間來獲取凍結文件-然后使用一些簡單的文本編輯器宏將凍結文件轉換為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/\$/'/

如果需要,也可以在編輯器中手動執行這些操作。 在此過程結束時(您可以在臨時目錄中運行以簡化之后的清理工作),您應該有一個名為cabal-v2-install.sh的文件,其中的命令將為涉及的所有軟件包選擇完全相同的版本和標志,包括依賴項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM