mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 19:00:11 +01:00
Support jj workspaces (#7219)
In particular, bazel builds would previously fail in `workspace_status.py` if you didn't have a `.git` with this error: > ``` > ERROR: <builtin>: BazelWorkspaceStatusAction stable-status.txt failed: Failed to determine workspace status: Process exited with status 1 > fatal: not a git repository (or any of the parent directories): .git > ``` Assisted-by: Google Antigravity --------- Co-authored-by: Josh L <josh11b@users.noreply.github.com> Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
co-authored by
Josh L
Chandler Carruth
parent
843323b864
commit
f0aa561bd6
@@ -12,7 +12,18 @@ Exceptions. See /LICENSE for license information.
|
||||
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def use_jj() -> bool:
|
||||
if os.path.isdir(".jj"):
|
||||
return True
|
||||
elif os.path.exists(".git"):
|
||||
return False
|
||||
print("Can't tell whether to use jj or git:", os.getcwd())
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def git_commit_sha() -> str:
|
||||
@@ -28,9 +39,31 @@ def git_dirty_suffix() -> str:
|
||||
return ".dirty" if len(status) > 0 else ""
|
||||
|
||||
|
||||
def jj_commit_sha() -> str:
|
||||
# Get the first 9 characters of the commit id of the parent of the current
|
||||
# working copy.
|
||||
return subprocess.check_output(
|
||||
["jj", "log", "-r", "@-", "--no-graph", "-T", "commit_id.shortest(9)"],
|
||||
encoding="utf-8",
|
||||
).strip()
|
||||
|
||||
|
||||
def jj_dirty_suffix() -> str:
|
||||
# This `jj log` template returns "true" if the current working copy is
|
||||
# empty, otherwise "false".
|
||||
status = subprocess.check_output(
|
||||
["jj", "log", "-r", "@", "--no-graph", "-T", "empty"], encoding="utf-8"
|
||||
).strip()
|
||||
return ".dirty" if status == "false" else ""
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print("STABLE_GIT_COMMIT_SHA " + git_commit_sha())
|
||||
print("STABLE_GIT_DIRTY_SUFFIX " + git_dirty_suffix())
|
||||
if use_jj():
|
||||
print("STABLE_GIT_COMMIT_SHA " + jj_commit_sha())
|
||||
print("STABLE_GIT_DIRTY_SUFFIX " + jj_dirty_suffix())
|
||||
else:
|
||||
print("STABLE_GIT_COMMIT_SHA " + git_commit_sha())
|
||||
print("STABLE_GIT_DIRTY_SUFFIX " + git_dirty_suffix())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user