From 1f8a8e7f4b407dd9308cbd96ac847a471c8bdf02 Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Sat, 30 Mar 2024 18:50:43 +0100 Subject: [PATCH] conf: add settings for package URL and package Source These settings are only valid for non-crate or workspace projects. For crates published on crates.io, both URL and Source0 have values that can be derived from the crate name. --- docs/rust2rpm.toml.5.asciidoc | 14 ++++++++++++++ rust2rpm/__main__.py | 14 ++++++++++++++ rust2rpm/conf.py | 22 ++++++++++++++++++++++ rust2rpm/generator.py | 5 ++++- rust2rpm/templates/README.md | 7 +++++-- rust2rpm/templates/project.spec | 4 +--- rust2rpm/templates/workspace.spec | 4 ++-- 7 files changed, 62 insertions(+), 8 deletions(-) diff --git a/docs/rust2rpm.toml.5.asciidoc b/docs/rust2rpm.toml.5.asciidoc index 732bf7d..777ca42 100644 --- a/docs/rust2rpm.toml.5.asciidoc +++ b/docs/rust2rpm.toml.5.asciidoc @@ -34,6 +34,20 @@ This table contains settings that affect RPM metadata. TOML string (for longer / multi-line descriptions, triple-quoted multi-line strings can be used). +*url*:: + This setting allows specifying the homepage of the packaged project which is + used as the value of the "URL" tag in the generated spec file. This setting is + only valid for non-crate and workspace projects and can be used when the + upstream project does not specify a homepage or repository URL in its + metadata. + +*source-url*:: + This setting allows specifying the download URL for the source code of the + packaged project. It is used as the value of the "Source" tag in the generated + spec file. This setting is only valid for non-crate and workspace projects and + can be used for persisting the download URL which cannot be known in advance + for non-crate and workspace projects. + *supported-arches*:: This setting can be used to specify that the crate only has support for limited architectures (i.e. not all CPU architectures that are supported by diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py index eaf2a83..d1f57d6 100644 --- a/rust2rpm/__main__.py +++ b/rust2rpm/__main__.py @@ -265,6 +265,20 @@ def main(): ) sys.exit(1) + if tomlconf.package_url: + log.error( + "The rust2rpm.toml configuration file specifies an override for the package URL, " + "but this is not valid for crates packaged from crates.io." + ) + sys.exit(1) + + if tomlconf.package_source_url: + log.error( + "The rust2rpm.toml configuration file specifies an override for the Source URL, " + "but this is not valid for crates packaged from crates.io." + ) + sys.exit(1) + warn_if_package_uses_restrictive_dependencies(package) try: diff --git a/rust2rpm/conf.py b/rust2rpm/conf.py index a8eecb7..c13e730 100644 --- a/rust2rpm/conf.py +++ b/rust2rpm/conf.py @@ -26,6 +26,14 @@ TOML_SCHEMA = { "description": { "type": "string", }, + # override package project URL + "url": { + "type": "string", + }, + # override package source URL + "source-url": { + "type": "string", + }, # supported target architectures "supported-arches": { "type": "array", @@ -560,6 +568,20 @@ class TomlConf: else: return None + @property + def package_url(self) -> Optional[str]: + if package := self._package: + return package.get("url") + else: + return None + + @property + def package_source_url(self) -> Optional[str]: + if package := self._package: + return package.get("source-url") + else: + return None + @property def package_supported_arches(self) -> Optional[list[str]]: if package := self._package: diff --git a/rust2rpm/generator.py b/rust2rpm/generator.py index a4d2dc7..91e2197 100644 --- a/rust2rpm/generator.py +++ b/rust2rpm/generator.py @@ -552,7 +552,8 @@ def spec_render_project( "rpm_version": Version.parse(package.version).to_rpm(), "rpm_summary": rpm_summary, "rpm_description": rpm_description, - "rpm_url": package.repository or package.homepage or "# FIXME", + "rpm_url": tomlconf.package_url or package.repository or package.homepage or "# FIXME", + "rpm_source_url": tomlconf.package_source_url or "# FIXME", "rpm_license": rpm_license, "rpm_license_comments": rpm_license_comments, "rpm_patch_file_automatic": patch_file_automatic, @@ -738,6 +739,8 @@ def spec_render_workspace( "rpm_version": rpm_version, "rpm_summary": rpm_summary, "rpm_description": rpm_description, + "rpm_url": tomlconf.package_url or "# FIXME", + "rpm_source_url": tomlconf.package_source_url or "# FIXME", "rpm_license": rpm_license_tag, "rpm_license_comments": rpm_license_comments, "rpm_buildrequires": rpm_buildrequires, diff --git a/rust2rpm/templates/README.md b/rust2rpm/templates/README.md index 61eab06..03c10e9 100644 --- a/rust2rpm/templates/README.md +++ b/rust2rpm/templates/README.md @@ -28,7 +28,7 @@ | `rpm_license_comments` | `Optional[str]` | additional information returned by license string translation | | `rpm_patch_file_automatic` | `Optional[str]` | name of the automatically generated patch file | | `rpm_patch_file_manual` | `Optional[str]` | name of the manually generated patch file | -| `rpm_patch_file_comments` | `list[str]` | additional lines of comments for the manually generated patch file | +| `rpm_patch_file_comments` | `list[str]` | additional lines of comments for the manually generated patch file | | `rpm_buildrequires` | `list[str]` | list of RPM `BuildRequires` | | `rpm_test_requires` | `list[str]` | list of RPM `BuildRequires` that are gated by an `%if %{with check}` conditional | | `rpm_requires` | `dict[str, list[str]]` | map of feature names to lists of RPM `Requires` for library sub-packages | @@ -135,11 +135,12 @@ | `rpm_summary` | `Optional[str]` | RPM package summary (derived from `package.description` value from `Cargo.toml`) | | `rpm_description` | `Optional[str]` | RPM package description (derived from `package.description` value from `Cargo.toml`) | | `rpm_url` | `Optional[str]` | URL for the crate (either homepage or repository URL) | +| `rpm_source_url` | `Optional[str]` | URL for the source of the project | | `rpm_license` | `Optional[str]` | RPM License tag (derived from `package.license` value from `Cargo.toml`) | | `rpm_license_comments` | `Optional[str]` | additional information returned by license string translation | | `rpm_patch_file_automatic` | `Optional[str]` | name of the automatically generated patch file | | `rpm_patch_file_manual` | `Optional[str]` | name of the manually generated patch file | -| `rpm_patch_file_comments` | `list[str]` | additional lines of comments for the manually generated patch file | +| `rpm_patch_file_comments` | `list[str]` | additional lines of comments for the manually generated patch file | | `rpm_buildrequires` | `list[str]` | list of RPM `BuildRequires` | | `rpm_test_requires` | `list[str]` | list of RPM `BuildRequires` that are gated by an `%if %{with check}` conditional | | `rpm_license_files` | `list[str]` | list of the license files which were detected in crate sources | @@ -233,6 +234,8 @@ | `rpm_version` | `str` | RPM package Version (translated to RPM format from SemVer) | | `rpm_summary` | `Optional[str]` | RPM package summary (derived from `package.description` value from `Cargo.toml`) | | `rpm_description` | `Optional[str]` | RPM package description (derived from `package.description` value from `Cargo.toml`) | +| `rpm_url` | `Optional[str]` | URL for the crate (either homepage or repository URL) | +| `rpm_source_url` | `Optional[str]` | URL for the source of the project | | `rpm_license` | `Optional[str]` | RPM License tag (derived from `package.license` value from `Cargo.toml`) | | `rpm_license_comments` | `Optional[str]` | additional information returned by license string translation | | `rpm_buildrequires` | `list[str]` | list of RPM `BuildRequires` | diff --git a/rust2rpm/templates/project.spec b/rust2rpm/templates/project.spec index f270450..322ad6f 100644 --- a/rust2rpm/templates/project.spec +++ b/rust2rpm/templates/project.spec @@ -49,10 +49,8 @@ License: # FIXME {{ rpm_license_comments }} {% endif %} -{% if rpm_url %} URL: {{ rpm_url }} -{% endif %} -Source: # FIXME +Source: {{ rpm_source_url }} {% if use_vendor_tarball %} Source: {{ rpm_vendor_source }} {% endif %} diff --git a/rust2rpm/templates/workspace.spec b/rust2rpm/templates/workspace.spec index c305c7c..c54aa2a 100644 --- a/rust2rpm/templates/workspace.spec +++ b/rust2rpm/templates/workspace.spec @@ -40,8 +40,8 @@ License: # FIXME {{ rpm_license_comments }} {% endif %} -URL: # FIXME -Source: # FIXME +URL: {{ rpm_url }} +Source: {{ rpm_source_url }} {% if use_vendor_tarball %} Source: {{ rpm_vendor_source }} {% endif %}