gpt4 book ai didi

ruby - Rake 综合任务和文件日期检查

转载 作者:太空宇宙 更新时间:2023-11-03 18:00:58 24 4
gpt4 key购买 nike

我有一个 Rakefile,我用它来从 markdown 生成 HTML(并做一些与问题无关的其他事情。

我正在从我的源文件生成文件,.feature 文件(在 FileList DOCUMENTS 中),作为 HTML 到我的输出目录 OUTPUT 中。我有一个 htmlfile 方法来组装和编写我的 HTML 文件。

我在这里尝试两种替代方案:

文件任务:

DOCUMENTS.each do |doc|
file doc.pathmap("#{OUTPUT}/%X.html") => doc do |t|
htmlfile t.name, RDiscount.new(F.read doc).to_html, t.name.pathmap('%n')
end
end

使用规则合成文件任务:

rule '.html' => proc {|html| html.pathmap("%{#{OUTPUT}/,}X.feature")} do |t|
htmlfile t.name, RDiscount.new(F.read t.source).to_html, t.name.pathmap('%n')
end

我的理解是后一个选项会合成文件任务,并且具有相同的净效果。但是我发现如果我选择它,它不能处理增量构建,而第一个选项可以。

如果我构建,然后修改一个文件,然后运行 ​​rake --trace 我得到以下信息:

合成任务:

** Invoke output/Module/Feature.html (first_time, not_needed)
** Invoke output/Module (not_needed)

还有明确的文件任务:

** Invoke output/Module/Feature.html (first_time)
** Invoke output/Module (not_needed)
** Invoke Module/Feature.feature (first_time, not_needed)
** Execute output/Module/Feature.html

这个选项显然是在检查源文件。我认为链接输出和源正是什么规则

最佳答案

(我认为将答案作为实际答案而不是评论是最有帮助的。参见 https://meta.stackexchange.com/questions/68507/what-to-do-if-you-find-the-answer-to-your-own-question )

事实证明,如果您在 Rakefile 的其他地方有 file outdoc => something,它会干扰合成任务。而如果您有这些输出文档的文件任务,它会添加到先决条件并且工作正常。这是有道理的;综合任务实际上并不存在。

我还发现规则仅适用于一个推理级别 ( http://onestepback.org/articles/buildingwithrake/rulelimitations.html ),但事实证明这并不是答案。

修复:重新排列任务的先决条件,或使用显式文件任务。

关于ruby - Rake 综合任务和文件日期检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4827734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com