Mark BUILD_NUMBER as obsolete, more vars as readonly
In preparation for moving BUILD_NUMBER and FILE_NAME_TAG handling to
soong_ui, mark BUILD_NUMBER as obsolete and FILE_NAME_TAG as readonly.
Later changes will remove BUILD_NUMBER entirely, and move FILE_NAME_TAG
handling into the kati packaging step via dist-for-goals renames.
Test: build_test on master
Change-Id: I0e340d32fe0cb6296d3b5a7fec349b50632d044e
diff --git a/Changes.md b/Changes.md
index 4aa7ea2..2d5cd97 100644
--- a/Changes.md
+++ b/Changes.md
@@ -1,5 +1,22 @@
# Build System Changes for Android.mk Writers
+## `BUILD_NUMBER` removal from Android.mk {#BUILD_NUMBER}
+
+`BUILD_NUMBER` should not be used directly in Android.mk files, as it would
+trigger them to be re-read every time the `BUILD_NUMBER` changes (which it does
+on every build server build). If possible, just remove the use so that your
+builds are more reproducible. If you do need it, use `BUILD_NUMBER_FROM_FILE`:
+
+``` make
+$(LOCAL_BUILT_MODULE):
+ mytool --build_number $(BUILD_NUMBER_FROM_FILE) -o $@
+```
+
+That will expand out to a subshell that will read the current `BUILD_NUMBER`
+whenever it's run. It will not re-run your command if the build number has
+changed, so incremental builds will have the build number from the last time
+the particular output was rebuilt.
+
## `DIST_DIR`, `dist_goal`, and `dist-for-goals` {#dist}
`DIST_DIR` and `dist_goal` are no longer available when reading Android.mk
diff --git a/core/main.mk b/core/main.mk
index 6ff5f93..461c3b4 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -66,12 +66,15 @@
$(shell mkdir -p $(OUT_DIR) && \
echo -n $(BUILD_NUMBER) > $(OUT_DIR)/build_number.txt)
BUILD_NUMBER_FILE := $(OUT_DIR)/build_number.txt
+.KATI_READONLY := BUILD_NUMBER_FILE
+$(KATI_obsolete_var BUILD_NUMBER,See https://android.googlesource.com/platform/build/+/master/Changes.md#BUILD_NUMBER)
ifeq ($(HOST_OS),darwin)
DATE_FROM_FILE := date -r $(BUILD_DATETIME_FROM_FILE)
else
DATE_FROM_FILE := date -d @$(BUILD_DATETIME_FROM_FILE)
endif
+.KATI_READONLY := DATE_FROM_FILE
# Pick a reasonable string to use to identify files.
ifeq ($(strip $(HAS_BUILD_NUMBER)),false)
@@ -81,6 +84,7 @@
else
FILE_NAME_TAG := $(file <$(BUILD_NUMBER_FILE))
endif
+.KATI_READONLY := FILE_NAME_TAG
# Make an empty directory, which can be used to make empty jars
EMPTY_DIRECTORY := $(OUT_DIR)/empty