Define the build number with the product flavour and the manifest

Change compared to the cherry-picked commit: Override HAS_BUILD_NUMBER
that is set by build/make/core/version_defaults.mk, so that the now
stricter checks in build/make/core/Makefile correctly pick up our
modified BUILD_NUMBER.

Note that we cannot set the BUILD_NUMBER early during the invocation of
envsetup.sh as it seems to be intended by the build system, because our
BUILD_NUMBER depends on the build flavor (gms, sibon).

Issue: ST-911
Issue: FP2P-155
Issue: FP3-A11#306
Change-Id: Ib759f39815956ba6c26eecdc2837295dd733b704
Depends-On: I40f38e5605db16ac3dc16f00a68569bae0855ca1
Depends-On: Idf51e7fb6a9a13cf543807d01adce4d7676de3ea
Depends-On: Idf9e46d6eb2b4ff6a72045ab082f5389b1c26d82
(cherry picked from commit 3969e5d9e08dfe8d02cd8e14e4a6dc45f72321a2)
(cherry picked from commit 1b9d26020aebfc7ce1910561b061a6688cc862d8)
diff --git a/device.mk b/device.mk
index 2a870ce..9e4b875 100644
--- a/device.mk
+++ b/device.mk
@@ -41,6 +41,17 @@
 
 TARGET_SYSTEM_PROP := device/$(TARGET_VENDOR)/$(PRODUCT_NAME)/system.prop
 
+# Define the build number based on the product flavour and on the build manifest
+# revision
+ifneq (,$(strip $(PRODUCT_FLAVOR)))
+  _BUILD_MANIFEST_REV := $(shell (git -C $(TOPDIR).repo/manifests rev-parse --short=8 HEAD))
+  BUILD_NUMBER := $(PRODUCT_FLAVOR)-$(_BUILD_MANIFEST_REV)
+  HAS_BUILD_NUMBER := true
+else
+  $(error PRODUCT_FLAVOR must be defined)
+endif
+$(warning Build defined as $(BUILD_ID) ($(BUILD_NUMBER)))
+
 
 # We don't have the calibration data as this sort of
 # data can only be generated at the factory so don't generate persist.img