Skip to content

Commit

Permalink
cargo: Ignore Cargo.lock if toml implementation is missing
Browse files Browse the repository at this point in the history
It is only required if a Cargo subproject is actually configured.
  • Loading branch information
xclaesse committed Aug 15, 2024
1 parent 85e9233 commit e8b98a3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mesonbuild/cargo/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@
toml2json = shutil.which('toml2json')


class TomlImplementationMissing(MesonException):
pass


def load_toml(filename: str) -> T.Dict[object, object]:
if tomllib:
with open(filename, 'rb') as f:
raw = tomllib.load(f)
else:
if toml2json is None:
raise MesonException('Could not find an implementation of tomllib, nor toml2json')
raise TomlImplementationMissing('Could not find an implementation of tomllib, nor toml2json')

p, out, err = Popen_safe([toml2json, filename])
if p.returncode != 0:
Expand Down Expand Up @@ -742,7 +746,10 @@ def load_wraps(source_dir: str, subproject_dir: str) -> T.List[PackageDefinition
wraps: T.List[PackageDefinition] = []
filename = os.path.join(source_dir, 'Cargo.lock')
if os.path.exists(filename):
cargolock = T.cast('manifest.CargoLock', load_toml(filename))
try:
cargolock = T.cast('manifest.CargoLock', load_toml(filename))
except TomlImplementationMissing as e:
return wraps
for package in cargolock['package']:
name = package['name']
version = package['version']
Expand Down

0 comments on commit e8b98a3

Please sign in to comment.