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 authored and nirbheek committed Aug 16, 2024
1 parent 4b76aab commit 42a4d1a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 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,11 @@ 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:
mlog.warning('Failed to load Cargo.lock:', str(e), fatal=False)
return wraps
for package in cargolock['package']:
name = package['name']
version = package['version']
Expand Down

0 comments on commit 42a4d1a

Please sign in to comment.