workspace_status.py 936 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python3
  2. """Bazel `--workspace_status_command` script.
  3. This script is designed to be used in Bazel`s `--workspace_status_command` and
  4. generate any desirable status artifacts.
  5. """
  6. __copyright__ = """
  7. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  8. Exceptions. See /LICENSE for license information.
  9. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  10. """
  11. import subprocess
  12. def git_commit_sha() -> str:
  13. return subprocess.check_output(
  14. ["git", "rev-parse", "--short", "HEAD"], encoding="utf-8"
  15. ).strip()
  16. def git_dirty_suffix() -> str:
  17. status = subprocess.check_output(
  18. ["git", "status", "--porcelain"], encoding="utf-8"
  19. ).strip()
  20. return ".dirty" if len(status) > 0 else ""
  21. def main() -> None:
  22. print("STABLE_GIT_COMMIT_SHA " + git_commit_sha())
  23. print("STABLE_GIT_DIRTY_SUFFIX " + git_dirty_suffix())
  24. if __name__ == "__main__":
  25. main()