Use repeatable timestamps

This moves all of the date references under build/ to using a single
datetime that can be set manually using BUILD_DATETIME.

It also adds an option, OVERRIDE_C_DATE_TIME, that if set to true, will
redefine __DATE__ and __TIME__ for all C/C++ files so that it matches
BUILD_DATETIME.

Bug: 23117013
Change-Id: I880ef103a26bca86bd7bf42d58e62e740a6228c8
diff --git a/core/version_defaults.mk b/core/version_defaults.mk
index f3b2297..9b2ecf2 100644
--- a/core/version_defaults.mk
+++ b/core/version_defaults.mk
@@ -24,6 +24,7 @@
 #     DEFAULT_APP_TARGET_SDK
 #     BUILD_ID
 #     BUILD_NUMBER
+#     BUILD_DATETIME
 #
 
 # Look for an optional file containing overrides of the defaults,
@@ -89,6 +90,12 @@
   BUILD_ID := UNKNOWN
 endif
 
+ifeq "" "$(BUILD_DATETIME)"
+  # Used to reproduce builds by setting the same time. Must be in a
+  # format understood by `date`
+  BUILD_DATETIME := $(shell date)
+endif
+
 ifeq "" "$(BUILD_NUMBER)"
   # BUILD_NUMBER should be set to the source control value that
   # represents the current state of the source code.  E.g., a
@@ -99,5 +106,5 @@
   # If no BUILD_NUMBER is set, create a useful "I am an engineering build
   # from this date/time" value.  Make it start with a non-digit so that
   # anyone trying to parse it as an integer will probably get "0".
-  BUILD_NUMBER := eng.$(USER).$(shell date +%Y%m%d.%H%M%S)
+  BUILD_NUMBER := eng.$(USER).$(shell date -d "$(BUILD_DATETIME)" +%Y%m%d.%H%M%S)
 endif