David Ostrovsky | 2b5fe09 | 2021-03-03 11:52:30 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
David Ostrovsky | a7e95e5 | 2019-11-02 10:12:49 +0100 | [diff] [blame] | 2 | |
| 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 | |
| 13 | from __future__ import print_function |
| 14 | import os |
| 15 | import subprocess |
| 16 | import sys |
| 17 | |
| 18 | ROOT = os.path.abspath(__file__) |
| 19 | while not os.path.exists(os.path.join(ROOT, 'WORKSPACE')): |
| 20 | ROOT = os.path.dirname(ROOT) |
| 21 | CMD = ['git', 'describe', '--always', '--match', 'v[0-9].*', '--dirty'] |
| 22 | |
| 23 | |
| 24 | def 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 Ostrovsky | 4cdd7f7 | 2019-11-03 13:26:35 +0100 | [diff] [blame] | 32 | # ignore "not a git repository error" to report unknown version |
| 33 | return None |
David Ostrovsky | a7e95e5 | 2019-11-02 10:12:49 +0100 | [diff] [blame] | 34 | finally: |
| 35 | os.chdir(parent) |
| 36 | |
| 37 | |
| 38 | print("STABLE_BUILD_GERRIT_LABEL %s" % revision(ROOT, ROOT)) |
David Ostrovsky | 49f8002 | 2020-06-21 18:12:26 +0200 | [diff] [blame] | 39 | for 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')) |