在AOSP Android.mk文件中,如何执行命令并在命令失败时使构建失败? [英] In an AOSP Android.mk file, how do I execute a command and fail the build if the command fails?
本文介绍了在AOSP Android.mk文件中,如何执行命令并在命令失败时使构建失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Android.mk文件中,我具有执行bash脚本的以下行:
In an Android.mk file, I have the following line which executes a bash script:
$(info $(shell ($(LOCAL_PATH)/build.sh)))
但是,如果命令失败,则继续构建而不是退出.
However, if the command fails the build continues rather than quitting.
在这种情况下如何使整个构建失败?
How do I make the whole build fail in this situation?
推荐答案
转储stdout
,测试退出状态,并在发生故障时出错:
Dump stdout
, test the exit status, and error out on failure:
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
:
If you want to see stdout
, then you can save it to a variable and test only the 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.
这篇关于在AOSP Android.mk文件中,如何执行命令并在命令失败时使构建失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文