Skip to content

Commit 195dae4

Browse files
committed
Add script to mirror intel/llvm commits
1 parent e08700a commit 195dae4

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Mirror commits from the unified-runtime top level directory in the
5+
https://github.com/intel/llvm repository to the root of the
6+
https://github.com/oneapi-src/unified-runtime repository.
7+
"""
8+
9+
from argparse import ArgumentParser, RawTextHelpFormatter
10+
from subprocess import run, PIPE
11+
import os
12+
13+
14+
REPO_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
15+
INTEL_LLVM_MIRROR_BASE_COMMIT_FILE = os.path.join(
16+
REPO_DIR, ".github", "intel-llvm-mirror-base-commit"
17+
)
18+
19+
20+
def main():
21+
cli = ArgumentParser(description=__doc__, formatter_class=RawTextHelpFormatter)
22+
23+
# Positional arguments
24+
cli.add_argument(
25+
"unified_runtime_dir",
26+
help="path to a oneapi-src/unified-runtime clone",
27+
)
28+
cli.add_argument(
29+
"intel_llvm_dir",
30+
help="path to an intel/llvm clone",
31+
)
32+
33+
# Optional arguments
34+
cli.add_argument(
35+
"--unified-runtime-remote",
36+
default="origin",
37+
help="upstream remote to use in the oneapi-src/unified-runtime clone",
38+
)
39+
cli.add_argument(
40+
"--intel-llvm-remote",
41+
default="origin",
42+
help="upstream remote to use in the intel/llvm clone",
43+
)
44+
cli.add_argument(
45+
"--intel-llvm-mirror-base-commit-file",
46+
default=INTEL_LLVM_MIRROR_BASE_COMMIT_FILE,
47+
help="path to a file containing the intel/llvm mirror base commit",
48+
)
49+
50+
args = cli.parse_args()
51+
52+
with open(args.intel_llvm_mirror_base_commit_file, "r") as base_commit_file:
53+
intel_llvm_mirror_base_commit = base_commit_file.read().strip()
54+
55+
print(f"Using intel/llvm mirror base commit: {intel_llvm_mirror_base_commit}")
56+
57+
run(["git", "-C", args.intel_llvm_dir, "fetch", args.intel_llvm_remote])
58+
59+
result = run(
60+
[
61+
"git",
62+
"-C",
63+
args.intel_llvm_dir,
64+
"format-patch",
65+
"--relative=unified-runtime",
66+
f"--output-directory={args.unified_runtime_dir}",
67+
f"{intel_llvm_mirror_base_commit}..{args.intel_llvm_remote}/sycl",
68+
"unified-runtime",
69+
],
70+
stdout=PIPE,
71+
)
72+
73+
patches = result.stdout.decode().splitlines()
74+
if len(patches) == 0:
75+
print("There are no patches to apply, exiting.")
76+
exit(0)
77+
78+
print(f"Applying the following patches:\n{'\n'.join(patches)}")
79+
80+
run(["git", "-C", args.unified_runtime_dir, "am"] + patches)
81+
82+
result = run(
83+
[
84+
"git",
85+
"-C",
86+
args.intel_llvm_dir,
87+
"log",
88+
"-1",
89+
"--format=%H",
90+
"unified-runtime",
91+
],
92+
stdout=PIPE,
93+
)
94+
95+
new_intel_llvm_mirror_base_commit = result.stdout.decode().strip()
96+
print(
97+
f"Using new intel/llvm mirror base commit: {new_intel_llvm_mirror_base_commit}"
98+
)
99+
with open(args.intel_llvm_mirror_base_commit_file, "w") as base_commit_file:
100+
base_commit_file.write(f"{new_intel_llvm_mirror_base_commit}\n")
101+
102+
print("Cleaning up patch files.")
103+
for patch in patches:
104+
os.remove(patch)
105+
106+
107+
if __name__ == "__main__":
108+
try:
109+
main()
110+
except KeyboardInterrupt:
111+
exit(130)

0 commit comments

Comments
 (0)