conf/generator/templates: support cargo-install-{lib,bin} settings
rust-packaging >= 26 now has "official" support for overriding the installation of library sources / binary targets by setting RPM macros. This commit adds settings to correspond to the %cargo_install_lib and %cargo_install_bin macros and plugs them through to the spec generator. References to the the private %__cargo_is_bin and %__cargo_is_lib macros, which could previously be used to hack this behaviour, were removed.
This commit is contained in:
parent
1b1532da08
commit
139bac2eca
17 changed files with 93 additions and 26 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
),
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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" %}
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -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.}
|
||||
|
|
|
@ -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~)
|
||||
|
|
|
@ -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~)
|
||||
|
|
|
@ -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~)
|
||||
|
|
|
@ -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.}
|
||||
|
|
|
@ -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.}
|
||||
|
|
|
@ -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.}
|
||||
|
|
|
@ -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.}
|
||||
|
|
|
@ -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"],
|
||||
|
|
Loading…
Reference in a new issue