| Matthias Sohn | 9f97b8b | 2022-01-07 10:19:26 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 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: |
| 32 | # ignore "not a git repository error" to report unknown version |
| 33 | return None |
| 34 | finally: |
| 35 | os.chdir(parent) |
| 36 | |
| 37 | |
| 38 | print("STABLE_BUILD_GITILES_LABEL %s" % revision(ROOT, ROOT)) |
| Matthias Sohn | b3ee156 | 2022-01-07 10:23:02 +0100 | [diff] [blame^] | 39 | for kind in ['modules']: |
| 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')) |