From 78299d18cc0f6877c3713bb5c19827e5ed3f376e Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Sat, 7 Oct 2023 16:03:49 +0200 Subject: [PATCH] generator: raise minimum rust-packaging version to 24 for Fedora target --- rust2rpm/generator.py | 56 +++++++++++++------ .../samples/cxx-build-1.0.71.fedora.spec | 2 +- .../tests/samples/dotenvy-0.15.6.fedora.spec | 2 +- .../tests/samples/glib-sys-0.17.2.fedora.spec | 2 +- rust2rpm/tests/samples/nix-0.24.1.fedora.spec | 2 +- .../samples/rust2rpm-helper-0.1.3.fedora.spec | 2 +- .../tests/samples/tokio-1.19.2.fedora.spec | 2 +- .../tests/samples/zola-0.16.1.fedora.spec | 2 +- .../tests/samples/zola-0.16.1.mageia.spec | 2 +- .../tests/samples/zola-0.16.1.opensuse.spec | 2 +- rust2rpm/tests/samples/zola-0.16.1.plain.spec | 2 +- 11 files changed, 50 insertions(+), 26 deletions(-) diff --git a/rust2rpm/generator.py b/rust2rpm/generator.py index c6c68c0..0f1d7a5 100644 --- a/rust2rpm/generator.py +++ b/rust2rpm/generator.py @@ -16,6 +16,33 @@ from rust2rpm.licensing import translate_license from rust2rpm.metadata import package_uses_rust_1_60_feature_syntax, get_required_features_for_binaries +RUST_PACKAGING_DEPS: dict[int, str] = { + 21: "rust-packaging >= 21", + 23: "rust-packaging >= 23", + 24: "cargo-rpm-macros >= 24", + 25: "cargo-rpm-macros >= 25", +} + + +RUST_PACKAGING_TARGET_MIN: dict[str, int] = { + "fedora": 24, + "mageia": 21, + "opensuse": 21, + "plain": 21, +} + + +def min_rust_packaging_dep(package: Package, target: str, is_bin: bool, is_cdylib: bool) -> int: + if package_uses_rust_1_60_feature_syntax(package.features): + min_dep = 24 + elif is_bin or is_cdylib: + min_dep = 23 + else: + min_dep = 21 + + return max((min_dep, RUST_PACKAGING_TARGET_MIN[target])) + + def spec_file_template(filename: str): env = jinja2.Environment( loader=jinja2.ChoiceLoader([jinja2.FileSystemLoader(["/"]), jinja2.PackageLoader("rust2rpm", "templates")]), @@ -192,12 +219,7 @@ def spec_render_crate( for feature in features_hide: features.remove(feature) - 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" + rust_packaging_dep = RUST_PACKAGING_DEPS[min_rust_packaging_dep(package, target, is_bin, is_cdylib)] if feature_flags.all_features or tomlconf.features_enable_all: cargo_args = " -a" @@ -362,12 +384,7 @@ def spec_render_project( rpm_buildrequires = list(sorted(buildrequires)) rpm_test_requires = list(sorted(test_requires)) - 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" + rust_packaging_dep = RUST_PACKAGING_DEPS[min_rust_packaging_dep(package, target, is_bin, is_cdylib)] if feature_flags.all_features or tomlconf.features_enable_all: cargo_args = " -a" @@ -527,10 +544,17 @@ def spec_render_workspace( rpm_buildrequires = list(sorted(buildrequires)) rpm_test_requires = list(sorted(test_requires)) - if any(package_uses_rust_1_60_feature_syntax(package.features) for package in metadata.packages): - rust_packaging_dep = "cargo-rpm-macros >= 24" - else: - rust_packaging_dep = "rust-packaging >= 21" + rust_packaging_dep = RUST_PACKAGING_DEPS[ + max( + ( + 24, + max( + min_rust_packaging_dep(package, target, package.is_bin(), package.is_cdylib()) + for package in metadata.packages + ), + ) + ) + ] if feature_flags.all_features or tomlconf.features_enable_all: cargo_args = " -a" diff --git a/rust2rpm/tests/samples/cxx-build-1.0.71.fedora.spec b/rust2rpm/tests/samples/cxx-build-1.0.71.fedora.spec index 0bf486a..cd98b68 100644 --- a/rust2rpm/tests/samples/cxx-build-1.0.71.fedora.spec +++ b/rust2rpm/tests/samples/cxx-build-1.0.71.fedora.spec @@ -17,7 +17,7 @@ Patch: cxx-build-patch1.diff # Manually created patch for downstream crate metadata changes Patch: cxx-build-patch2.diff -BuildRequires: rust-packaging >= 21 +BuildRequires: cargo-rpm-macros >= 24 %global _description %{expand: C++ code generator for integrating `cxx` crate into a Cargo build.} diff --git a/rust2rpm/tests/samples/dotenvy-0.15.6.fedora.spec b/rust2rpm/tests/samples/dotenvy-0.15.6.fedora.spec index fa035f1..5e68659 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 >= 23 +BuildRequires: cargo-rpm-macros >= 24 %global _description %{expand: A well-maintained fork of the dotenv crate.} diff --git a/rust2rpm/tests/samples/glib-sys-0.17.2.fedora.spec b/rust2rpm/tests/samples/glib-sys-0.17.2.fedora.spec index bcd10f7..e46edee 100644 --- a/rust2rpm/tests/samples/glib-sys-0.17.2.fedora.spec +++ b/rust2rpm/tests/samples/glib-sys-0.17.2.fedora.spec @@ -19,7 +19,7 @@ Patch: glib-sys-patch1.diff # Manually created patch for downstream crate metadata changes Patch: glib-sys-patch2.diff -BuildRequires: rust-packaging >= 21 +BuildRequires: cargo-rpm-macros >= 24 %global _description %{expand: FFI bindings to libglib-2.0.} diff --git a/rust2rpm/tests/samples/nix-0.24.1.fedora.spec b/rust2rpm/tests/samples/nix-0.24.1.fedora.spec index 94e86b0..9445839 100644 --- a/rust2rpm/tests/samples/nix-0.24.1.fedora.spec +++ b/rust2rpm/tests/samples/nix-0.24.1.fedora.spec @@ -18,7 +18,7 @@ Patch: nix-patch1.diff # Manually created patch for downstream crate metadata changes Patch: nix-patch2.diff -BuildRequires: rust-packaging >= 21 +BuildRequires: cargo-rpm-macros >= 24 %global _description %{expand: Rust friendly bindings to *nix APIs.} diff --git a/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.fedora.spec b/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.fedora.spec index f511810..cb33e08 100644 --- a/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.fedora.spec +++ b/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.fedora.spec @@ -23,7 +23,7 @@ Patch: rust2rpm-helper-patch1.diff # Manually created patch for downstream crate metadata changes Patch: rust2rpm-helper-patch2.diff -BuildRequires: rust-packaging >= 23 +BuildRequires: cargo-rpm-macros >= 24 %global _description %{expand: Helper program for rust2rpm.} diff --git a/rust2rpm/tests/samples/tokio-1.19.2.fedora.spec b/rust2rpm/tests/samples/tokio-1.19.2.fedora.spec index de002bb..851fc43 100644 --- a/rust2rpm/tests/samples/tokio-1.19.2.fedora.spec +++ b/rust2rpm/tests/samples/tokio-1.19.2.fedora.spec @@ -17,7 +17,7 @@ Patch: tokio-patch1.diff # Manually created patch for downstream crate metadata changes Patch: tokio-patch2.diff -BuildRequires: rust-packaging >= 21 +BuildRequires: cargo-rpm-macros >= 24 %global _description %{expand: An event-driven, non-blocking I/O platform for writing asynchronous I/O diff --git a/rust2rpm/tests/samples/zola-0.16.1.fedora.spec b/rust2rpm/tests/samples/zola-0.16.1.fedora.spec index 966e78e..bec670e 100644 --- a/rust2rpm/tests/samples/zola-0.16.1.fedora.spec +++ b/rust2rpm/tests/samples/zola-0.16.1.fedora.spec @@ -14,7 +14,7 @@ License: # FIXME URL: # FIXME Source: # FIXME -BuildRequires: rust-packaging >= 21 +BuildRequires: cargo-rpm-macros >= 24 %global _description %{expand: A fast static site generator with everything built-in.} diff --git a/rust2rpm/tests/samples/zola-0.16.1.mageia.spec b/rust2rpm/tests/samples/zola-0.16.1.mageia.spec index cc97dd7..fecd972 100644 --- a/rust2rpm/tests/samples/zola-0.16.1.mageia.spec +++ b/rust2rpm/tests/samples/zola-0.16.1.mageia.spec @@ -17,7 +17,7 @@ Source: # FIXME ExclusiveArch: %{rust_arches} -BuildRequires: rust-packaging >= 21 +BuildRequires: cargo-rpm-macros >= 24 BuildRequires: (crate(ahash/default) >= 0.8.0 with crate(ahash/default) < 0.9.0~) BuildRequires: (crate(ammonia/default) >= 3.0.0 with crate(ammonia/default) < 4.0.0~) BuildRequires: (crate(anyhow/default) >= 1.0.56 with crate(anyhow/default) < 2.0.0~) diff --git a/rust2rpm/tests/samples/zola-0.16.1.opensuse.spec b/rust2rpm/tests/samples/zola-0.16.1.opensuse.spec index 390defe..d70c902 100644 --- a/rust2rpm/tests/samples/zola-0.16.1.opensuse.spec +++ b/rust2rpm/tests/samples/zola-0.16.1.opensuse.spec @@ -34,7 +34,7 @@ Source: # FIXME ExclusiveArch: %{rust_arches} -BuildRequires: rust-packaging >= 21 +BuildRequires: cargo-rpm-macros >= 24 BuildRequires: (crate(ahash/default) >= 0.8.0 with crate(ahash/default) < 0.9.0~) BuildRequires: (crate(ammonia/default) >= 3.0.0 with crate(ammonia/default) < 4.0.0~) BuildRequires: (crate(anyhow/default) >= 1.0.56 with crate(anyhow/default) < 2.0.0~) diff --git a/rust2rpm/tests/samples/zola-0.16.1.plain.spec b/rust2rpm/tests/samples/zola-0.16.1.plain.spec index 1ba829b..cce4587 100644 --- a/rust2rpm/tests/samples/zola-0.16.1.plain.spec +++ b/rust2rpm/tests/samples/zola-0.16.1.plain.spec @@ -16,7 +16,7 @@ Source: # FIXME ExclusiveArch: %{rust_arches} -BuildRequires: rust-packaging >= 21 +BuildRequires: cargo-rpm-macros >= 24 BuildRequires: (crate(ahash/default) >= 0.8.0 with crate(ahash/default) < 0.9.0~) BuildRequires: (crate(ammonia/default) >= 3.0.0 with crate(ammonia/default) < 4.0.0~) BuildRequires: (crate(anyhow/default) >= 1.0.56 with crate(anyhow/default) < 2.0.0~)