Read BUILD_NUMBER from file in rules

Using $(BUILD_NUMBER) inside a rule causes odd behavior, as the rule
is different every time make is run, but since make doesn't depend
on the command line it only ends up being built with the new value
if some other dependency has changed.

To allow ninja, which does depend on the command line, to provide the
same behavior, store the build number in out/build_number.txt, and
use a shell expansion to cat the file in rules that use it.  This will
cause the rule command to stay identical between builds, while still
getting the new build number if the rule is rerun for a dependency.

Also use the same trick for BUILD_FINGERPRINT, and the date in
droiddoc rules.

Change-Id: I6c5e6b6b3ef4c613563d7f5604df0e401575ba5f
diff --git a/core/main.mk b/core/main.mk
index 7f561ab..7f22d76 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -93,6 +93,12 @@
 # and host information.
 include $(BUILD_SYSTEM)/config.mk
 
+# Write the build number to a file so it can be read back in
+# without changing the command line every time.  Avoids rebuilds
+# when using ninja.
+$(shell echo -n $(BUILD_NUMBER) > $(OUT_DIR)/build_number.txt)
+BUILD_NUMBER_FROM_FILE := $$(cat $(OUT_DIR)/build_number.txt)
+
 # CTS-specific config.
 -include cts/build/config.mk