diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-10-10 15:33:22 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-10-10 15:39:33 +0200 |
commit | ccbfaa6901418363c2b79947b1ad1da33beeced3 (patch) | |
tree | 4414f7831f644c580246eb5eddb8cceb450a3a85 | |
parent | 7a23fd360c0d37f71911c6c0479c95ba1fc0ffc6 (diff) | |
download | justbuild-ccbfaa6901418363c2b79947b1ad1da33beeced3.tar.gz |
bootstrap traversing: for explicit trees, create closed directories
... by recursively copying and resolving sybolic links. In this
way, references within a tree (e.g., #include "../Something.hpp")
do not confuse the compiler, as opposed to directory symlinks.
Neverthess, by doing this copying only for tree constructors, we
still keep the overhead acceptable.
-rwxr-xr-x | bin/bootstrap-traverser.py | 7 | ||||
-rwxr-xr-x | bin/parallel-bootstrap-traverser.py | 7 |
2 files changed, 10 insertions, 4 deletions
diff --git a/bin/bootstrap-traverser.py b/bin/bootstrap-traverser.py index 46388cde..30187078 100755 --- a/bin/bootstrap-traverser.py +++ b/bin/bootstrap-traverser.py @@ -16,6 +16,7 @@ import hashlib import json import os +import shutil import subprocess import sys from typing import Any, Dict, List, Optional, cast @@ -79,12 +80,14 @@ def build_tree(desc: Json, *, config: Json, root: str, graph: Json) -> str: tree_dir = os.path.normpath(os.path.join(root, "TREE", tree_id)) if os.path.isdir(tree_dir): return tree_dir + tree_dir_tmp = tree_dir + ".tmp" tree_desc = graph["trees"][tree_id] for location, desc in tree_desc.items(): link(cast(str, build(desc, config=config, root=root, graph=graph)), - os.path.join(tree_dir, location)) + os.path.join(tree_dir_tmp, location)) # correctly handle the empty tree - os.makedirs(tree_dir, exist_ok=True) + os.makedirs(tree_dir_tmp, exist_ok=True) + shutil.copytree(tree_dir_tmp, tree_dir) return tree_dir diff --git a/bin/parallel-bootstrap-traverser.py b/bin/parallel-bootstrap-traverser.py index 86f50e6b..a6c64643 100755 --- a/bin/parallel-bootstrap-traverser.py +++ b/bin/parallel-bootstrap-traverser.py @@ -17,6 +17,7 @@ import hashlib import json import multiprocessing import os +import shutil import subprocess import sys import threading @@ -254,6 +255,7 @@ def build_tree(desc: Json, *, config: Json, root: str, graph: Json, if state != AtomicListMap.Entry.INSERTED: # tree ready, run callback callback(tree_dir) return + tree_dir_tmp = tree_dir + ".tmp" tree_desc: Json = graph["trees"][tree_id] num_entries = AtomicInt(len(tree_desc.items())) @@ -261,7 +263,8 @@ def build_tree(desc: Json, *, config: Json, root: str, graph: Json, def run_callbacks() -> None: if num_entries.fetch_dec() <= 1: # correctly handle the empty tree - os.makedirs(tree_dir, exist_ok=True) + os.makedirs(tree_dir_tmp, exist_ok=True) + shutil.copytree(tree_dir_tmp, tree_dir) vals = g_CALLBACKS_PER_ID.fetch_clear(f"TREE/{tree_id}") if vals: for cb in vals: # mark ready @@ -274,7 +277,7 @@ def build_tree(desc: Json, *, config: Json, root: str, graph: Json, def create_link(location: str) -> Callable[..., None]: def do_link(path: str) -> None: - link(path, os.path.join(tree_dir, location)) + link(path, os.path.join(tree_dir_tmp, location)) run_callbacks() return do_link |