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.
This commit is contained in:
Fabio Valentini 2024-03-30 18:50:43 +01:00
parent 558784b035
commit 1f8a8e7f4b
No known key found for this signature in database
GPG key ID: 5AC5F572E5D410AF
7 changed files with 62 additions and 8 deletions

View file

@ -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

View file

@ -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:

View file

@ -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:

View file

@ -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,

View file

@ -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` |

View file

@ -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 %}

View file

@ -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 %}