Improve checks for include dirs outside the source tree
See the Changes.md addition for more details.
Test: treehugger (build_test on downstream branches)
Change-Id: I6ad6b454a6fccf93772fda26cfc7dd6bbfc07c40
diff --git a/Changes.md b/Changes.md
index 0b5db4d..5a0fd23 100644
--- a/Changes.md
+++ b/Changes.md
@@ -1,5 +1,36 @@
# Build System Changes for Android.mk Writers
+## LOCAL_C_INCLUDES outside the source/output trees are an error {#BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS}
+
+Include directories are expected to be within the source tree (or in the output
+directory, generated during the build). This has been checked in some form
+since Oreo, but now has better checks.
+
+There's now a `BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS` variable, that when set, will
+turn these errors into warnings temporarily. I don't expect this to last more
+than a release, since they're fairly easy to clean up.
+
+Neither of these cases are supported by Soong, and will produce errors when
+converting your module.
+
+### Absolute paths
+
+This has been checked since Oreo. The common reason to hit this is because a
+makefile is calculating a path, and ran abspath/realpath/etc. This is a problem
+because it makes your build non-reproducible. It's very unlikely that your
+source path is the same on every machine.
+
+### Using `../` to leave the source/output directories
+
+This is the new check that has been added. In every case I've found, this has
+been a mistake in the Android.mk -- assuming that `LOCAL_C_INCLUDES` (which is
+relative to the top of the source tree) acts like `LOCAL_SRC_FILES` (which is
+relative to `LOCAL_PATH`).
+
+Since this usually isn't a valid path, you can almost always just remove the
+offending line.
+
+
# `BOARD_HAL_STATIC_LIBRARIES` and `LOCAL_HAL_STATIC_LIBRARIES` are obsolete {#BOARD_HAL_STATIC_LIBRARIES}
Define proper HIDL / Stable AIDL HAL instead.
diff --git a/core/binary.mk b/core/binary.mk
index 568766f..76fbc95 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -1289,9 +1289,13 @@
my_c_includes := $(foreach inc,$(my_c_includes),$(call clean-path,$(inc)))
-my_outside_includes := $(filter-out $(OUT_DIR)/%,$(filter /%,$(my_c_includes)))
+my_outside_includes := $(filter-out $(OUT_DIR)/%,$(filter /%,$(my_c_includes)) $(filter ../%,$(my_c_includes)))
ifneq ($(my_outside_includes),)
-$(error $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): C_INCLUDES must be under the source or output directories: $(my_outside_includes))
+ ifeq ($(BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS),true)
+ $(call pretty-warning,C_INCLUDES must be under the source or output directories: $(my_outside_includes))
+ else
+ $(call pretty-error,C_INCLUDES must be under the source or output directories: $(my_outside_includes))
+ endif
endif
# all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES;
diff --git a/core/board_config.mk b/core/board_config.mk
index 4c128f1..0e3c52f 100644
--- a/core/board_config.mk
+++ b/core/board_config.mk
@@ -89,6 +89,7 @@
BUILD_BROKEN_PREBUILT_ELF_FILES \
BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW \
BUILD_BROKEN_USES_NETWORK \
+ BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS \
_build_broken_var_list += \
$(foreach m,$(AVAILABLE_BUILD_MODULE_TYPES) \