summaryrefslogtreecommitdiff
path: root/bin/just-lock.py
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2025-02-24 17:06:56 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2025-02-28 14:57:48 +0100
commita1e68f7a02a61d5b03ca2fb1b1f5ec75fb1c9e31 (patch)
treed4eca81e217eca6493dbd3ab341f93a1080e71b0 /bin/just-lock.py
parentb9b8339487824c7020130c51ab908cf38be7e17f (diff)
downloadjustbuild-a1e68f7a02a61d5b03ca2fb1b1f5ec75fb1c9e31.tar.gz
just-lock clone: Fix wrong order in resolving trees
Match correctly the behavior of just-mr, i.e., resolve the special entries of the relevant subtree of the original tree instead of taking the subtree of the resolved original tree. This also means that the clones of archives can directly stage the relevant subdir of the unpacked content and forward any 'special' pragma (same as for other cloned repository types).
Diffstat (limited to 'bin/just-lock.py')
-rwxr-xr-xbin/just-lock.py60
1 files changed, 8 insertions, 52 deletions
diff --git a/bin/just-lock.py b/bin/just-lock.py
index 4e747fb8..0310a090 100755
--- a/bin/just-lock.py
+++ b/bin/just-lock.py
@@ -70,12 +70,6 @@ GIT_NOBODY_ENV: Dict[str, str] = {
"GIT_CONFIG_SYSTEM": "/dev/null",
}
-SPECIAL_PRAGMA_TO_CAS_RESOLVE_MAP: Dict[str, str] = {
- "ignore": "ignore",
- "resolve-partially": "tree-upwards",
- "resolve-completely": "tree-all"
-}
-
class ObjectType(Enum):
FILE = 1
@@ -2051,10 +2045,9 @@ def rewrite_cloned_repo(repos: Json, *, clone_to: str, target_repo: str,
# Keep relevant pragmas from the workspace root repository
pragma: Json = {}
existing: Json = repos[ws_root_repo]["repository"].get("pragma", {})
- if ws_root_desc["repository"]["type"] not in ["archive", "zip"]:
- special = existing.get("special", None)
- if special:
- pragma["special"] = special
+ special = existing.get("special", None)
+ if special:
+ pragma["special"] = special
to_git = existing.get("to_git", False)
if to_git:
pragma["to_git"] = True
@@ -2188,13 +2181,8 @@ def clone_repo(repos: Json, known_repo: str, deps_chain: List[str],
# Fetch the archive
content = archive_fetch_with_parse(repository,
fail_context=fail_context)
- # Stage the content; first resolve special entries, if needed, then keep
- # the relevant subdir, if given
- special_pragma: Optional[str] = repository.get("pragma",
- {}).get("special", None)
-
- if (special_pragma not in SPECIAL_PRAGMA_TO_CAS_RESOLVE_MAP.keys()
- and subdir is None):
+ # Stage the content of the relevant subdir
+ if subdir is None:
# Unpack directly to clone location
unpack_archive(content,
archive_type=repo_type,
@@ -2203,43 +2191,12 @@ def clone_repo(repos: Json, known_repo: str, deps_chain: List[str],
else:
# Unpack to a temporary dir
workdir: str = create_tmp_dir(type="archive-unpack")
- srcdir: str = os.path.join(workdir, "src")
unpack_archive(content,
archive_type=repo_type,
- unpack_to=srcdir,
+ unpack_to=workdir,
fail_context=fail_context)
-
- move_from_dir: str = srcdir
- if (special_pragma is not None and special_pragma
- in SPECIAL_PRAGMA_TO_CAS_RESOLVE_MAP.keys()):
- # Resolve the tree according to the pragma
- resolve_special_arg = SPECIAL_PRAGMA_TO_CAS_RESOLVE_MAP[
- special_pragma]
- resolved_tree = run_cmd(
- g_LAUNCHER + [
- g_JUST, "add-to-cas", "--local-build-root", g_ROOT,
- "--resolve-special=%s" % resolve_special_arg, srcdir
- ],
- cwd=workdir,
- stdout=subprocess.PIPE,
- fail_context=fail_context)[0].decode('utf-8').strip()
- # Stage the resolved tree
- resolved_dir: str = os.path.join(workdir, "resolved")
- subdir_args: List[str] = []
- if subdir is not None:
- subdir_args = ["-P", subdir]
- run_cmd(g_LAUNCHER + [
- g_JUST, "install-cas", "--local-build-root", g_ROOT,
- "%s::t" % resolved_tree, "-o", resolved_dir
- ] + subdir_args,
- cwd=workdir,
- fail_context=fail_context)
- move_from_dir = resolved_dir
- else:
- # Subdir is not None, so keep only that subdirectory
- move_from_dir = os.path.join(move_from_dir, cast(str, subdir))
-
- # Do the move into clone directory
+ # Keep relevant subdir
+ move_from_dir: str = os.path.join(workdir, subdir)
os.makedirs(clone_to, exist_ok=True)
for entry in os.listdir(move_from_dir):
# shutil.move uses os.rename if on same filesystem or
@@ -2250,7 +2207,6 @@ def clone_repo(repos: Json, known_repo: str, deps_chain: List[str],
except Exception as ex:
fail(fail_context + "Moving file path %s failed with:\n%r" %
(os.path.join(move_from_dir, entry), ex))
-
# Clean up tmp dir
try_rmtree(workdir)