From 9cfcdd8b6ca4b7d5bd6aad126ecc2610fe22cf91 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Mon, 17 Jun 2024 13:33:38 -0400 Subject: [PATCH] cargo: Load Cargo.lock and subprojects/*.wrap while recursing In the case the main project has a .wrap file for a cargo subproject, that subproject's Cargo.lock must be loaded before we can recursively fetch all its dependencies. --- mesonbuild/cargo/interpreter.py | 2 ++ mesonbuild/interpreter/interpreter.py | 14 ++++++-------- mesonbuild/wrap/wrap.py | 7 ++++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/mesonbuild/cargo/interpreter.py b/mesonbuild/cargo/interpreter.py index 027dd40239af..979961219389 100644 --- a/mesonbuild/cargo/interpreter.py +++ b/mesonbuild/cargo/interpreter.py @@ -454,6 +454,8 @@ def _fetch_package(self, package_name: str, api: str) -> T.Tuple[PackageState, b return pkg, True meson_depname = _dependency_name(package_name, api) subdir, _ = self.environment.wrap_resolver.resolve(meson_depname) + subprojects_dir = os.path.join(subdir, 'subprojects') + self.environment.wrap_resolver.load_and_merge(subprojects_dir, meson_depname) manifest = self._load_manifest(subdir) pkg = PackageState(manifest) self.packages[key] = pkg diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 200396b2bd65..cc40fe7dc8fd 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1286,14 +1286,12 @@ def func_project(self, node: mparser.FunctionNode, args: T.Tuple[str, T.List[str self.build.subproject_dir = self.subproject_dir # Load wrap files from this (sub)project. - wrap_mode = WrapMode.from_string(self.coredata.get_option(OptionKey('wrap_mode'))) - if not self.is_subproject() or wrap_mode != WrapMode.nopromote: - subdir = os.path.join(self.subdir, spdirname) - r = wrap.Resolver(self.environment.get_source_dir(), subdir, self.subproject, wrap_mode) - if self.is_subproject(): - self.environment.wrap_resolver.merge_wraps(r) - else: - self.environment.wrap_resolver = r + subprojects_dir = os.path.join(self.subdir, spdirname) + if not self.is_subproject: + wrap_mode = WrapMode.from_string(self.coredata.get_option(OptionKey('wrap_mode'))) + self.environment.wrap_resolver = wrap.Resolver(self.environment.get_source_dir(), subprojects_dir, self.subproject, wrap_mode) + else: + self.environment.wrap_resolver.load_and_merge(subprojects_dir, self.subproject) self.build.projects[self.subproject] = proj_name mlog.log('Project name:', mlog.bold(proj_name)) diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py index 4e98c600cf87..0cadf2e6f952 100644 --- a/mesonbuild/wrap/wrap.py +++ b/mesonbuild/wrap/wrap.py @@ -394,7 +394,7 @@ def get_from_wrapdb(self, subp_name: str) -> T.Optional[PackageDefinition]: self.add_wrap(wrap) return wrap - def merge_wraps(self, other_resolver: 'Resolver') -> None: + def _merge_wraps(self, other_resolver: 'Resolver') -> None: for k, v in other_resolver.wraps.items(): self.wraps.setdefault(k, v) for k, v in other_resolver.provided_deps.items(): @@ -402,6 +402,11 @@ def merge_wraps(self, other_resolver: 'Resolver') -> None: for k, v in other_resolver.provided_programs.items(): self.provided_programs.setdefault(k, v) + def load_and_merge(self, subdir: str, subproject: SubProject) -> None: + if self.wrap_mode != WrapMode.nopromote: + other_resolver = Resolver(self.source_dir, subdir, subproject, self.wrap_mode, self.wrap_frontend, self.allow_insecure, self.silent) + self._merge_wraps(other_resolver) + def find_dep_provider(self, packagename: str) -> T.Tuple[T.Optional[str], T.Optional[str]]: # Python's ini parser converts all key values to lowercase. # Thus the query name must also be in lower case.