-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_internal_headers.py
More file actions
executable file
·70 lines (50 loc) · 1.82 KB
/
Copy pathfetch_internal_headers.py
File metadata and controls
executable file
·70 lines (50 loc) · 1.82 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
import argparse
import logging
from pathlib import Path
import requests
OWNER = "llvm"
REPO = "llvm-project"
REF = "llvmorg-22.1.8"
START_PATHS = ["clang/lib/CodeGen", "clang-tools-extra/clangd"]
OUTPUT_DIR = Path("include") / REPO
API = f"https://api.github.com/repos/{OWNER}/{REPO}/contents"
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s | %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
logger = logging.getLogger(__name__)
def download_headers(path: str, ref: str):
url = f"{API}/{path}?ref={ref}"
logger.info(f"Scanning {path}")
r = requests.get(url)
r.raise_for_status()
total = sum(1 for item in r.json() if item["type"] == "file" and item["name"].endswith(".h"))
cur = 0
for item in r.json():
if item["type"] == "file" and item["name"].endswith(".h"):
cur += 1
out_file = OUTPUT_DIR / path / item["name"]
out_file.parent.mkdir(parents=True, exist_ok=True)
logger.info(f"[{cur:>{len(str(total))}}/{total}] Downloading {item['path']}")
resp = requests.get(item["download_url"])
resp.raise_for_status()
out_file.write_bytes(resp.content)
def main():
parser = argparse.ArgumentParser(description="Fetch Clang internal headers from GitHub")
parser.add_argument(
"-v",
"--version",
action="store",
default=REF,
help="Clang internal headers version to fetch (default: %(default)s)",
)
args = parser.parse_args()
logger.info(f"Fetching Clang internal headers from {OWNER}/{REPO} at ref {args.version}")
OUTPUT_DIR.mkdir(exist_ok=True)
for start_path in START_PATHS:
download_headers(start_path, args.version)
logger.info("Done")
if __name__ == "__main__":
main()