summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Short <keithshort@chromium.org>2021-05-14 14:36:25 -0600
committerCommit Bot <commit-bot@chromium.org>2021-05-19 18:57:41 +0000
commite19a8e92bcf167385f46270b486ff2179ed891f4 (patch)
treea58e08747121d6b0973114b3f35d1d5e3c1991c7
parent2ae344c3f242be0c80361fa95df4ca563a5b3767 (diff)
downloadchrome-ec-e19a8e92bcf167385f46270b486ff2179ed891f4.tar.gz
zmake: Fall back to VCSID for version information
The git repository information is not available to ebuilds after doing a "cros-workon-<board> start" on the package. Fall back to the VCSID in this case. BUG=b:188530338 BRANCH=none TEST=emerge zephyr-build-tools TEST=zmake testall TEST="cros-workon-volteer-zephyr start chromeos-zephyr" and "emerge-volteer-zephyr chromeos-zephyr" Cq-Depend: chromium:2902154 Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I03227005097b114061514ef1f1dcd79f242a1bf7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2903906 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--zephyr/zmake/zmake/version.py47
1 files changed, 37 insertions, 10 deletions
diff --git a/zephyr/zmake/zmake/version.py b/zephyr/zmake/zmake/version.py
index 9128dd2bff..6cc37f95d4 100644
--- a/zephyr/zmake/zmake/version.py
+++ b/zephyr/zmake/zmake/version.py
@@ -3,12 +3,16 @@
# found in the LICENSE file.
import subprocess
+import os
import zmake.util as util
def _get_num_commits(repo):
- """Get the number of commits that have been made in a Git repository.
+ """Get the number of commits that have been made.
+
+ If a Git repository is available, return the number of commits that have
+ been made. Otherwise return a fixed count.
Args:
repo: The path to the git repo.
@@ -16,14 +20,25 @@ def _get_num_commits(repo):
Returns:
An integer, the number of commits that have been made.
"""
- result = subprocess.run(['git', '-C', repo, 'rev-list', 'HEAD', '--count'],
- check=True, stdout=subprocess.PIPE,
- encoding='utf-8')
- return int(result.stdout)
+ try:
+ result = subprocess.run(['git', '-C', repo, 'rev-list', 'HEAD',
+ '--count'],
+ check=True, stdout=subprocess.PIPE,
+ stderr=subprocess.DEVNULL, encoding='utf-8')
+ except subprocess.CalledProcessError:
+ commits = '9999'
+ else:
+ commits = result.stdout
+
+ return int(commits)
def _get_revision(repo):
- """Get the index's current revision of a Git repo.
+ """Get the current revision hash.
+
+ If a Git repository is available, return the hash of the current index.
+ Otherwise return the hash of the VCSID environment variable provided by
+ the packaging system.
Args:
repo: The path to the git repo.
@@ -31,10 +46,22 @@ def _get_revision(repo):
Returns:
A string, of the current revision.
"""
- result = subprocess.run(['git', '-C', repo, 'log', '-n1', '--format=%H'],
- check=True, stdout=subprocess.PIPE,
- encoding='utf-8')
- return result.stdout
+ try:
+ result = subprocess.run(['git', '-C', repo, 'log', '-n1',
+ '--format=%H'],
+ check=True, stdout=subprocess.PIPE,
+ stderr=subprocess.DEVNULL, encoding='utf-8')
+ except subprocess.CalledProcessError:
+ # Fall back to the VCSID provided by the packaging system.
+ # Format is 0.0.1-r425-032666c418782c14fe912ba6d9f98ffdf0b941e9 for
+ # releases and 9999-032666c418782c14fe912ba6d9f98ffdf0b941e9 for
+ # 9999 ebuilds.
+ vcsid = os.environ.get('VCSID', '9999-unknown')
+ revision = vcsid.rsplit('-', 1)[1]
+ else:
+ revision = result.stdout
+
+ return revision
def get_version_string(project, zephyr_base, modules, static=False):