diff --git a/docs/rust2rpm.toml.5.asciidoc b/docs/rust2rpm.toml.5.asciidoc index 0643ed6..770d764 100644 --- a/docs/rust2rpm.toml.5.asciidoc +++ b/docs/rust2rpm.toml.5.asciidoc @@ -46,6 +46,18 @@ This table contains settings that affect RPM metadata. generated if there are any "bin" (or "cdylib") targets. The default is to fall back to the name of the current crate ("%{crate}"). +*cargo-install-lib*:: + This setting controls whether library sources are installed by the + %cargo_install macro. Setting "false" for this key causes crate sources not + to be installed to %{crate_instdir} even if a library target is auto-detected + or the crate defines a [lib] target explicitly. The default value is "true". + +*cargo-install-bin*:: + This setting controls whether binary targets are installed by the + %cargo_install macro. Setting "false" for this key causes "bin" targets not + to be installed to %{_bindir} even if a "bin" target is auto-detected or the + crate defines any "bin" target explicitly. The default value is "true". + === [tests] table This table contains settings that control which tests are run. If any settings diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py index f92a398..08d2094 100644 --- a/rust2rpm/__main__.py +++ b/rust2rpm/__main__.py @@ -191,11 +191,14 @@ def main(): warn_if_package_uses_restrictive_dependencies(package) try: + compat = args.compat or args.suffix is not None + spec_contents = spec_render_crate( metadata=metadata, upstream_version=version, target=args.target, rpm_name=rpm_name, + compat=compat, patch_file_automatic=patch_files[0], patch_file_manual=patch_files[1], license_files=license_files, diff --git a/rust2rpm/cli.py b/rust2rpm/cli.py index 15a8c67..ef9192c 100644 --- a/rust2rpm/cli.py +++ b/rust2rpm/cli.py @@ -98,6 +98,7 @@ def get_parser() -> argparse.ArgumentParser: parser.add_argument( "--compat", action="store_true", + default=False, help="Create a compat package with appropriate version suffix", ) parser.add_argument( diff --git a/rust2rpm/conf.py b/rust2rpm/conf.py index 02ec8c3..5fa678a 100644 --- a/rust2rpm/conf.py +++ b/rust2rpm/conf.py @@ -37,6 +37,14 @@ TOML_SCHEMA = { "bin-package-name": { "type": "string", }, + # override installation of binary targets + "cargo-install-bin": { + "type": "boolean", + }, + # override installation of library sources + "cargo-install-lib": { + "type": "boolean", + }, }, "additionalProperties": False, }, @@ -362,6 +370,20 @@ class TomlConf: else: return None + @property + def package_cargo_install_bin(self) -> Optional[bool]: + if package := self._package: + return package.get("cargo-install-bin") + else: + return None + + @property + def package_cargo_install_lib(self) -> Optional[bool]: + if package := self._package: + return package.get("cargo-install-lib") + 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 36cdfbe..5afe479 100644 --- a/rust2rpm/generator.py +++ b/rust2rpm/generator.py @@ -21,6 +21,7 @@ RUST_PACKAGING_DEPS: dict[int, str] = { 23: "rust-packaging >= 23", 24: "cargo-rpm-macros >= 24", 25: "cargo-rpm-macros >= 25", + 26: "cargo-rpm-macros >= 26", } @@ -44,9 +45,17 @@ def license_is_composite(license: str) -> bool: def min_rust_packaging_dep( - package: Package, target: str, is_bin: bool, is_cdylib: bool, vendor_tarball: Optional[str] + package: Package, + target: str, + is_bin: bool, + is_cdylib: bool, + vendor_tarball: Optional[str], + cargo_install_lib: bool, + cargo_install_bin: bool, ) -> int: - if vendor_tarball: + if (not cargo_install_lib) or (not cargo_install_bin): + min_dep = 26 + elif vendor_tarball: min_dep = 25 elif package_uses_rust_1_60_feature_syntax(package.features): min_dep = 24 @@ -161,6 +170,7 @@ def spec_render_crate( upstream_version: str, target: str, rpm_name: str, + compat: bool, patch_file_automatic: Optional[str], patch_file_manual: Optional[str], license_files: list[str], @@ -184,6 +194,9 @@ def spec_render_crate( is_lib = metadata.is_lib() is_cdylib = metadata.is_cdylib() + cargo_install_lib = (tomlconf.package_cargo_install_lib is not False) and (vendor_tarball is None) + cargo_install_bin = (tomlconf.package_cargo_install_bin is not False) and (not compat) + if tomlconf.package_bin_package_name is None: bin_name = "%{crate}" else: @@ -253,7 +266,9 @@ def spec_render_crate( for feature in features_hide: features.remove(feature) - rust_packaging_dep = RUST_PACKAGING_DEPS[min_rust_packaging_dep(package, target, is_bin, is_cdylib, vendor_tarball)] + rust_packaging_dep = RUST_PACKAGING_DEPS[ + min_rust_packaging_dep(package, target, is_bin, is_cdylib, vendor_tarball, cargo_install_lib, cargo_install_bin) + ] if feature_flags.all_features or tomlconf.features_enable_all: cargo_args = " -a" @@ -326,6 +341,8 @@ def spec_render_crate( "rpm_library_package": is_lib, "rpm_binary_names": binaries, "crate_features": features, + "cargo_install_lib": cargo_install_lib, + "cargo_install_bin": cargo_install_bin, # Parameters for crate metadata "crate_name": package.name, "crate_version": package.version, @@ -425,7 +442,9 @@ def spec_render_project( rpm_buildrequires = list(sorted(buildrequires)) rpm_test_requires = list(sorted(test_requires)) - rust_packaging_dep = RUST_PACKAGING_DEPS[min_rust_packaging_dep(package, target, is_bin, is_cdylib, vendor_tarball)] + rust_packaging_dep = RUST_PACKAGING_DEPS[ + min_rust_packaging_dep(package, target, is_bin, is_cdylib, vendor_tarball, False, True) + ] if feature_flags.all_features or tomlconf.features_enable_all: cargo_args = " -a" @@ -600,7 +619,9 @@ def spec_render_workspace( ( 24, max( - min_rust_packaging_dep(package, target, package.is_bin(), package.is_cdylib(), vendor_tarball) + min_rust_packaging_dep( + package, target, package.is_bin(), package.is_cdylib(), vendor_tarball, True, True + ) for package in metadata.packages ), ) diff --git a/rust2rpm/templates/README.md b/rust2rpm/templates/README.md index 1c37a7a..2a40b75 100644 --- a/rust2rpm/templates/README.md +++ b/rust2rpm/templates/README.md @@ -41,6 +41,8 @@ | `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 | +| `cargo_install_lib` | `bool` | prevent installation of library sources if `False` (default: `True`) | +| `cargo_install_bin` | `bool` | prevent installation of binary targets if `False` (default: `True`) | ### Parameters for crate metadata diff --git a/rust2rpm/templates/crate.spec b/rust2rpm/templates/crate.spec index bb90df1..8f5f9da 100644 --- a/rust2rpm/templates/crate.spec +++ b/rust2rpm/templates/crate.spec @@ -14,9 +14,14 @@ %global debug_package %{nil} {% endif %} -{% if use_vendor_tarball %} +{% if not cargo_install_lib %} # prevent library files from being installed -%global __cargo_is_lib() 0 +%global cargo_install_lib 0 + +{% endif %} +{% if not cargo_install_bin %} +# prevent executables from being installed +%global cargo_install_bin 0 {% endif %} %global crate {{ crate_name }} @@ -113,7 +118,7 @@ BuildRequires: {{ req }} %description %{_description} -{% if rpm_binary_package or rpm_cdylib_package %} +{% if (rpm_binary_package or rpm_cdylib_package) and cargo_install_bin %} %package -n {{ rpm_binary_package_name }} Summary: %{summary} {% if rpm_group is defined %} @@ -149,7 +154,7 @@ Requires: {{ req }} {% endif -%} -{% if rpm_library_package and not use_vendor_tarball %} +{% if rpm_library_package and cargo_install_lib %} {% for feature in crate_features %} {% if feature is none %} {% set pkg = " devel" %} diff --git a/rust2rpm/templates/project.spec b/rust2rpm/templates/project.spec index dcca2eb..4a3e064 100644 --- a/rust2rpm/templates/project.spec +++ b/rust2rpm/templates/project.spec @@ -12,7 +12,7 @@ {% endif %} # prevent library files from being installed -%global __cargo_is_lib() 0 +%global cargo_install_lib 0 %global crate {{ crate_name }} {% if crate_version != rpm_version %} 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 cb33e08..e9af7d0 100644 --- a/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.fedora.spec +++ b/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.fedora.spec @@ -2,7 +2,7 @@ %bcond_without check # prevent library files from being installed -%global __cargo_is_lib() 0 +%global cargo_install_lib 0 %global crate rust2rpm-helper @@ -23,7 +23,7 @@ Patch: rust2rpm-helper-patch1.diff # Manually created patch for downstream crate metadata changes Patch: rust2rpm-helper-patch2.diff -BuildRequires: cargo-rpm-macros >= 24 +BuildRequires: cargo-rpm-macros >= 26 %global _description %{expand: Helper program for rust2rpm.} diff --git a/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.mageia.spec b/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.mageia.spec index 473bfd8..05c5139 100644 --- a/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.mageia.spec +++ b/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.mageia.spec @@ -2,7 +2,7 @@ %bcond_without check # prevent library files from being installed -%global __cargo_is_lib() 0 +%global cargo_install_lib 0 %global crate rust2rpm-helper @@ -26,7 +26,7 @@ Patch: rust2rpm-helper-patch2.diff ExclusiveArch: %{rust_arches} -BuildRequires: rust-packaging >= 23 +BuildRequires: cargo-rpm-macros >= 26 BuildRequires: (crate(anyhow/default) >= 1.0.0 with crate(anyhow/default) < 2.0.0~) BuildRequires: (crate(cfg-expr/default) >= 0.15.0 with crate(cfg-expr/default) < 0.16.0~) BuildRequires: (crate(clap/default) >= 4.0.0 with crate(clap/default) < 5.0.0~) diff --git a/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.opensuse.spec b/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.opensuse.spec index d67762d..e7a281c 100644 --- a/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.opensuse.spec +++ b/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.opensuse.spec @@ -19,7 +19,7 @@ %bcond_without check # prevent library files from being installed -%global __cargo_is_lib() 0 +%global cargo_install_lib 0 %global crate rust2rpm-helper @@ -43,7 +43,7 @@ Patch: rust2rpm-helper-patch2.diff ExclusiveArch: %{rust_arches} -BuildRequires: rust-packaging >= 23 +BuildRequires: cargo-rpm-macros >= 26 BuildRequires: (crate(anyhow/default) >= 1.0.0 with crate(anyhow/default) < 2.0.0~) BuildRequires: (crate(cfg-expr/default) >= 0.15.0 with crate(cfg-expr/default) < 0.16.0~) BuildRequires: (crate(clap/default) >= 4.0.0 with crate(clap/default) < 5.0.0~) diff --git a/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.plain.spec b/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.plain.spec index 47b289b..ca4070a 100644 --- a/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.plain.spec +++ b/rust2rpm/tests/samples/rust2rpm-helper-0.1.3.plain.spec @@ -2,7 +2,7 @@ %bcond_without check # prevent library files from being installed -%global __cargo_is_lib() 0 +%global cargo_install_lib 0 %global crate rust2rpm-helper @@ -25,7 +25,7 @@ Patch: rust2rpm-helper-patch2.diff ExclusiveArch: %{rust_arches} -BuildRequires: rust-packaging >= 23 +BuildRequires: cargo-rpm-macros >= 26 BuildRequires: (crate(anyhow/default) >= 1.0.0 with crate(anyhow/default) < 2.0.0~) BuildRequires: (crate(cfg-expr/default) >= 0.15.0 with crate(cfg-expr/default) < 0.16.0~) BuildRequires: (crate(clap/default) >= 4.0.0 with crate(clap/default) < 5.0.0~) diff --git a/rust2rpm/tests/samples/stgit-2.3.3.fedora.spec b/rust2rpm/tests/samples/stgit-2.3.3.fedora.spec index 934dc1c..2f92b50 100644 --- a/rust2rpm/tests/samples/stgit-2.3.3.fedora.spec +++ b/rust2rpm/tests/samples/stgit-2.3.3.fedora.spec @@ -2,7 +2,7 @@ %bcond_without check # prevent library files from being installed -%global __cargo_is_lib() 0 +%global cargo_install_lib 0 %global crate stgit @@ -24,7 +24,7 @@ Patch: stgit-patch1.diff # Manually created patch for downstream crate metadata changes Patch: stgit-patch2.diff -BuildRequires: cargo-rpm-macros >= 25 +BuildRequires: cargo-rpm-macros >= 26 %global _description %{expand: Stack-based patch management for Git.} diff --git a/rust2rpm/tests/samples/stgit-2.3.3.mageia.spec b/rust2rpm/tests/samples/stgit-2.3.3.mageia.spec index b3a2299..8a1f822 100644 --- a/rust2rpm/tests/samples/stgit-2.3.3.mageia.spec +++ b/rust2rpm/tests/samples/stgit-2.3.3.mageia.spec @@ -2,7 +2,7 @@ %bcond_without check # prevent library files from being installed -%global __cargo_is_lib() 0 +%global cargo_install_lib 0 %global crate stgit @@ -28,7 +28,7 @@ Patch: stgit-patch2.diff ExclusiveArch: %{rust_arches} -BuildRequires: cargo-rpm-macros >= 25 +BuildRequires: cargo-rpm-macros >= 26 %global _description %{expand: Stack-based patch management for Git.} diff --git a/rust2rpm/tests/samples/stgit-2.3.3.opensuse.spec b/rust2rpm/tests/samples/stgit-2.3.3.opensuse.spec index 2ed43ad..e67c536 100644 --- a/rust2rpm/tests/samples/stgit-2.3.3.opensuse.spec +++ b/rust2rpm/tests/samples/stgit-2.3.3.opensuse.spec @@ -19,7 +19,7 @@ %bcond_without check # prevent library files from being installed -%global __cargo_is_lib() 0 +%global cargo_install_lib 0 %global crate stgit @@ -44,7 +44,7 @@ Patch: stgit-patch2.diff ExclusiveArch: %{rust_arches} -BuildRequires: cargo-rpm-macros >= 25 +BuildRequires: cargo-rpm-macros >= 26 %global _description %{expand: Stack-based patch management for Git.} diff --git a/rust2rpm/tests/samples/stgit-2.3.3.plain.spec b/rust2rpm/tests/samples/stgit-2.3.3.plain.spec index 5db3674..c24e150 100644 --- a/rust2rpm/tests/samples/stgit-2.3.3.plain.spec +++ b/rust2rpm/tests/samples/stgit-2.3.3.plain.spec @@ -2,7 +2,7 @@ %bcond_without check # prevent library files from being installed -%global __cargo_is_lib() 0 +%global cargo_install_lib 0 %global crate stgit @@ -26,7 +26,7 @@ Patch: stgit-patch2.diff ExclusiveArch: %{rust_arches} -BuildRequires: cargo-rpm-macros >= 25 +BuildRequires: cargo-rpm-macros >= 26 %global _description %{expand: Stack-based patch management for Git.} diff --git a/rust2rpm/tests/test_generator.py b/rust2rpm/tests/test_generator.py index 19ff236..ffa5c1c 100644 --- a/rust2rpm/tests/test_generator.py +++ b/rust2rpm/tests/test_generator.py @@ -60,6 +60,7 @@ def test_spec_file_render_crate(filename: str, conf: Optional[str], target: str) upstream_version=version, metadata=metadata, rpm_name=rpm_name, + compat=False, patch_file_automatic=f"{crate}-patch1.diff", patch_file_manual=f"{crate}-patch2.diff", license_files=["LIC1", "LIC2"],