forked from carbon-language/carbon-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkspace_status.py
executable file
·37 lines (25 loc) · 936 Bytes
/
workspace_status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
"""Bazel `--workspace_status_command` script.
This script is designed to be used in Bazel`s `--workspace_status_command` and
generate any desirable status artifacts.
"""
__copyright__ = """
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import subprocess
def git_commit_sha() -> str:
return subprocess.check_output(
["git", "rev-parse", "--short", "HEAD"], encoding="utf-8"
).strip()
def git_dirty_suffix() -> str:
status = subprocess.check_output(
["git", "status", "--porcelain"], encoding="utf-8"
).strip()
return ".dirty" if len(status) > 0 else ""
def main() -> None:
print("STABLE_GIT_COMMIT_SHA " + git_commit_sha())
print("STABLE_GIT_DIRTY_SUFFIX " + git_dirty_suffix())
if __name__ == "__main__":
main()