使用make -j

时间:2019-04-08 09:43:12

标签: gnu-make

在具有许多目标的文件上使用make -j时,其中一个失败了,要识别引起该错误的特定命令可能会有些麻烦。尤其是在有很多输出的情况下。

我可以说服gnu make打印以下内容吗(最好在输出末尾):

This particular command failed: "frobniz -foo" with output "frobniz only takes -foo options on a thursday"? 

就目前而言,我求助于在tmux中使用make -j -Otarget及其可搜索的历史记录,以便可以找到“失败”的输出:

Makefile:41: recipe for target 't4' failed

A,'t4'目标大约有40条命令,输出很多,因此我必须做更多搜索才能找到失败的实际命令。这是可管理的,但确实很笨拙。 我也尝试过remake,但这似乎没有任何选择。

编辑:显然,我应该在这里放一些代码,让我修改一下;这是16个目标中的一个,每个目标约有40条命令。示例下面的内容已被剪切为4个命令。

t4:
  sso -dump FAIL:B -path /instadm-bin/ktkopdat.start -ttarget "AA" ht1
  sso -dump FAIL:B -path /instadm-bin/ktknyadm -ttarget "BB" ht1
  sso -dump FAIL:B -path /instadm-bin/multiadm -ttarget "CC" ht1
  sso -dump FAIL:B -path /instadm-bin/ktkslet.start -ttarge "DD" ht1

可以说我运行make -j并且上面的第二行失败。故障和命令在make的输出中可见,但与许多其他输出混在一起。

make执行产生错误的原因是:sso -dump FAIL:B -path /instadm-bin/ktknyadm -ttarget "BB" ht1-失败,状态为-1。

现在,make必须知道哪个命令失败了,因为它现在可以中止该过程。这些信息对我来说非常有价值,但是仍然隐藏在许多并行进程的输出混乱中。请注意,如果没有-j选项,我当然可以重新运行make,这样可以确保所需的信息显示在输出的底部,但我不想重复冗长的构建而不是必要的次数。

1 个答案:

答案 0 :(得分:0)

I'm not sure what you mean by 40 commands with plenty of output. It would be helpful if you provided an example.

If you mean, you have 40 logical recipe lines (not using backslash to combine 40 physical lines into a single logical line), then as soon as one of those commands fails make will stop building that recipe and won't run any more commands, so the failed command will always be the last one.

If you mean, you have a long shell script that consists of 40 physical lines combined into a single logical line using semicolons and backslashes, then make cannot help you, because make has no idea what command failed.

Make will invoke one instance of the shell and pass each entire logical recipe line to that shell, and wait for the shell to exit with an exit code of 0 or not-0. If the exit code is 0 then make assumes the recipe succeeded; if the exit code is non-0 make assumes the recipe failed. Make has no way to know that there was more than one command invoked, which commands were invoked, which ones may have failed, which ones emitted which output, etc. All of that information is known only to the shell, not to make.