You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

workspace_status.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python
  2. # Copyright (C) 2020, David Ostrovsky <david@ostrovsky.org> and others
  3. #
  4. # This program and the accompanying materials are made available under the
  5. # terms of the Eclipse Distribution License v. 1.0 which is available at
  6. # http://www.eclipse.org/org/documents/edl-v10.php.
  7. #
  8. # SPDX-License-Identifier: BSD-3-Clause
  9. # This script will be run by bazel when the build process starts to
  10. # generate key-value information that represents the status of the
  11. # workspace. The output should be like
  12. #
  13. # KEY1 VALUE1
  14. # KEY2 VALUE2
  15. #
  16. # If the script exits with non-zero code, it's considered as a failure
  17. # and the output will be discarded.
  18. from __future__ import print_function
  19. import os
  20. import subprocess
  21. import sys
  22. ROOT = os.path.abspath(__file__)
  23. while not os.path.exists(os.path.join(ROOT, 'WORKSPACE')):
  24. ROOT = os.path.dirname(ROOT)
  25. CMD = ['git', 'describe', '--always', '--match', 'v[0-9].*', '--dirty']
  26. def revision(directory, parent):
  27. try:
  28. os.chdir(directory)
  29. return subprocess.check_output(CMD).strip().decode("utf-8")
  30. except OSError as err:
  31. print('could not invoke git: %s' % err, file=sys.stderr)
  32. sys.exit(1)
  33. except subprocess.CalledProcessError as err:
  34. # ignore "not a git repository error" to report unknown version
  35. return None
  36. finally:
  37. os.chdir(parent)
  38. print("STABLE_BUILD_JGIT_LABEL %s" % revision(ROOT, ROOT))