1
在Android.mk文件,我有以下行,其执行bash脚本:在AOSP Android.mk文件中,如果命令失败,我该如何执行命令并使构建失败?
$(info $(shell ($(LOCAL_PATH)/build.sh)))
但是,如果命令失败,构建持续,而不是退出。
在这种情况下,我该如何让整个构建失败?
在Android.mk文件,我有以下行,其执行bash脚本:在AOSP Android.mk文件中,如果命令失败,我该如何执行命令并使构建失败?
$(info $(shell ($(LOCAL_PATH)/build.sh)))
但是,如果命令失败,构建持续,而不是退出。
在这种情况下,我该如何让整个构建失败?
自卸stdout
,测试退出状态,以及错误出在失败:
ifneq (0,$(shell >/dev/null command doesnotexist ; echo $$?))
$(error "not good")
endif
这里是失败的样子:
[[email protected]]$ make
/bin/sh: doesnotexist: command not found
Makefile:6: *** not good. Stop.
[[email protected]]$
如果你想看到stdout
,那么你可以将它保存到一个变量和只测试lastword
:
FOOBAR_OUTPUT := $(shell echo "I hope this works" ; command foobar ; echo $$?)
$(info $$(FOOBAR_OUTPUT) == $(FOOBAR_OUTPUT))
$(info $$(lastword $$(FOOBAR_OUTPUT)) == $(lastword $(FOOBAR_OUTPUT)))
ifneq (0,$(lastword $(FOOBAR_OUTPUT)))
$(error not good)
endif
wh ich给出
$ make
/bin/sh: foobar: command not found
$(FOOBAR_OUTPUT) == I hope this works 127
$(lastword $(FOOBAR_OUTPUT)) == 127
Makefile:12: *** not good. Stop.
谢谢,这工作得很好,但我怎么让它也显示标准输出控制台以及stderr? –
@CameronMartin,优点。我用一个技巧修改了我的答案,以捕获'stdout'并通过'lastword'测试。 – rubicks