use Metadata directly instead of calling subprocess

Subprocesses are slow and we have to pass too many different parameters
for rendering. It's better to pass just metadata object and use Python
interface.

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
This commit is contained in:
Igor Gnatenko 2017-02-03 10:39:37 +01:00
parent 3c354a3b91
commit 38ca0bf280

View file

@ -14,34 +14,34 @@ API_URL = "https://crates.io/api/v1/"
TEMPLATE = """# Generated by rust2rpm
%bcond_without check
%global crate {{ name }}
%global crate {{ md.name }}
Name: rust-%{crate}
Version: {{ version }}
Version: {{ md.version }}
Release: 1%{?dist}
Summary: # FIXME
License: # FIXME
URL: https://crates.io/crates/{{ name }}
URL: https://crates.io/crates/{{ md.name }}
Source0: https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{crate}-%{version}.crate
ExclusiveArch: %{rust_arches}
BuildRequires: rust
BuildRequires: cargo
{% for br in buildrequires %}
BuildRequires: {{ br }}
{% for req in md.build_requires %}
BuildRequires: {{ req }}
{% endfor %}
{% for bc in buildconflicts %}
BuildConflicts: {{ bc }}
{% for con in md.build_conflicts %}
BuildConflicts: {{ con }}
{% endfor %}
{% if testrequires|length > 0 %}
{% if md.test_requires|length > 0 %}
%if %{with check}
{% for tr in testrequires %}
BuildRequires: {{ tr }}
{% for req in md.test_requires %}
BuildRequires: {{ req }}
{% endfor %}
{% for tc in testconflicts %}
BuildConflicts: {{ tc }}
{% for con in md.test_conflicts %}
BuildConflicts: {{ con }}
{% endfor %}
%endif
{% endif %}
@ -52,15 +52,17 @@ BuildConflicts: {{ tc }}
%package devel
Summary: %{summary}
BuildArch: noarch
{% for prov in provides %}
Provides: {{ prov }}
{% if target == "epel-7" %}
{% for prv in md.provides %}
Provides: {{ prv }}
{% endfor %}
{% for req in requires %}
{% for req in md.requires %}
Requires: {{ req }}
{% endfor %}
{% for con in conflicts %}
{% for con in md.conflicts %}
Conflicts: {{ con }}
{% endfor %}
{% endif %}
%description devel
%{summary}.
@ -128,23 +130,7 @@ if __name__ == "__main__":
toml = "{}/{}-{}/Cargo.toml".format(tmpdir, args.crate, args.version)
assert os.path.isfile(toml)
buildrequires = run_depgen("--build-requires", toml)
buildconflicts = run_depgen("--build-conflicts", toml)
testrequires = run_depgen("--test-requires", toml)
testconflicts = run_depgen("--test-conflicts", toml)
if args.target == "fedora-26":
# Those are automatically added by dependency generator
provides = []
requires = []
conflicts = []
else:
provides = run_depgen("--provides", toml)
requires = run_depgen("--requires", toml)
conflicts = run_depgen("--conflicts", toml)
metadata = cargodeps.Metadata.from_file(toml)
template = JINJA_ENV.from_string(TEMPLATE)
print(template.render(name=args.crate, version=args.version,
provides=provides,
buildrequires=buildrequires, buildconflicts=buildconflicts,
testrequires=testrequires, testconflicts=testconflicts,
requires=requires, conflicts=conflicts))
print(template.render(target=args.target, md=metadata))