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.
pull/13815/head
Xavier Claessens 5 months ago committed by Xavier Claessens
parent ed62a975b2
commit 6736a540c7
  1. 3
      mesonbuild/cargo/interpreter.py
  2. 16
      mesonbuild/interpreter/interpreter.py
  3. 7
      mesonbuild/wrap/wrap.py

@ -33,6 +33,7 @@ if T.TYPE_CHECKING:
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 @@ class Interpreter:
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

@ -1294,15 +1294,13 @@ class Interpreter(InterpreterBase, HoldableObject):
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))

@ -394,7 +394,7 @@ class Resolver:
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 @@ class Resolver:
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.

Loading…
Cancel
Save