From e527d8a25bb10f5131fc67c8519b5f4c65d404ec 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 | 3 +++ mesonbuild/interpreter/interpreter.py | 16 +++++++--------- mesonbuild/wrap/wrap.py | 7 ++++++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/mesonbuild/cargo/interpreter.py b/mesonbuild/cargo/interpreter.py index b7b5b4a98784..f8f73a3b2ef3 100644 --- a/mesonbuild/cargo/interpreter.py +++ b/mesonbuild/cargo/interpreter.py @@ -33,6 +33,7 @@ from . import manifest from .. import mparser from ..environment import Environment + from ..interpreterbase import SubProject # tomllib is present in python 3.11, before that it is a pypi module called tomli, # we try to import tomllib, then tomli, @@ -458,6 +459,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, T.cast('SubProject', 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 aab8b265ab4d..778afaee19e1 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1292,15 +1292,13 @@ 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(): - assert self.environment.wrap_resolver is not None, 'for mypy' - 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: + assert self.environment.wrap_resolver is not None, 'for mypy' + 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 197a4478a40e..7aae1663fd1f 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.