From 7166b781bd281790c331f322ece6169e2560ca90 Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Sun, 6 Aug 2023 11:02:26 +0200 Subject: [PATCH] template: include %cargo_license / %cargo_license_summary macros The macros are now well-tested and can be used unconditionally for packages that ship statically linked binaries (executables or shared libraries). --- rust2rpm/generator.py | 3 +++ rust2rpm/templates/crate.spec | 8 ++++++++ rust2rpm/tests/samples/dotenvy-0.15.6.fedora.spec | 8 +++++++- rust2rpm/tests/samples/dotenvy-0.15.6.mageia.spec | 8 +++++++- rust2rpm/tests/samples/dotenvy-0.15.6.opensuse.spec | 8 +++++++- rust2rpm/tests/samples/dotenvy-0.15.6.plain.spec | 8 +++++++- 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/rust2rpm/generator.py b/rust2rpm/generator.py index 04d83c1..3acb87b 100644 --- a/rust2rpm/generator.py +++ b/rust2rpm/generator.py @@ -155,12 +155,15 @@ def spec_render_crate( if package_uses_rust_1_60_feature_syntax(package.features): rust_packaging_dep = "cargo-rpm-macros >= 24" + elif is_bin or is_cdylib: + rust_packaging_dep = "rust-packaging >= 23" else: rust_packaging_dep = "rust-packaging >= 21" if feature_flags.all_features or distconf.all_features: cargo_args = " -a" elif required_features := get_required_features_for_binaries(package): + # FIXME: remove features that are already part of the default feature set # merge, de-duplicate, and re-sort lists of enabled features enabled_features = sorted(set.union(set(required_features), set(distconf.enabled_features))) cargo_args = f" -f {','.join(enabled_features)}" diff --git a/rust2rpm/templates/crate.spec b/rust2rpm/templates/crate.spec index beb7d9e..9c6bd1c 100644 --- a/rust2rpm/templates/crate.spec +++ b/rust2rpm/templates/crate.spec @@ -100,6 +100,9 @@ Group: # FIXME {% for req in conf_bin_requires %} Requires: {{ req }} {% endfor %} +# FIXME: paste output of %cargo_license_summary here +License: # FIXME +# LICENSE.dependencies contains a full license breakdown %description -n %{crate} %{_description} @@ -111,6 +114,7 @@ Requires: {{ req }} {% else %} # FIXME: no license files detected {% endif %} +%license LICENSE.dependencies {% for file in rpm_doc_files %} %doc {{ file }} {% endfor %} @@ -208,6 +212,10 @@ echo {{ "%r" | format(req) }} {% if conf_supported_arches %} %endif {% endif %} +{% if rpm_binary_package or rpm_cdylib_package %} +%{cargo_license_summary{{ cargo_args }}} +%{cargo_license{{ cargo_args }}} > LICENSE.dependencies +{% endif %} %install {% if rpm_cdylib_package and (rpm_library_package or rpm_binary_package) %} diff --git a/rust2rpm/tests/samples/dotenvy-0.15.6.fedora.spec b/rust2rpm/tests/samples/dotenvy-0.15.6.fedora.spec index d488914..9b54819 100644 --- a/rust2rpm/tests/samples/dotenvy-0.15.6.fedora.spec +++ b/rust2rpm/tests/samples/dotenvy-0.15.6.fedora.spec @@ -16,7 +16,7 @@ Patch: dotenvy-patch1.diff # Manually created patch for downstream crate metadata changes Patch: dotenvy-patch2.diff -BuildRequires: rust-packaging >= 21 +BuildRequires: rust-packaging >= 23 %global _description %{expand: A well-maintained fork of the dotenv crate.} @@ -25,12 +25,16 @@ A well-maintained fork of the dotenv crate.} %package -n %{crate} Summary: %{summary} +# FIXME: paste output of %cargo_license_summary here +License: # FIXME +# LICENSE.dependencies contains a full license breakdown %description -n %{crate} %{_description} %files -n %{crate} %license LIC1 %license LIC2 +%license LICENSE.dependencies %doc DOC1 %doc DOC2 %{_bindir}/dotenvy @@ -96,6 +100,8 @@ use the "cli" feature of the "%{crate}" crate. %build %cargo_build -f cli +%{cargo_license_summary -f cli} +%{cargo_license -f cli} > LICENSE.dependencies %install %cargo_install -f cli diff --git a/rust2rpm/tests/samples/dotenvy-0.15.6.mageia.spec b/rust2rpm/tests/samples/dotenvy-0.15.6.mageia.spec index d8e6de0..4d4bc01 100644 --- a/rust2rpm/tests/samples/dotenvy-0.15.6.mageia.spec +++ b/rust2rpm/tests/samples/dotenvy-0.15.6.mageia.spec @@ -19,7 +19,7 @@ Patch: dotenvy-patch2.diff ExclusiveArch: %{rust_arches} -BuildRequires: rust-packaging >= 21 +BuildRequires: rust-packaging >= 23 %if %{with check} BuildRequires: (crate(dirs/default) >= 4.0.0 with crate(dirs/default) < 5.0.0~) BuildRequires: (crate(tempfile/default) >= 3.3.0 with crate(tempfile/default) < 4.0.0~) @@ -33,12 +33,16 @@ A well-maintained fork of the dotenv crate.} %package -n %{crate} Summary: %{summary} Group: # FIXME +# FIXME: paste output of %cargo_license_summary here +License: # FIXME +# LICENSE.dependencies contains a full license breakdown %description -n %{crate} %{_description} %files -n %{crate} %license LIC1 %license LIC2 +%license LICENSE.dependencies %doc DOC1 %doc DOC2 %{_bindir}/dotenvy @@ -105,6 +109,8 @@ use the "cli" feature of the "%{crate}" crate. %build %cargo_build -f cli +%{cargo_license_summary -f cli} +%{cargo_license -f cli} > LICENSE.dependencies %install %cargo_install -f cli diff --git a/rust2rpm/tests/samples/dotenvy-0.15.6.opensuse.spec b/rust2rpm/tests/samples/dotenvy-0.15.6.opensuse.spec index 0564825..6642ab0 100644 --- a/rust2rpm/tests/samples/dotenvy-0.15.6.opensuse.spec +++ b/rust2rpm/tests/samples/dotenvy-0.15.6.opensuse.spec @@ -36,7 +36,7 @@ Patch: dotenvy-patch2.diff ExclusiveArch: %{rust_arches} -BuildRequires: rust-packaging >= 21 +BuildRequires: rust-packaging >= 23 %if %{with check} BuildRequires: (crate(dirs/default) >= 4.0.0 with crate(dirs/default) < 5.0.0~) BuildRequires: (crate(tempfile/default) >= 3.3.0 with crate(tempfile/default) < 4.0.0~) @@ -50,12 +50,16 @@ A well-maintained fork of the dotenv crate.} %package -n %{crate} Summary: %{summary} Group: # FIXME +# FIXME: paste output of %cargo_license_summary here +License: # FIXME +# LICENSE.dependencies contains a full license breakdown %description -n %{crate} %{_description} %files -n %{crate} %license LIC1 %license LIC2 +%license LICENSE.dependencies %doc DOC1 %doc DOC2 %{_bindir}/dotenvy @@ -122,6 +126,8 @@ use the "cli" feature of the "%{crate}" crate. %build %cargo_build -f cli +%{cargo_license_summary -f cli} +%{cargo_license -f cli} > LICENSE.dependencies %install %cargo_install -f cli diff --git a/rust2rpm/tests/samples/dotenvy-0.15.6.plain.spec b/rust2rpm/tests/samples/dotenvy-0.15.6.plain.spec index 06c0878..3ce98aa 100644 --- a/rust2rpm/tests/samples/dotenvy-0.15.6.plain.spec +++ b/rust2rpm/tests/samples/dotenvy-0.15.6.plain.spec @@ -18,7 +18,7 @@ Patch: dotenvy-patch2.diff ExclusiveArch: %{rust_arches} -BuildRequires: rust-packaging >= 21 +BuildRequires: rust-packaging >= 23 %if %{with check} BuildRequires: (crate(dirs/default) >= 4.0.0 with crate(dirs/default) < 5.0.0~) BuildRequires: (crate(tempfile/default) >= 3.3.0 with crate(tempfile/default) < 4.0.0~) @@ -31,12 +31,16 @@ A well-maintained fork of the dotenv crate.} %package -n %{crate} Summary: %{summary} +# FIXME: paste output of %cargo_license_summary here +License: # FIXME +# LICENSE.dependencies contains a full license breakdown %description -n %{crate} %{_description} %files -n %{crate} %license LIC1 %license LIC2 +%license LICENSE.dependencies %doc DOC1 %doc DOC2 %{_bindir}/dotenvy @@ -112,6 +116,8 @@ use the "cli" feature of the "%{crate}" crate. %build %cargo_build -f cli +%{cargo_license_summary -f cli} +%{cargo_license -f cli} > LICENSE.dependencies %install %cargo_install -f cli