好的,可能有更好的内置方法来做这种事情,但在真正的阴谋集团专家出现之前,这里有一个可能适合你的 hacky 解决方法。
基本计划是这样的:用你关心的三个包临时创建一个项目——只要足够长的时间来获得一个冻结文件——然后使用一些简单的文本编辑器宏将冻结文件变成一个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
,该命令将为所有涉及的包(包括依赖项)选择完全相同的版本和标志。