Debian Codegraph @

scripts/fetch-vendor.py

raw symbols SCIP
1 import argparse
2 import json
3 import logging
4 import os
5 import platform
6 import shutil
7 import struct
8 import subprocess
9
10
11 def get_platform():
12 system = platform.system()
13 machine = platform.machine()
14 if system == "Linux":
15 if platform.libc_ver()[0] == "glibc":
16 return f"manylinux_{machine}"
17 else:
18 return f"musllinux_{machine}"
19 elif system == "Darwin":
20 # cibuildwheel sets ARCHFLAGS:
21 # https://github.com/pypa/cibuildwheel/blob/5255155bc57eb6224354356df648dc42e31a0028/cibuildwheel/macos.py#L207-L220
22 if "ARCHFLAGS" in os.environ:
23 machine = os.environ["ARCHFLAGS"].split()[1]
24 return f"macosx_{machine}"
25 elif system == "Windows":
26 if machine == "ARM64":
27 return "win_arm64"
28 elif struct.calcsize("P") * 8 == 64:
29 return "win_amd64"
30 else:
31 return "win32"
32 else:
33 raise Exception(f"Unsupported system {system}")
34
35
36 parser = argparse.ArgumentParser(description="Fetch and extract tarballs")
37 parser.add_argument("destination_dir")
38 parser.add_argument("--cache-dir", default="tarballs")
39 parser.add_argument("--config-file", default=os.path.splitext(__file__)[0] + ".json")
40 args = parser.parse_args()
41 logging.basicConfig(level=logging.INFO)
42
43 # read config file
44 with open(args.config_file, "r") as fp:
45 config = json.load(fp)
46
47 # create fresh destination directory
48 logging.info("Creating directory %s" % args.destination_dir)
49 if os.path.exists(args.destination_dir):
50 shutil.rmtree(args.destination_dir)
51 os.makedirs(args.destination_dir)
52
53 for url_template in config["urls"]:
54 tarball_url = url_template.replace("{platform}", get_platform())
55
56 # download tarball
57 tarball_name = tarball_url.split("/")[-1]
58 tarball_file = os.path.join(args.cache_dir, tarball_name)
59 if not os.path.exists(tarball_file):
60 logging.info("Downloading %s" % tarball_url)
61 if not os.path.exists(args.cache_dir):
62 os.mkdir(args.cache_dir)
63 subprocess.check_call(
64 ["curl", "--location", "--output", tarball_file, "--silent", tarball_url]
65 )
66
67 # extract tarball
68 logging.info("Extracting %s" % tarball_name)
69 subprocess.check_call(["tar", "-C", args.destination_dir, "-xf", tarball_file])