rust2rpm: return single metadata

When generating the spec file, takes care of asserting that there is a
single metadata.  If not, write a warning.
This commit is contained in:
Alberto Planas 2021-10-13 14:25:18 +02:00
parent 1883197d9c
commit 31a778c4f2

View file

@ -261,6 +261,9 @@ def make_diff_metadata(crate, version, patch=False, store=False):
toml, crate, version, doc_files, license_files = local_toml(crate, version)
diff = make_patch(toml, enabled=patch, tmpfile=True)
metadata = Metadata.from_file(toml)
if len(metadata) > 1:
print(f"Warning: multiple metadata for {toml}")
metadata = metadata[0]
return metadata.name, diff, metadata, doc_files, license_files
else:
cratef, crate, version = download(crate, version)
@ -268,6 +271,9 @@ def make_diff_metadata(crate, version, patch=False, store=False):
with files_from_crate(cratef, crate, version) as (toml, doc_files, license_files):
diff = make_patch(toml, enabled=patch)
metadata = Metadata.from_file(toml)
if len(metadata) > 1:
print(f"Warning: multiple metadata for {toml}")
metadata = metadata[0]
if store:
shutil.copy2(cratef, os.path.join(os.getcwd(), f"{metadata.name}-{version}.crate"))
return crate, diff, metadata, doc_files, license_files