do better for renamed crates

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
This commit is contained in:
Igor Gnatenko 2018-09-11 00:06:50 +02:00
parent 561280a0ea
commit 2050880140
No known key found for this signature in database
GPG key ID: 695714BD1BBC5F4C
2 changed files with 16 additions and 4 deletions

View file

@ -180,7 +180,7 @@ def make_diff_metadata(crate, version, patch=False, store=False):
diff = make_patch(toml, enabled=patch)
metadata = Metadata.from_file(toml)
if store:
shutil.copy2(cratef, os.path.join(os.getcwd(), f"{crate}-{version}.crate"))
shutil.copy2(cratef, os.path.join(os.getcwd(), f"{metadata.name}-{version}.crate"))
return crate, diff, metadata
def main():
@ -218,11 +218,12 @@ def main():
template = JINJA_ENV.get_template("main.spec")
if args.patch and len(diff) > 0:
patch_file = "{}-fix-metadata.diff".format(metadata.name)
patch_file = f"{metadata.name}-fix-metadata.diff"
else:
patch_file = None
kwargs = {}
kwargs["crate"] = crate
kwargs["target"] = args.target
bins = [tgt for tgt in metadata.targets if tgt.kind == "bin"]
libs = [tgt for tgt in metadata.targets if tgt.kind in ("lib", "rlib", "proc-macro")]
@ -269,7 +270,7 @@ def main():
kwargs["license"] = license
kwargs["license_comments"] = comments
spec_file = "rust-{}.spec".format(metadata.name)
spec_file = f"rust-{metadata.name}.spec"
spec_contents = template.render(md=metadata, patch_file=patch_file, **kwargs)
if args.stdout:
print("# {}".format(spec_file))

View file

@ -6,6 +6,9 @@
{% endif %}
%global crate {{ md.name }}
{% if md.name != crate %}
%global real_crate {{ crate }}
{% endif %}
Name: rust-%{crate}
Version: {{ md.version }}
@ -27,8 +30,12 @@ License: {{ license|default("# FIXME") }}
{% if license_comments is not none %}
{{ license_comments }}
{% endif %}
URL: https://crates.io/crates/{{ md.name }}
URL: https://crates.io/crates/{{ crate }}
{% if md.name != crate %}
Source0: https://crates.io/api/v1/crates/%{real_crate}/%{version}/download#/%{crate}-%{version}.crate
{% else %}
Source0: https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{crate}-%{version}.crate
{% endif %}
{% if patch_file is not none %}
{% if target == "opensuse" %}
# PATCH-FIX-OPENSUSE {{ patch_file }} -- Initial patched metadata
@ -118,7 +125,11 @@ which use %{crate} from crates.io.
{% endif %}
%prep
{% if md.name != crate %}
%autosetup -n %{real_crate}-%{version} -p1
{% else %}
%autosetup -n %{crate}-%{version} -p1
{% endif %}
%cargo_prep
%build