conf/template: support specifying supported architectures
This commit is contained in:
parent
6f40c1a026
commit
267d9fbef9
7 changed files with 48 additions and 27 deletions
|
@ -5,10 +5,13 @@ from typing import Optional
|
|||
from rust2rpm import log
|
||||
|
||||
|
||||
def to_list(s):
|
||||
def to_list(s, sort=True):
|
||||
if not s:
|
||||
return []
|
||||
return list(sorted(filter(None, (l.strip() for l in s.splitlines()))))
|
||||
if sort:
|
||||
return list(sorted(filter(None, (l.strip() for l in s.splitlines()))))
|
||||
else:
|
||||
return list(filter(None, (l.strip() for l in s.splitlines())))
|
||||
|
||||
|
||||
class Rust2RpmConfError(ValueError):
|
||||
|
@ -19,6 +22,7 @@ class Rust2RpmConf:
|
|||
def __init__(
|
||||
self,
|
||||
*,
|
||||
supported_arches: list[str] = None,
|
||||
all_features: bool = False,
|
||||
unwanted_features: list[str] = None,
|
||||
enabled_features: list[str] = None,
|
||||
|
@ -27,6 +31,7 @@ class Rust2RpmConf:
|
|||
bin_requires: list[str] = None,
|
||||
lib_requires: dict[Optional[str], list[str]] = None,
|
||||
):
|
||||
self.supported_arches: list[str] = supported_arches or list()
|
||||
self.all_features: bool = all_features
|
||||
self.unwanted_features: list[str] = unwanted_features or list()
|
||||
self.enabled_features: list[str] = enabled_features or list()
|
||||
|
@ -42,7 +47,8 @@ class Rust2RpmConf:
|
|||
# order of items in the list is consistent:
|
||||
# lists are sorted when parsing rust2rpm.conf files
|
||||
return (
|
||||
self.all_features == other.all_features
|
||||
self.supported_arches == other.supported_arches
|
||||
and self.all_features == other.all_features
|
||||
and self.unwanted_features == other.unwanted_features
|
||||
and self.enabled_features == other.enabled_features
|
||||
and self.buildrequires == other.buildrequires
|
||||
|
@ -76,6 +82,7 @@ class Rust2RpmConf:
|
|||
# validate configuration file
|
||||
valid_targets = ["fedora", "mageia", "opensuse", "plain"]
|
||||
valid_keys = [
|
||||
"supported-arches",
|
||||
"all-features",
|
||||
"unwanted-features",
|
||||
"enabled-features",
|
||||
|
@ -100,6 +107,9 @@ class Rust2RpmConf:
|
|||
# parse configuration and validate settings
|
||||
settings = dict()
|
||||
|
||||
if supported_arches := merged.get("supported-arches"):
|
||||
settings["supported_arches"] = to_list(supported_arches, False)
|
||||
|
||||
all_features = merged.getboolean("all-features")
|
||||
if all_features is not None:
|
||||
settings["all_features"] = all_features
|
||||
|
|
|
@ -15,12 +15,6 @@ from rust2rpm.licensing import translate_license
|
|||
from rust2rpm.metadata import package_uses_rust_1_60_feature_syntax, get_required_features_for_binaries
|
||||
|
||||
|
||||
def to_list(s):
|
||||
if not s:
|
||||
return []
|
||||
return list(filter(None, (l.strip() for l in s.splitlines())))
|
||||
|
||||
|
||||
def spec_file_template(filename: str):
|
||||
env = jinja2.Environment(
|
||||
loader=jinja2.ChoiceLoader([jinja2.FileSystemLoader(["/"]), jinja2.PackageLoader("rust2rpm", "templates")]),
|
||||
|
@ -29,8 +23,6 @@ def spec_file_template(filename: str):
|
|||
lstrip_blocks=True,
|
||||
)
|
||||
|
||||
env.globals["to_list"] = to_list
|
||||
|
||||
return env.get_template(filename)
|
||||
|
||||
|
||||
|
@ -220,6 +212,7 @@ def spec_render_crate(
|
|||
"conf_test_requires": distconf.testrequires,
|
||||
"conf_bin_requires": distconf.bin_requires,
|
||||
"conf_lib_requires": conf_lib_requires,
|
||||
"conf_supported_arches": " ".join(distconf.supported_arches),
|
||||
# Parameters derived from command-line flags
|
||||
"cargo_args": cargo_args,
|
||||
"use_relative_license_paths": relative_license_paths,
|
||||
|
|
|
@ -49,12 +49,13 @@
|
|||
|
||||
### Parameters derived from rust2rpm.conf
|
||||
|
||||
| parameter name | type | value |
|
||||
| -------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `conf_buildrequires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.conf` |
|
||||
| `conf_test_requires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.conf` that are gated by an `%if %{with check}` conditional |
|
||||
| `conf_bin_requires` | `list[str]` | list of additional RPM `Requires` for the binary package specified in `rust2rpm.conf` |
|
||||
| `conf_lib_requires` | `dict[str, list[str]]` | map of feature names to lists of additional RPM `Requires` for library packages specified in `rust2rpm.conf` |
|
||||
| parameter name | type | value |
|
||||
| ----------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `conf_buildrequires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.conf` |
|
||||
| `conf_test_requires` | `list[str]` | list of additional RPM `BuildRequires` specified in `rust2rpm.conf` that are gated by an `%if %{with check}` conditional |
|
||||
| `conf_bin_requires` | `list[str]` | list of additional RPM `Requires` for the binary package specified in `rust2rpm.conf` |
|
||||
| `conf_lib_requires` | `dict[str, list[str]]` | map of feature names to lists of additional RPM `Requires` for library packages specified in `rust2rpm.conf` |
|
||||
| `conf_supported_arches` | `list[str]` | list of supported architectures (results in `%ifarch` conditionals around `%cargo_build` and `%cargo_test` macros) |
|
||||
|
||||
### Parameters derived from command-line flags
|
||||
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
{% if crate_version != rpm_version %}
|
||||
%global crate_version {{ crate_version }}
|
||||
{% endif %}
|
||||
{% if conf_supported_arches %}
|
||||
|
||||
# compile and run tests only on supported architectures
|
||||
%global supported_arches {{ conf_supported_arches }}
|
||||
{% endif %}
|
||||
|
||||
Name: {{ rpm_name }}
|
||||
Version: {{ rpm_version }}
|
||||
|
@ -196,7 +201,13 @@ echo {{ "%r" | format(req) }}
|
|||
{% endif -%}
|
||||
|
||||
%build
|
||||
{% if conf_supported_arches %}
|
||||
%ifarch %{supported_arches}
|
||||
{% endif %}
|
||||
%cargo_build{{ cargo_args }}
|
||||
{% if conf_supported_arches %}
|
||||
%endif
|
||||
{% endif %}
|
||||
|
||||
%install
|
||||
{% if rpm_cdylib_package and (rpm_library_package or rpm_binary_package) %}
|
||||
|
@ -209,8 +220,14 @@ echo {{ "%r" | format(req) }}
|
|||
{% endif %}
|
||||
|
||||
%if %{with check}
|
||||
{% if conf_supported_arches %}
|
||||
%ifarch %{supported_arches}
|
||||
{% endif %}
|
||||
%check
|
||||
%cargo_test{{ cargo_args }}
|
||||
{% if conf_supported_arches %}
|
||||
%endif
|
||||
{% endif %}
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import Optional
|
|||
|
||||
import pytest
|
||||
|
||||
from rust2rpm.conf import Rust2RpmConf
|
||||
from rust2rpm.conf import Rust2RpmConf, to_list
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -57,3 +57,10 @@ def test_rust2rpm_conf_load(
|
|||
path = str(resources.files("rust2rpm.tests.samples").joinpath(filename))
|
||||
conf = Rust2RpmConf.load(path, "fedora", features)
|
||||
assert conf == expected
|
||||
|
||||
|
||||
def test_to_list():
|
||||
assert to_list("1\n2") == ["1", "2"]
|
||||
assert to_list("1\n\n 2") == ["1", "2"]
|
||||
assert to_list(" 2 ") == ["2"]
|
||||
assert to_list("\n\n") == []
|
||||
|
|
|
@ -8,19 +8,12 @@ import pytest
|
|||
|
||||
from rust2rpm.cli import get_parser
|
||||
from rust2rpm.conf import Rust2RpmConf
|
||||
from rust2rpm.generator import to_list, spec_render_crate, spec_render_workspace
|
||||
from rust2rpm.generator import spec_render_crate, spec_render_workspace
|
||||
from rust2rpm.metadata import guess_main_package
|
||||
from rust2rpm.patching import drop_foreign_dependencies
|
||||
from rust2rpm.utils import package_name_suffixed
|
||||
|
||||
|
||||
def test_to_list():
|
||||
assert to_list("1\n2") == ["1", "2"]
|
||||
assert to_list("1\n\n 2") == ["1", "2"]
|
||||
assert to_list(" 2 ") == ["2"]
|
||||
assert to_list("\n\n") == []
|
||||
|
||||
|
||||
# How to add new tests samples:
|
||||
# - find an interesting crate
|
||||
# - copy unpatched Cargo.toml to rust2rpm/test/samples/<name>-<version>.toml
|
||||
|
|
2
tox.ini
2
tox.ini
|
@ -9,7 +9,7 @@ deps =
|
|||
whitelist_externals =
|
||||
cargo
|
||||
commands =
|
||||
pytest -v
|
||||
pytest -v {posargs}
|
||||
setenv =
|
||||
PYTHONPATH = {toxinidir}
|
||||
|
||||
|
|
Loading…
Reference in a new issue