| |
@@ -6,21 +6,69 @@
|
| |
import sys
|
| |
|
| |
import jinja2
|
| |
+ import jinja2.ext
|
| |
+ import jinja2.exceptions
|
| |
import requests
|
| |
import tqdm
|
| |
|
| |
from rust2rpm import Metadata
|
| |
|
| |
+ # See: http://jinja.pocoo.org/docs/latest/extensions/#example-extension
|
| |
+ class RaiseExtension(jinja2.ext.Extension):
|
| |
+ # a set of names that trigger the extension.
|
| |
+ tags = set(["raise"])
|
| |
+
|
| |
+ def parse(self, parser):
|
| |
+ # the first token is the token that started the tag. In our case
|
| |
+ # we only listen to ``'raise'`` so this will be a name token with
|
| |
+ # `raise` as value. We get the line number so that we can give
|
| |
+ # that line number to the nodes we create by hand.
|
| |
+ lineno = next(parser.stream).lineno
|
| |
+
|
| |
+ # Extract the message from the template
|
| |
+ message_node = parser.parse_expression()
|
| |
+
|
| |
+ return jinja2.nodes.CallBlock(
|
| |
+ self.call_method("_raise", [message_node], lineno=lineno),
|
| |
+ [], [], [], lineno=lineno)
|
| |
+
|
| |
+ def _raise(self, msg, caller):
|
| |
+ raise jinja2.exceptions.TemplateRuntimeError(msg)
|
| |
+
|
| |
XDG_CACHE_HOME = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache"))
|
| |
CACHEDIR = os.path.join(XDG_CACHE_HOME, "rust2rpm")
|
| |
API_URL = "https://crates.io/api/v1/"
|
| |
TEMPLATE = """# Generated by rust2rpm
|
| |
+ {% set bins = md.targets|selectattr("kind", "equalto", "bin")|list() %}
|
| |
+ {% set libs = md.targets|selectattr("kind", "equalto", "lib")|list() %}
|
| |
+ {% set is_bin = bins|length > 0 %}
|
| |
+ {% set is_lib = libs|length > 0 %}
|
| |
+ {% if is_bin and not is_lib %}
|
| |
+ {% set include_debug = True %}
|
| |
+ {% set name = "%{crate}" %}
|
| |
+ {% set include_main = True %}
|
| |
+ {% set name_devel = None %}
|
| |
+ {% elif is_lib and not is_bin %}
|
| |
+ {% set include_debug = False %}
|
| |
+ {% set name = "rust-%{crate}" %}
|
| |
+ {% set include_main = False %}
|
| |
+ {% set name_devel = " devel" %}
|
| |
+ {% elif is_bin and is_lib %}
|
| |
+ {% set include_debug = True %}
|
| |
+ {% set name = "%{crate}" %}
|
| |
+ {% set include_main = True %}
|
| |
+ {% set name_devel = "-n rust-%{crate}-devel" %}
|
| |
+ {% else %}
|
| |
+ {% raise "No bins and no libs" %}
|
| |
+ {% endif %}
|
| |
%bcond_without check
|
| |
+ {% if not include_debug %}
|
| |
%global debug_package %{nil}
|
| |
+ {% endif %}
|
| |
|
| |
%global crate {{ md.name }}
|
| |
|
| |
- Name: rust-%{crate}
|
| |
+ Name: {{ name }}
|
| |
Version: {{ md.version }}
|
| |
Release: 1%{?dist}
|
| |
Summary: # FIXME
|
| |
@@ -53,7 +101,8 @@
|
| |
%description
|
| |
%{summary}.
|
| |
|
| |
- %package devel
|
| |
+ {% if name_devel is not none %}
|
| |
+ %package {{ name_devel }}
|
| |
Summary: %{summary}
|
| |
BuildArch: noarch
|
| |
{% if target == "epel-7" %}
|
| |
@@ -68,9 +117,10 @@
|
| |
{% endfor %}
|
| |
{% endif %}
|
| |
|
| |
- %description devel
|
| |
+ %description {{ name_devel }}
|
| |
%{summary}.
|
| |
|
| |
+ {% endif %}
|
| |
%prep
|
| |
%autosetup -n %{crate}-%{version}
|
| |
%cargo_prep
|
| |
@@ -86,15 +136,25 @@
|
| |
%cargo_test
|
| |
%endif
|
| |
|
| |
- %files devel
|
| |
+ {% if include_main %}
|
| |
+ %files
|
| |
+ {% for bin in bins %}
|
| |
+ %{_bindir}/{{ bin.name }}
|
| |
+ {% endfor %}
|
| |
+
|
| |
+ {% endif %}
|
| |
+ {% if name_devel is not none %}
|
| |
+ %files {{ name_devel }}
|
| |
{% if md.license_file is not none %}
|
| |
%license {{ md.license_file }}
|
| |
{% endif %}
|
| |
%{cargo_registry}/%{crate}-%{version}/
|
| |
|
| |
+ {% endif %}
|
| |
%changelog
|
| |
"""
|
| |
JINJA_ENV = jinja2.Environment(undefined=jinja2.StrictUndefined,
|
| |
+ extensions=[RaiseExtension],
|
| |
trim_blocks=True, lstrip_blocks=True)
|
| |
|
| |
def main():
|
| |
Signed-off-by: Igor Gnatenko ignatenkobrain@fedoraproject.org