在Android.mk文件中,我具有执行bash脚本的以下行:
$(info $(shell ($(LOCAL_PATH)/build.sh)))
但是,如果命令失败,则继续构建而不是退出。
在这种情况下,如何使整个构建失败?
转储stdout
,测试退出状态,并在发生错误时出错:
ifneq (0,$(shell >/dev/null command doesnotexist ; echo $$?))
$(error "not good")
endif
这是失败的样子:
[user@host]$ make
/bin/sh: doesnotexist: command not found
Makefile:6: *** not good. Stop.
[user@host]$
如果您想查看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
这使
$ make
/bin/sh: foobar: command not found
$(FOOBAR_OUTPUT) == I hope this works 127
$(lastword $(FOOBAR_OUTPUT)) == 127
Makefile:12: *** not good. Stop.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句