Skip to content

Commit

Permalink
cargo: Fix crash when enabling feature on dev/build dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
xclaesse committed Dec 1, 2024
1 parent fd309ff commit dc6fa2d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions mesonbuild/cargo/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,18 +543,27 @@ def _load_manifest(self, subdir: str) -> Manifest:
raise MesonException(f'{subdir}/Cargo.toml does not have [package] section')
return manifest_

def _add_dependency(self, pkg: PackageState, depname: str) -> None:
def _add_dependency(self, pkg: PackageState, depname: str) -> T.Optional[PackageState]:
if depname in pkg.required_deps:
return
dep = pkg.manifest.dependencies.get(depname)
if dep is None:
if depname in pkg.manifest.dev_dependencies:
# FIXME: Not supported yet
return None
if depname in pkg.manifest.build_dependencies:
# FIXME: Not supported yet
return None
raise MesonException(f'Dependency {depname} not defined in {pkg.manifest.package.name} manifest')
pkg.required_deps.add(depname)
dep = pkg.manifest.dependencies[depname]
dep_pkg, _ = self._fetch_package(dep.package, dep.api)
if dep.default_features:
self._enable_feature(dep_pkg, 'default')
for f in dep.features:
self._enable_feature(dep_pkg, f)
for f in pkg.optional_deps_features[depname]:
self._enable_feature(dep_pkg, f)
return dep_pkg

def _enable_feature(self, pkg: PackageState, feature: str) -> None:
if feature in pkg.features:
Expand All @@ -579,10 +588,9 @@ def _enable_feature(self, pkg: PackageState, feature: str) -> None:
# is later added.
pkg.optional_deps_features[depname].add(dep_f)
else:
self._add_dependency(pkg, depname)
dep = pkg.manifest.dependencies[depname]
dep_pkg = self._dep_package(dep)
self._enable_feature(dep_pkg, dep_f)
dep_pkg = self._add_dependency(pkg, depname)
if dep_pkg is not None:
self._enable_feature(dep_pkg, dep_f)
elif f.startswith('dep:'):
self._add_dependency(pkg, f[4:])
else:
Expand Down

0 comments on commit dc6fa2d

Please sign in to comment.