add support for feeding user configuration

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
This commit is contained in:
Igor Gnatenko 2018-10-31 18:03:21 +01:00
parent a1d3a84645
commit 197150ee2e
No known key found for this signature in database
GPG key ID: 695714BD1BBC5F4C
4 changed files with 55 additions and 6 deletions

26
README.md Normal file
View file

@ -0,0 +1,26 @@
# rust2rpm
Convert Rust crates to RPM.
## `.rust2rpm.conf`
You can place configuration file which is used as source for additional
information for spec generation.
Some simple example would be better than many words ;)
```ini
[DEFAULT]
buildrequires =
pkgconfig(foo) >= 1.2.3
lib.requires =
pkgconfig(foo) >= 1.2.3
[fedora]
bin.requires =
findutils
buildrequires =
lib.requires =
lib+default.requires =
pkgconfig(bar) >= 2.0.0
```

View file

@ -1,5 +0,0 @@
========
rust2rpm
========
Convert Rust crates to RPM.

View file

@ -199,6 +199,11 @@ def make_diff_metadata(crate, version, patch=False, store=False):
shutil.copy2(cratef, os.path.join(os.getcwd(), f"{metadata.name}-{version}.crate")) shutil.copy2(cratef, os.path.join(os.getcwd(), f"{metadata.name}-{version}.crate"))
return crate, diff, metadata return crate, diff, metadata
def to_list(s):
if not s:
return []
return list(filter(None, (l.strip() for l in s.splitlines())))
def main(): def main():
parser = argparse.ArgumentParser("rust2rpm", parser = argparse.ArgumentParser("rust2rpm",
formatter_class=argparse.RawTextHelpFormatter) formatter_class=argparse.RawTextHelpFormatter)
@ -232,6 +237,7 @@ def main():
store=args.store_crate) store=args.store_crate)
JINJA_ENV.globals["normalize_deps"] = normalize_deps JINJA_ENV.globals["normalize_deps"] = normalize_deps
JINJA_ENV.globals["to_list"] = to_list
template = JINJA_ENV.get_template("main.spec") template = JINJA_ENV.get_template("main.spec")
if args.patch and len(diff) > 0: if args.patch and len(diff) > 0:
@ -287,6 +293,13 @@ def main():
kwargs["license"] = license kwargs["license"] = license
kwargs["license_comments"] = comments kwargs["license_comments"] = comments
conf = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
conf.read(".rust2rpm.conf")
if args.target not in conf:
conf.add_section(args.target)
kwargs["distconf"] = conf[args.target]
spec_file = f"rust-{metadata.name}.spec" spec_file = f"rust-{metadata.name}.spec"
spec_contents = template.render(md=metadata, patch_file=patch_file, **kwargs) spec_contents = template.render(md=metadata, patch_file=patch_file, **kwargs)
if args.stdout: if args.stdout:

View file

@ -65,6 +65,9 @@ BuildRequires: {{ req }}
{% endfor %} {% endfor %}
%endif %endif
{% endif %} {% endif %}
{% for req in to_list(distconf.get("buildrequires"))|sort %}
BuildRequires: {{ req }}
{% endfor %}
%global _description \ %global _description \
{% if md.description is none %} {% if md.description is none %}
@ -81,6 +84,9 @@ Summary: %{summary}
{% if rust_group is defined %} {% if rust_group is defined %}
Group: # FIXME Group: # FIXME
{% endif %} {% endif %}
{% for req in to_list(distconf.get("bin.requires"))|sort %}
Requires: {{ req }}
{% endfor %}
%description -n %{crate} %description -n %{crate}
%{summary}. %{summary}.
@ -106,7 +112,13 @@ Group: # FIXME
{% do features.insert(0, None) %} {% do features.insert(0, None) %}
{% do features.insert(1, "default") %} {% do features.insert(1, "default") %}
{% for feature in features %} {% for feature in features %}
{% set pkg = "-n %%{name}+%s-devel"|format(feature) if feature is not none else " devel" %} {% if feature is none %}
{% set pkg = " devel" %}
{% set conf_prefix = "lib" %}
{% else %}
{% set pkg = "-n %%{name}+%s-devel"|format(feature) %}
{% set conf_prefix = "lib+%s"|format(feature) %}
{% endif %}
%package {{ pkg }} %package {{ pkg }}
Summary: %{summary} Summary: %{summary}
{% if rust_group is defined %} {% if rust_group is defined %}
@ -122,6 +134,9 @@ Requires: cargo
Requires: {{ req }} Requires: {{ req }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% for req in to_list(distconf.get("%s.requires"|format(conf_prefix)))|sort %}
Requires: {{ req }}
{% endfor %}
%description {{ pkg }} %{_description} %description {{ pkg }} %{_description}