Skip to content

Commit

Permalink
cargo: Load Cargo.lock and subprojects/*.wrap while recursing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xclaesse committed Jun 17, 2024
1 parent 4aa5b35 commit 856ef89
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions mesonbuild/cargo/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 6 additions & 1 deletion mesonbuild/wrap/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,19 @@ 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():
self.provided_deps.setdefault(k, v)
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.
Expand Down

0 comments on commit 856ef89

Please sign in to comment.