From 4c36ef43808f8e0382798f4ab4e6898f0a7f2e39 Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Tue, 20 Feb 2024 18:14:31 +0100 Subject: [PATCH] conf: add a setting for overriding the name of the "bin" subpackage --- docs/rust2rpm.toml.5.asciidoc | 5 +++++ rust2rpm/conf.py | 11 ++++++++++ rust2rpm/generator.py | 6 +++++ rust2rpm/templates/README.md | 41 ++++++++++++++++++----------------- rust2rpm/templates/crate.spec | 6 ++--- 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/docs/rust2rpm.toml.5.asciidoc b/docs/rust2rpm.toml.5.asciidoc index 22de76f..0643ed6 100644 --- a/docs/rust2rpm.toml.5.asciidoc +++ b/docs/rust2rpm.toml.5.asciidoc @@ -41,6 +41,11 @@ This table contains settings that affect RPM metadata. is present, the "cargo build" and "cargo test" steps in the generated spec file are wrapped with "%ifarch" conditionals. +*bin-package-name*:: + This setting can be used to override the name of the subpackage that is + generated if there are any "bin" (or "cdylib") targets. The default is to + fall back to the name of the current crate ("%{crate}"). + === [tests] table This table contains settings that control which tests are run. If any settings diff --git a/rust2rpm/conf.py b/rust2rpm/conf.py index 8e95655..02ec8c3 100644 --- a/rust2rpm/conf.py +++ b/rust2rpm/conf.py @@ -33,6 +33,10 @@ TOML_SCHEMA = { "uniqueItems": True, }, }, + # override binary subpackage name + "bin-package-name": { + "type": "string", + }, }, "additionalProperties": False, }, @@ -351,6 +355,13 @@ class TomlConf: else: return None + @property + def package_bin_package_name(self) -> Optional[str]: + if package := self._package: + return package.get("bin-package-name") + else: + return None + @property def _tests(self) -> Optional[dict[str, Any]]: return self._data.get("tests") diff --git a/rust2rpm/generator.py b/rust2rpm/generator.py index d699b4b..55be085 100644 --- a/rust2rpm/generator.py +++ b/rust2rpm/generator.py @@ -184,6 +184,11 @@ def spec_render_crate( is_lib = metadata.is_lib() is_cdylib = metadata.is_cdylib() + if tomlconf.package_bin_package_name is None: + bin_name = "%{crate}" + else: + bin_name = tomlconf.package_bin_package_name + package = metadata.packages[0] description = package.get_description() summary = package.get_summary() @@ -303,6 +308,7 @@ def spec_render_crate( "rpm_vendor_source": vendor_tarball, # Parameters that control generation of subpackages "rpm_binary_package": is_bin, + "rpm_binary_package_name": bin_name, "rpm_cdylib_package": is_cdylib, "rpm_library_package": is_lib, "rpm_binary_names": binaries, diff --git a/rust2rpm/templates/README.md b/rust2rpm/templates/README.md index 2e476d5..1c37a7a 100644 --- a/rust2rpm/templates/README.md +++ b/rust2rpm/templates/README.md @@ -33,13 +33,14 @@ ### Parameters that control generation of subpackages -| parameter name | type | value | -| --------------------- | --------------------- | --------------------------------------------------------------------------- | -| `rpm_binary_package` | `bool` | `True` if package ships any binaries, `False` for source-only packages | -| `rpm_cdylib_package` | `bool` | `True` if package ships any shared libraries (`cdylib` targets) | -| `rpm_library_package` | `bool` | `True` if package has a library component, `False` for binary-only packages | -| `rpm_binary_names` | `list[str]` | list of the names of executables which are built from the crate | -| `crate_features` | `list[Optional[str]]` | list of names of features for which sub-packages are generated | +| parameter name | type | value | +| ------------------------- | --------------------- | --------------------------------------------------------------------------- | +| `rpm_binary_package` | `bool` | `True` if package ships any binaries, `False` for source-only packages | +| `rpm_binary_package_name` | `str` | override name of the binary subpackage (default: `%{crate}`) | +| `rpm_cdylib_package` | `bool` | `True` if package ships any shared libraries (`cdylib` targets) | +| `rpm_library_package` | `bool` | `True` if package has a library component, `False` for binary-only packages | +| `rpm_binary_names` | `list[str]` | list of the names of executables which are built from the crate | +| `crate_features` | `list[Optional[str]]` | list of names of features for which sub-packages are generated | ### Parameters for crate metadata @@ -50,14 +51,14 @@ | `crate_license` | `Optional[str]` | crate license (from `Cargo.toml` metadata) | | `upstream_version` | `str` | upstream crate version (from `crates.io`) | -### Parameters derived from rust2rpm configuration +### Other parameters derived from rust2rpm configuration | parameter name | type | value | | ----------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------ | -| `conf_buildrequires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.conf` | -| `conf_test_requires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.conf` that are gated by an `%if %{with check}` conditional | -| `conf_bin_requires` | `list[str]` | list of additional RPM `Requires` for the binary package specified in `rust2rpm.conf` | -| `conf_lib_requires` | `dict[str, list[str]]` | map of feature names to lists of additional RPM `Requires` for library packages specified in `rust2rpm.conf` | +| `conf_buildrequires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.toml` | +| `conf_test_requires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.toml` that are gated by an `%if %{with check}` conditional | +| `conf_bin_requires` | `list[str]` | list of additional RPM `Requires` for the binary package specified in `rust2rpm.toml` | +| `conf_lib_requires` | `dict[str, list[str]]` | map of feature names to lists of additional RPM `Requires` for library packages specified in `rust2rpm.toml` | | `conf_supported_arches` | `list[str]` | list of supported architectures (results in `%ifarch` conditionals around `%cargo_build` and `%cargo_test` macros) | | `cargo_test_args` | `list[str]` | list of arguments that are passed to `%cargo_test` | @@ -129,13 +130,13 @@ | `crate_license` | `Optional[str]` | crate license (from `Cargo.toml` metadata) | | `upstream_version` | `str` | upstream crate version (from `crates.io`) | -### Parameters derived from rust2rpm configuration +### Other parameters derived from rust2rpm configuration | parameter name | type | value | | ----------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------ | -| `conf_buildrequires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.conf` | -| `conf_test_requires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.conf` that are gated by an `%if %{with check}` conditional | -| `conf_bin_requires` | `list[str]` | list of additional RPM `Requires` for the binary package specified in `rust2rpm.conf` | +| `conf_buildrequires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.toml` | +| `conf_test_requires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.toml` that are gated by an `%if %{with check}` conditional | +| `conf_bin_requires` | `list[str]` | list of additional RPM `Requires` for the binary package specified in `rust2rpm.toml` | | `conf_supported_arches` | `list[str]` | list of supported architectures (results in `%ifarch` conditionals around `%cargo_build` and `%cargo_test` macros) | | `cargo_test_args` | `list[str]` | list of arguments that are passed to `%cargo_test` | @@ -186,13 +187,13 @@ | `rpm_bcond_check` | `bool` | flag to switch default value of the `check` bcond | | `rpm_test_comments` | `list[str]` | comments that document why (specific) tests are disabled | -### Parameters derived from rust2rpm configuration +### Other parameters derived from rust2rpm configuration | parameter name | type | value | | -------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------ | -| `conf_buildrequires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.conf` | -| `conf_test_requires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.conf` that are gated by an `%if %{with check}` conditional | -| `conf_bin_requires` | `list[str]` | list of additional RPM `Requires` for the binary package specified in `rust2rpm.conf` | +| `conf_buildrequires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.toml` | +| `conf_test_requires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.toml` that are gated by an `%if %{with check}` conditional | +| `conf_bin_requires` | `list[str]` | list of additional RPM `Requires` for the binary package specified in `rust2rpm.toml` | | `cargo_test_args` | `list[str]` | list of arguments that are passed to `%cargo_test` | ### Parameters derived from command-line flags diff --git a/rust2rpm/templates/crate.spec b/rust2rpm/templates/crate.spec index 76e4c79..bb90df1 100644 --- a/rust2rpm/templates/crate.spec +++ b/rust2rpm/templates/crate.spec @@ -114,7 +114,7 @@ BuildRequires: {{ req }} %description %{_description} {% if rpm_binary_package or rpm_cdylib_package %} -%package -n %{crate} +%package -n {{ rpm_binary_package_name }} Summary: %{summary} {% if rpm_group is defined %} Group: # FIXME @@ -126,9 +126,9 @@ License: # FIXME Requires: {{ req }} {% endfor %} -%description -n %{crate} %{_description} +%description -n {{ rpm_binary_package_name }} %{_description} -%files -n %{crate} +%files -n {{ rpm_binary_package_name }} {% if rpm_license_files|length > 0 %} {% for file in rpm_license_files %} %license {{ file }}