common-mk: use $SYSROOT/usr/share/libchrome/BASE_VER.

- Stop using common-mk/BASE_VER since it will be removed. Use
$SYSROOT/usr/share/libchrome/BASE_VER instead.
- Don't assert if $SYSROOT/usr/share/libchrome/BASE_VER is not found,
since software not depending on libchrome may still use common-mk
utilities.

BUG=chromium:1062979
TEST=emerge hardware_verifier_proto (adding WANT_LIBCHROME=no locally)

Change-Id: Iad2e844f4a0d61e4ac8b3e0d596440e68914b71b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2341278
Tested-by: Qijiang Fan <fqj@google.com>
Commit-Queue: Qijiang Fan <fqj@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/common-mk/common.mk b/common-mk/common.mk
index 62c005a..18f18d6 100644
--- a/common-mk/common.mk
+++ b/common-mk/common.mk
@@ -125,10 +125,13 @@
 
 # If BASE_VER is not set, read the libchrome revision number from
 # common-mk/BASE_VER file.
-ifeq ($(strip $(BASE_VER)),)
-BASE_VER := $(shell cat $(SRC)/../common-mk/BASE_VER)
-endif
+BASE_VER_PATH := $(SYSROOT)/usr/share/libchrome/BASE_VER
+ifeq (,$(wildcard $(BASE_VER_PATH)))
+BASE_VER := $(shell cat $(BASE_VER_PATH))
 $(info Using BASE_VER=$(BASE_VER))
+else
+$(info Libchrome is not installed. No BASE_VER will be provided.)
+endif
 
 # Re-start in the $(OUT) directory if we're not there.
 # We may be invoked using -C or bare and we need to ensure behavior
diff --git a/common-mk/platform2.py b/common-mk/platform2.py
index 8fb19d0..0f60311 100755
--- a/common-mk/platform2.py
+++ b/common-mk/platform2.py
@@ -152,12 +152,18 @@
 
     self.libbase_ver = os.environ.get('BASE_VER', '')
     if not self.libbase_ver:
-      # If BASE_VER variable not set, read the content of common_mk/BASE_VER
+      # If BASE_VER variable not set, read the content of
+      # $SYSROOT/usr/share/libchrome/BASE_VER
       # file which contains the default libchrome revision number.
-      base_ver_file = os.path.join(self.get_src_dir(), 'BASE_VER')
-      self.libbase_ver = osutils.ReadFile(base_ver_file).strip()
-    assert self.libbase_ver
-
+      base_ver_file = os.path.join(self.sysroot,
+                                   'usr/share/libchrome/BASE_VER')
+      try:
+        self.libbase_ver = osutils.ReadFile(base_ver_file).strip()
+      except FileNotFoundError:
+        # Software not depending on libchrome still uses platform2.py, Instead
+        # of asserting here. Provide a human readable bad value that is not
+        # supposed to be used.
+        self.libbase_ver = 'NOT-INSTALLED'
 
   def get_src_dir(self):
     """Return the path to build tools and common GN files"""