即使前提条件失败,Makefile目标能否调用命令? [英] Can a Makefile target invoke commands even if a prerequisite fails?
问题描述
这里是一个骨架的Makefile,目的是为了更轻松地描述问题:
all_tests : unit_tests other_tests_1 other_tests_2 ... other_tests_N
unit_tests : set1_summary.txt set2_summary.txt ... setN_summary.txt
%_summary.txt : %_details.txt
perl createSummary.pl --in $^ -out $@
%_details.txt : test_harness
./test_harness --test-set $*
因此,我有一个测试运行程序,它会生成带有详细结果的文件,然后是用于创建摘要文件的过滤机制.
现在,如果测试集中的任何项目失败,则测试运行器应用程序将返回错误代码,这将正确终止"all_tests"目标,并且从不调用other_test目标.但是,我想无条件运行详细信息->摘要转换,因为即使失败的测试运行也很重要.
我尝试了一些不同的变体,但是我唯一可以使用的方法是将整个命令链包装到Perl脚本中,存储掉第一个命令的结果,并将其用作整个脚本的返回值. /p>
但是,这似乎不是一个很整洁的解决方案,特别是因为实际"命令集比该框架显示的要复杂一些.您是否知道任何纯粹基于GNU Make的方法来实现这一目标?
您可能有一条特殊的规则,该规则以递归方式两次调用Make,如下所示:
.PHONY: test
test :
make all_tests ; make summary
唯一的缺点是,顶层make进程的退出状态将不再表示测试成功/失败,但是如果您想使用$编写一些额外的脚本,甚至可以修复该问题.外壳变量.
Here's a skeleton Makefile just to make it easier to describe the problem:
all_tests : unit_tests other_tests_1 other_tests_2 ... other_tests_N
unit_tests : set1_summary.txt set2_summary.txt ... setN_summary.txt
%_summary.txt : %_details.txt
perl createSummary.pl --in $^ -out $@
%_details.txt : test_harness
./test_harness --test-set $*
So I have a test runner that produces a file with detailed results, and then a filtering mechanism to create a summary file.
Now, the test runner application returns an error code if any of the items in the test set fails, which will correctly abort the "all_tests" target and never invoke the other_test targets. However, I would like to run the details -> summary transformation unconditionally, since that is relevant even for a failed test run.
I've tried some different variants but the only method I could get to work was wrapping the whole command chain into a Perl script, storing away the result of the first command and using that as return value for the whole script.
But that does not feel like a very neat solution, especially since the "actual" command set is a bit more complex than what this skeleton shows. Do you know any purely GNU Make-based method to accomplish this?
You could have a special rule that invokes Make recursively twice, like this:
.PHONY: test
test :
make all_tests ; make summary
The only downside is that the exit status of the top make process will no longer indicate success/failure of tests, but you could even fix that if you wanted to by a little extra scripting using the $? shell variable.
这篇关于即使前提条件失败,Makefile目标能否调用命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!