Skip to content

Commit dc384a8

Browse files
committed
also generate .gitmodules metadata
1 parent b6ffe25 commit dc384a8

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

.devcontainer/prepare_workspace.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ GITA_PROJECT_HOME=$(pwd)/.gita
1717
mkdir -p "$GITA_PROJECT_HOME"
1818
export GITA_PROJECT_HOME
1919

20-
# Generate .gita-workspace.csv from known_good.json
21-
python3 tools/known_good_to_gita_workspace.py known_good.json .gita-workspace.csv
20+
# Generate a few workspace metadata files from known_good.json:
21+
# - .gita-workspace.csv
22+
# - .gitmodules
23+
python3 tools/known_good_to_workspace_metadata.py --known-good known_good.json --gita-workspace .gita-workspace.csv --git-submodules .gitmodules
24+
25+
# Replace git_overrides with local_path_overrides for Bazel
2226
python3 tools/update_module_from_known_good.py --override-type local_path
2327

2428
# Automagically clone repositories listed in .gita-workspace.csv

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ __pycache__/
2727
/score_*/
2828
/.gita/
2929
/.gita-workspace.csv
30+
/.gitmodules
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313
]
1414

1515
def main():
16-
parser = argparse.ArgumentParser(description="Convert known_good.json to baseline.csv format.")
17-
parser.add_argument("input_json", help="Path to known_good.json")
18-
parser.add_argument("output_csv", help="Path to output baseline.csv")
16+
parser = argparse.ArgumentParser(description="Convert known_good.json to workspace metadata files for gita and git submodules.")
17+
18+
parser.add_argument("--known-good", dest="known_good", default="known_good.json", help="Path to known_good.json")
19+
parser.add_argument("--gita-workspace", dest="gita_workspace", default=".gita-workspace.csv", help="File to output gita workspace metadata")
20+
parser.add_argument("--git-submodules", dest="git_submodules", default=".gitmodules", help="File to output git submodules metadata")
1921
args = parser.parse_args()
2022

21-
with open(args.input_json, "r") as f:
23+
with open(args.known_good, "r") as f:
2224
data = json.load(f)
2325

2426
modules = data.get("modules", {})
25-
rows = []
27+
28+
gita_metadata = []
2629
for name, info in modules.items():
2730
repo_url = info.get("repo", "")
2831
if not repo_url:
@@ -39,12 +42,22 @@ def main():
3942

4043
# gita format: {url},{name},{path},{prop['type']},{repo_flags},{branch}
4144
row = [repo_url, name, workspace_path, "", "", hash_]
42-
rows.append(row)
45+
gita_metadata.append(row)
4346

44-
with open(args.output_csv, "w", newline="") as f:
47+
with open(args.gita_workspace, "w", newline="") as f:
4548
writer = csv.writer(f)
46-
for row in rows:
49+
for row in gita_metadata:
4750
writer.writerow(row)
4851

52+
with open(args.git_submodules, "w") as f:
53+
for name, info in modules.items():
54+
repo_url = info.get("repo", "")
55+
branch = info.get("branch", "main")
56+
workspace_path = name
57+
f.write(f"[submodule \"{name}\"]\n")
58+
f.write(f"\tpath = {workspace_path}\n")
59+
f.write(f"\turl = {repo_url}\n")
60+
f.write(f"\tbranch = {branch}\n")
61+
4962
if __name__ == "__main__":
5063
main()

0 commit comments

Comments
 (0)