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