From 9de25b0a25ac92e829960fcb3176280937fb7868 Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Sat, 1 Apr 2023 16:07:22 +0200 Subject: [PATCH] conf/generator: support overriding generated RPM summary --- README.md | 5 +++++ rust2rpm/conf.py | 9 ++++++++- rust2rpm/generator.py | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ff887b8..9dd1181 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,11 @@ default settings (`[DEFAULT]`) and target-specific settings (i.e. `[fedora]`). These configuration options are available right now: +- `summary`: override the generated summary for the RPM package for cases where + generating a summary from the crate's description fails +- `supported-arches`: conditionally build and run tests only on specific + architectures (mostly useful for libraries with limited cross-platform + support - applications need to use `ExcludeArch` or `ExclusiveArch` instead) - `all-features`: enable all cargo features when generating `BuildRequires`, building the crate, and running cargo tests (defaults to `false`; setting this value to `true` is equivalent to supplying the `--all-features` CLI flag) diff --git a/rust2rpm/conf.py b/rust2rpm/conf.py index 745fe82..c1a249e 100644 --- a/rust2rpm/conf.py +++ b/rust2rpm/conf.py @@ -22,6 +22,7 @@ class Rust2RpmConf: def __init__( self, *, + summary: Optional[str] = None, supported_arches: list[str] = None, all_features: bool = False, unwanted_features: list[str] = None, @@ -31,6 +32,7 @@ class Rust2RpmConf: bin_requires: list[str] = None, lib_requires: dict[Optional[str], list[str]] = None, ): + self.summary = summary self.supported_arches: list[str] = supported_arches or list() self.all_features: bool = all_features self.unwanted_features: list[str] = unwanted_features or list() @@ -47,7 +49,8 @@ class Rust2RpmConf: # order of items in the list is consistent: # lists are sorted when parsing rust2rpm.conf files return ( - self.supported_arches == other.supported_arches + self.summary == other.summary + and self.supported_arches == other.supported_arches and self.all_features == other.all_features and self.unwanted_features == other.unwanted_features and self.enabled_features == other.enabled_features @@ -82,6 +85,7 @@ class Rust2RpmConf: # validate configuration file valid_targets = ["fedora", "mageia", "opensuse", "plain"] valid_keys = [ + "summary", "supported-arches", "all-features", "unwanted-features", @@ -107,6 +111,9 @@ class Rust2RpmConf: # parse configuration and validate settings settings = dict() + if summary := merged.get("summary"): + settings["summary"] = summary + if supported_arches := merged.get("supported-arches"): settings["supported_arches"] = to_list(supported_arches, False) diff --git a/rust2rpm/generator.py b/rust2rpm/generator.py index 4e17db0..04d83c1 100644 --- a/rust2rpm/generator.py +++ b/rust2rpm/generator.py @@ -185,7 +185,7 @@ def spec_render_crate( # Parameters for RPM package metadata "rpm_name": rpm_name, "rpm_version": Version.parse(package.version).to_rpm(), - "rpm_summary": summary, + "rpm_summary": distconf.summary or summary, "rpm_description": description, "rpm_license": rpm_license, "rpm_license_comments": rpm_license_comments, @@ -318,7 +318,7 @@ def spec_render_workspace( # Parameters for RPM package metadata "rpm_name": rpm_name, "rpm_version": rpm_version, - "rpm_summary": rpm_summary, + "rpm_summary": distconf.summary or rpm_summary, "rpm_description": rpm_description, "rpm_license": rpm_license_tag, "rpm_license_comments": rpm_license_comments,