summaryrefslogtreecommitdiff
path: root/bin/bootstrap.py
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2022-06-21 11:09:02 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2022-06-23 16:11:51 +0200
commitd5ffa3e0978b689f1dd7bc2267f50ded647c715f (patch)
tree9d9c8104c48565d0548bc142b3a71438c7c20371 /bin/bootstrap.py
parent8ff466f8ee444d22ec31d679c616459b7c2bf71b (diff)
downloadjustbuild-d5ffa3e0978b689f1dd7bc2267f50ded647c715f.tar.gz
Fix style of bootstrap.py
Diffstat (limited to 'bin/bootstrap.py')
-rwxr-xr-xbin/bootstrap.py103
1 files changed, 53 insertions, 50 deletions
diff --git a/bin/bootstrap.py b/bin/bootstrap.py
index 8154ee7d..b4d89696 100755
--- a/bin/bootstrap.py
+++ b/bin/bootstrap.py
@@ -8,7 +8,6 @@ import subprocess
import sys
import tempfile
-
from pathlib import Path
# path within the repository (constants)
@@ -25,18 +24,21 @@ SRCDIR = os.getcwd()
WRKDIR = None
DISTDIR = []
+
def git_hash(content):
- header = "blob {}\0".format(len(content)).encode('utf-8')
- h = hashlib.sha1()
- h.update(header)
- h.update(content)
- return h.hexdigest()
+ header = "blob {}\0".format(len(content)).encode('utf-8')
+ h = hashlib.sha1()
+ h.update(header)
+ h.update(content)
+ return h.hexdigest()
+
def get_checksum(filename):
with open(filename, "rb") as f:
data = f.read()
return git_hash(data)
+
def get_archive(*, distfile, fetch):
# Fetch the archive, if necessary. Return path to archive
for d in DISTDIR:
@@ -50,10 +52,12 @@ def get_archive(*, distfile, fetch):
subprocess.run(["wget", "-O", target, fetch])
return target
+
def run(cmd, *, cwd, **kwargs):
print("Running %r in %r" % (cmd, cwd), flush=True)
subprocess.run(cmd, cwd=cwd, check=True, **kwargs)
+
def setup_deps():
# unpack all dependencies and return a list of
# additional C++ flags required
@@ -65,10 +69,10 @@ def setup_deps():
for repo, total_desc in config.items():
desc = total_desc.get("repository", {})
if not isinstance(desc, dict):
- # Indirect definition; we will set up the repository at the
- # resolved place, which also has to be part of the global
- # repository description.
- continue
+ # Indirect definition; we will set up the repository at the
+ # resolved place, which also has to be part of the global
+ # repository description.
+ continue
hints = total_desc.get("bootstrap", {})
if desc.get("type") in ["archive", "zip"]:
fetch = desc["fetch"]
@@ -77,29 +81,28 @@ def setup_deps():
actual_checksum = get_checksum(archive)
expected_checksum = desc.get("content")
if actual_checksum != expected_checksum:
- print("Checksum mismatch for %r. Expected %r, found %r"
- % (archive, expected_checksum, actual_checksum))
+ print("Checksum mismatch for %r. Expected %r, found %r" %
+ (archive, expected_checksum, actual_checksum))
print("Unpacking %r from %r" % (repo, archive))
unpack_location = os.path.join(WRKDIR, "deps", repo)
os.makedirs(unpack_location)
if desc["type"] == "zip":
subprocess.run(["unzip", "-d", ".", archive],
- cwd=unpack_location, stdout=subprocess.DEVNULL)
+ cwd=unpack_location,
+ stdout=subprocess.DEVNULL)
else:
- subprocess.run(["tar", "xf", archive],
- cwd=unpack_location)
- subdir = os.path.join(unpack_location,
- desc.get("subdir", "."))
- include_dir = os.path.join(subdir,
- hints.get("include_dir", "."))
+ subprocess.run(["tar", "xf", archive], cwd=unpack_location)
+ subdir = os.path.join(unpack_location, desc.get("subdir", "."))
+ include_dir = os.path.join(subdir, hints.get("include_dir", "."))
include_name = hints.get("include_name", repo)
if include_name == ".":
- for entry in os.listdir(include_dir):
- os.symlink(os.path.normpath(os.path.join(include_dir, entry)),
- os.path.join(include_location, entry))
+ for entry in os.listdir(include_dir):
+ os.symlink(
+ os.path.normpath(os.path.join(include_dir, entry)),
+ os.path.join(include_location, entry))
else:
- os.symlink(os.path.normpath(include_dir),
- os.path.join(include_location, include_name))
+ os.symlink(os.path.normpath(include_dir),
+ os.path.join(include_location, include_name))
if "build" in hints:
run(["sh", "-c", hints["build"]], cwd=subdir)
if "link" in hints:
@@ -107,18 +110,16 @@ def setup_deps():
if "link" in hints:
link_flags.extend(hints["link"])
- return {
- "include": ["-I", include_location],
- "link": link_flags
- }
+ return {"include": ["-I", include_location], "link": link_flags}
+
def bootstrap():
# TODO: add package build mode, building against preinstalled dependencies
# rather than building dependencies ourselves.
- print("Bootstrapping in %r from sources %r, taking files from %r"
- % (WRKDIR, SRCDIR, DISTDIR))
+ print("Bootstrapping in %r from sources %r, taking files from %r" %
+ (WRKDIR, SRCDIR, DISTDIR))
os.makedirs(WRKDIR, exist_ok=True)
- dep_flags = setup_deps();
+ dep_flags = setup_deps()
# handle proto
src_wrkdir = os.path.join(WRKDIR, "src")
shutil.copytree(SRCDIR, src_wrkdir)
@@ -134,42 +135,43 @@ def bootstrap():
cpp_files.append(os.path.join(root, f))
object_files = []
for f in cpp_files:
- obj_file_name =f[:-len(".cpp")] + ".o"
+ obj_file_name = f[:-len(".cpp")] + ".o"
object_files.append(obj_file_name)
cmd = BOOTSTRAP_CC + flags + ["-c", f, "-o", obj_file_name]
run(cmd, cwd=src_wrkdir)
bootstrap_just = os.path.join(WRKDIR, "bootstrap-just")
- cmd = BOOTSTRAP_CC + ["-o", bootstrap_just] + object_files + dep_flags["link"]
+ cmd = BOOTSTRAP_CC + ["-o", bootstrap_just
+ ] + object_files + dep_flags["link"]
run(cmd, cwd=src_wrkdir)
CONF_FILE = os.path.join(WRKDIR, "repo-conf.json")
LOCAL_ROOT = os.path.join(WRKDIR, ".just")
os.makedirs(LOCAL_ROOT, exist_ok=True)
- run(["sh", "-c",
- "cp `./bin/just-mr.py --always-file -C %s --local-build-root=%s setup just` %s"
- % (REPOS, LOCAL_ROOT, CONF_FILE)],
+ run([
+ "sh", "-c",
+ "cp `./bin/just-mr.py --always-file -C %s --local-build-root=%s setup just` %s"
+ % (REPOS, LOCAL_ROOT, CONF_FILE)
+ ],
cwd=src_wrkdir)
GRAPH = os.path.join(WRKDIR, "graph.json")
TO_BUILD = os.path.join(WRKDIR, "to_build.json")
- run([bootstrap_just, "analyse",
- "-C", CONF_FILE,
- "--dump-graph", GRAPH,
- "--dump-artifacts-to-build", TO_BUILD,
- MAIN_MODULE, MAIN_TARGET],
+ run([
+ bootstrap_just, "analyse", "-C", CONF_FILE, "--dump-graph", GRAPH,
+ "--dump-artifacts-to-build", TO_BUILD, MAIN_MODULE, MAIN_TARGET
+ ],
cwd=src_wrkdir)
- run(["./bin/bootstrap-traverser.py",
- "-C", CONF_FILE,
- "--default-workspace", src_wrkdir,
- GRAPH, TO_BUILD],
+ run([
+ "./bin/bootstrap-traverser.py", "-C", CONF_FILE, "--default-workspace",
+ src_wrkdir, GRAPH, TO_BUILD
+ ],
cwd=src_wrkdir)
OUT = os.path.join(WRKDIR, "out")
- run(["./out-boot/%s" % (MAIN_STAGE,),
- "install", "-C", CONF_FILE,
- "-o", OUT, "--local-build-root", LOCAL_ROOT,
- MAIN_MODULE, MAIN_TARGET],
+ run([
+ "./out-boot/%s" % (MAIN_STAGE, ), "install", "-C", CONF_FILE, "-o",
+ OUT, "--local-build-root", LOCAL_ROOT, MAIN_MODULE, MAIN_TARGET
+ ],
cwd=src_wrkdir)
-
def main(args):
global SRCDIR
global WRKDIR
@@ -185,6 +187,7 @@ def main(args):
DISTDIR = [os.path.join(Path.home(), ".distfiles")]
bootstrap()
+
if __name__ == "__main__":
# Parse options, set DISTDIR
main(sys.argv)