Cameron Martin Cameron Martin - 5 months ago 29
Android Question

In an AOSP Android.mk file, how do I execute a command and fail the build if the command fails?

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?

Answer

Dump stdout, test the exit status, and error out on failure:

ifneq (0,$(shell >/dev/null command doesnotexist ; echo $$?))
  $(error "not good")
endif

Here's what failure looks like:

[user@host]$ make 
/bin/sh: doesnotexist: command not found
Makefile:6: *** not good.  Stop.
[user@host]$
Comments