blob: bedc051f283fdd5d7abf503900ce980c5839e5ce [file] [log] [blame]
David Ostrovsky2b5fe092021-03-03 11:52:30 +01001#!/usr/bin/env python3
David Ostrovskya7e95e52019-11-02 10:12:49 +01002
3# This script will be run by bazel when the build process starts to
4# generate key-value information that represents the status of the
5# workspace. The output should be like
6#
7# KEY1 VALUE1
8# KEY2 VALUE2
9#
10# If the script exits with non-zero code, it's considered as a failure
11# and the output will be discarded.
12
13from __future__ import print_function
14import os
15import subprocess
16import sys
17
18ROOT = os.path.abspath(__file__)
19while not os.path.exists(os.path.join(ROOT, 'WORKSPACE')):
20 ROOT = os.path.dirname(ROOT)
21CMD = ['git', 'describe', '--always', '--match', 'v[0-9].*', '--dirty']
22
23
24def revision(directory, parent):
25 try:
26 os.chdir(directory)
27 return subprocess.check_output(CMD).strip().decode("utf-8")
28 except OSError as err:
29 print('could not invoke git: %s' % err, file=sys.stderr)
30 sys.exit(1)
31 except subprocess.CalledProcessError as err:
David Ostrovsky4cdd7f72019-11-03 13:26:35 +010032 # ignore "not a git repository error" to report unknown version
33 return None
David Ostrovskya7e95e52019-11-02 10:12:49 +010034 finally:
35 os.chdir(parent)
36
37
38print("STABLE_BUILD_GERRIT_LABEL %s" % revision(ROOT, ROOT))
David Ostrovsky49f80022020-06-21 18:12:26 +020039for kind in ['modules', 'plugins']:
40 kind_dir = os.path.join(ROOT, kind)
41 for d in os.listdir(kind_dir):
42 p = os.path.join(kind_dir, d)
43 if os.path.isdir(p):
44 v = revision(p, ROOT)
45 print('STABLE_BUILD_%s_LABEL %s' % (os.path.basename(p).upper(),
46 v if v else 'unknown'))