cli/generator: add "legacy" mode to support older RPM versions

Currently, this prevents generating spec files with the "SourceLicense"
tag, which was only implemented in RPM 4.18. This is not supported when
targeting RHEL / EPEL 9, which is on RPM 4.16.
This commit is contained in:
Fabio Valentini 2024-03-11 23:07:59 +01:00
parent 25bf9c165f
commit b145e4832b
No known key found for this signature in database
GPG key ID: 5AC5F572E5D410AF
7 changed files with 39 additions and 0 deletions

View file

@ -1,3 +1,16 @@
Unreleased
==========
Added:
- Support for generating spec files that target distributions with older
versions of RPM was implemented. Currently, the only difference between
"normal" and "legacy" mode is whether the `SourceLicense` tag is present in
generated spec files. Support for this tag was added in RPM 4.18, but RHEL 9
is currently on RPM 4.16. In "legacy" mode (i.e. when targeting EPEL 9), the
`SourceLicense` tag in generated spec files is replaced with a comment. To
enable "legacy" mode, pass the new `--legacy` flag on the CLI.
Version 26.0.0
==============

View file

@ -199,6 +199,7 @@ def main():
main_package=main_package,
upstream_version=version,
target=args.target,
legacy=args.legacy,
rpm_name=rpm_name,
license_files=license_files,
doc_files=doc_files,
@ -231,6 +232,7 @@ def main():
metadata=metadata,
upstream_version=version,
target=args.target,
legacy=args.legacy,
rpm_name=rpm_name,
patch_file_automatic=patch_files[0],
patch_file_manual=patch_files[1],
@ -270,6 +272,7 @@ def main():
metadata=metadata,
upstream_version=version,
target=args.target,
legacy=args.legacy,
rpm_name=rpm_name,
compat=args.compat,
patch_file_automatic=patch_files[0],

View file

@ -102,6 +102,12 @@ def get_parser() -> argparse.ArgumentParser:
action="store_true",
help="Create a vendor tarball and write a spec for building with vendored dependencies",
)
parser.add_argument(
"-l",
"--legacy",
action="store_true",
help="Generate a spec file that is compatible with older versions of RPM",
)
parser.add_argument(
"crate",
help="crates.io name\n" "path/to/local.crate\n" "path/to/project/",

View file

@ -178,6 +178,7 @@ def spec_render_crate(
metadata: Metadata,
upstream_version: str,
target: str,
legacy: bool,
rpm_name: str,
compat: bool,
patch_file_automatic: Optional[str],
@ -331,6 +332,7 @@ def spec_render_crate(
# Parameters specific to rust2rpm
"rust2rpm_version": generator_version,
"rust2rpm_target": target,
"rust2rpm_legacy": legacy,
"rust_packaging_dep": rust_packaging_dep,
# Parameters for RPM package metadata
"rpm_name": rpm_name,
@ -424,6 +426,7 @@ def spec_render_project(
metadata: Metadata,
upstream_version: str,
target: str,
legacy: bool,
rpm_name: str,
patch_file_automatic: Optional[str],
patch_file_manual: Optional[str],
@ -535,6 +538,7 @@ def spec_render_project(
# Parameters specific to rust2rpm
"rust2rpm_version": generator_version,
"rust2rpm_target": target,
"rust2rpm_legacy": legacy,
"rust_packaging_dep": rust_packaging_dep,
# Parameters for RPM package metadata
"rpm_name": rpm_name,
@ -621,6 +625,7 @@ def spec_render_workspace(
main_package: Package,
upstream_version: str,
target: str,
legacy: bool,
rpm_name: str,
license_files: list[str],
doc_files: list[str],
@ -728,6 +733,7 @@ def spec_render_workspace(
# Parameters specific to rust2rpm
"rust2rpm_version": generator_version,
"rust2rpm_target": target,
"rust2rpm_legacy": legacy,
"rust_packaging_dep": rust_packaging_dep,
# Parameters for RPM package metadata
"rpm_name": rpm_name,

View file

@ -33,7 +33,11 @@ Group: {{ rpm_group }}
{% if crate_license != rpm_license %}
# Upstream license specification: {{ crate_license|default("(missing)") }}
{% endif %}
{% if rust2rpm_legacy %}
# Source License: {{ rpm_license|default("# FIXME") }}
{% else %}
SourceLicense: {{ rpm_license|default("# FIXME") }}
{% endif %}
# FIXME: paste output of %%cargo_license_summary here
License: # FIXME
# LICENSE.dependencies contains a full license breakdown

View file

@ -22,7 +22,11 @@ Summary: {{ rpm_summary }}
Group: {{ rpm_group }}
{% endif %}
{% if rust2rpm_legacy %}
# Source License: {{ rpm_license|default("# FIXME") }}
{% else %}
SourceLicense: {{ rpm_license|default("# FIXME") }}
{% endif %}
# FIXME: paste output of %%cargo_license_summary here
License: # FIXME
# LICENSE.dependencies contains a full license breakdown

View file

@ -54,6 +54,7 @@ def test_spec_file_render_crate(filename: str, conf: Optional[str], target: str)
rendered = spec_render_crate(
target=target,
legacy=False,
upstream_version=version,
metadata=metadata,
rpm_name=rpm_name,
@ -108,6 +109,7 @@ def test_spec_file_render_project(filename: str, vendor_tarball: Optional[str],
rendered = spec_render_project(
target=target,
legacy=False,
upstream_version=version,
metadata=metadata,
rpm_name=crate,
@ -162,6 +164,7 @@ def test_spec_file_render_workspace(filename: str, vendor_tarball: Optional[str]
main_package=guess_main_package(metadata),
upstream_version=version,
target=target,
legacy=False,
rpm_name=crate,
license_files=["LIC1", "LIC2"],
doc_files=["DOC1", "DOC2"],