基本代码:
def make_check(local, master, old_revno, old_revid, future_revno, future_revid,
tree_delta, future_tree):
try:
check_call('make check', shell=True)
except CalledProcessError as e:
raise BzrError(e)
结果:bzr:错误:命令“make check”返回非零退出状态 2
我有一个包含“检查”目标的 Makefile,其中运行一些脚本以检查所有源代码是否具有有效的语法。
如果我make check
从控制台运行,它的状态为 0。
如果我make check
从 Bazaar 中的预提交挂钩运行,它的状态为 2。
我进行了一些深入的调查,包括检查环境变量(基本上相同)并strace
针对这两种方法运行。
在这两种情况下,脚本的输出是相同的,但是在 precommit 钩子的情况下,退出状态是 2 没有任何解释我可以辨别,因为它调用的最后一个进程的退出状态为零并且没有其他外部系统调用。有没有我忽略的东西,或者可能是内部错误的一些机会make
?
安慰
16436 execve("/usr/bin/make", ["make", "check"], [/* 22 vars */]) = 0
#Big snip
16947 execve("/bin/sh", ["/bin/sh", "-c", "find archive/rpm/6 -name '*.rpm' -printf '%f\\n' | rev | cut -d- -f3- | rev | sort | uniq -c | grep -v '^ *1 ' && \\\n{ echo \"ERROR: Found duplicate RPMs in archive.\"; exit 1; } || true"], [/* 35 vars */]) = 0
#Big snip
16948 exit_group(0) = ?
16947 <... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 16949
16947 --- SIGCHLD (Child exited) @ 0 (0) ---
16947 rt_sigreturn(0x11) = 16949
16947 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 16948
16947 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 16950
16947 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 16951
16947 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 16952
16947 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 16953
16947 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 1}], 0, NULL) = 16954
16947 exit_group(0) = ?
16436 <... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 16947
16436 --- SIGCHLD (Child exited) @ 0 (0) ---
16436 rt_sigreturn(0xffffffff) = 16947
16436 rt_sigprocmask(SIG_BLOCK, [HUP INT QUIT TERM XCPU XFSZ], NULL, 8) = 0
16436 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
16436 chdir("/code/n/branches/jeff") = 0
16436 close(1) = 0
16436 munmap(0x7f7ed780e000, 4096) = 0
16436 exit_group(0)
脚本
14001 execve("/usr/bin/make", ["make", "check"], [/* 21 vars */]) = 0
#Big snip
14525 execve("/bin/sh", ["/bin/sh", "-c", "find archive/rpm/6 -name '*.rpm' -printf '%f\\n' | rev | cut -d- -f3- | rev | sort | uniq -c | grep -v '^ *1 ' && \\\n{ echo \"ERROR: Found duplicate RPMs in archive.\"; exit 1; } || true"], [/* 34 vars */]) = 0
#Big snip
14526 exit_group(0) = ?
14525 <... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 14527
14525 --- SIGCHLD (Child exited) @ 0 (0) ---
14525 rt_sigreturn(0x11) = 14527
14525 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 14526
14525 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 14528
14525 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 14529
14525 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 14530
14525 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 14531
14525 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 1}], 0, NULL) = 14532
14525 exit_group(0) = ?
14001 <... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 14525
14001 --- SIGCHLD (Child exited) @ 0 (0) ---
14001 rt_sigreturn(0xffffffff) = 14525
14001 rt_sigprocmask(SIG_BLOCK, [HUP INT QUIT TERM XCPU], NULL, 8) = 0
14001 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
14001 chdir("/code/n/branches/jeff") = 0
14001 close(1) = 0
14001 munmap(0x7f064aa7b000, 4096) = 0
14001 exit_group(2) = ?
更新
我将以下目标附加到我的 Makefile 中:
.PHONY: foobar
foobar:
echo "Testing foobar"
当通过 pre-commit 钩子脚本调用时,此目标还会导致 make 进程以错误状态 2 退出,同时手动执行仍然成功。