You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
4.3 KiB
149 lines
4.3 KiB
6 years ago
|
From 52b6ff8d55d59ace29950621ed41175ac31fa90c Mon Sep 17 00:00:00 2001
|
||
|
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
|
||
|
Date: Wed, 31 Oct 2018 18:03:21 +0100
|
||
|
Subject: [PATCH 09/10] add support for feeding user configuration
|
||
|
|
||
|
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
|
||
|
---
|
||
|
README.md | 26 ++++++++++++++++++++++++++
|
||
|
README.rst | 5 -----
|
||
|
rust2rpm/__main__.py | 13 +++++++++++++
|
||
|
rust2rpm/templates/main.spec | 17 ++++++++++++++++-
|
||
|
4 files changed, 55 insertions(+), 6 deletions(-)
|
||
|
create mode 100644 README.md
|
||
|
delete mode 100644 README.rst
|
||
|
|
||
|
diff --git a/README.md b/README.md
|
||
|
new file mode 100644
|
||
|
index 0000000..22b4b30
|
||
|
--- /dev/null
|
||
|
+++ b/README.md
|
||
|
@@ -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
|
||
|
+```
|
||
|
diff --git a/README.rst b/README.rst
|
||
|
deleted file mode 100644
|
||
|
index 8866027..0000000
|
||
|
--- a/README.rst
|
||
|
+++ /dev/null
|
||
|
@@ -1,5 +0,0 @@
|
||
|
-========
|
||
|
-rust2rpm
|
||
|
-========
|
||
|
-
|
||
|
-Convert Rust crates to RPM.
|
||
|
diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py
|
||
|
index d19cb47..18fac5c 100644
|
||
|
--- a/rust2rpm/__main__.py
|
||
|
+++ b/rust2rpm/__main__.py
|
||
|
@@ -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"))
|
||
|
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():
|
||
|
parser = argparse.ArgumentParser("rust2rpm",
|
||
|
formatter_class=argparse.RawTextHelpFormatter)
|
||
|
@@ -232,6 +237,7 @@ def main():
|
||
|
store=args.store_crate)
|
||
|
|
||
|
JINJA_ENV.globals["normalize_deps"] = normalize_deps
|
||
|
+ JINJA_ENV.globals["to_list"] = to_list
|
||
|
template = JINJA_ENV.get_template("main.spec")
|
||
|
|
||
|
if args.patch and len(diff) > 0:
|
||
|
@@ -287,6 +293,13 @@ def main():
|
||
|
kwargs["license"] = license
|
||
|
kwargs["license_comments"] = comments
|
||
|
|
||
|
+ conf = configparser.ConfigParser()
|
||
|
+ 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_contents = template.render(md=metadata, patch_file=patch_file, **kwargs)
|
||
|
if args.stdout:
|
||
|
diff --git a/rust2rpm/templates/main.spec b/rust2rpm/templates/main.spec
|
||
|
index 0d9a80b..d901e6d 100644
|
||
|
--- a/rust2rpm/templates/main.spec
|
||
|
+++ b/rust2rpm/templates/main.spec
|
||
|
@@ -65,6 +65,9 @@ BuildRequires: {{ req }}
|
||
|
{% endfor %}
|
||
|
%endif
|
||
|
{% endif %}
|
||
|
+{% for req in to_list(distconf.get("buildrequires"))|sort %}
|
||
|
+BuildRequires: {{ req }}
|
||
|
+{% endfor %}
|
||
|
|
||
|
%global _description \
|
||
|
{% if md.description is none %}
|
||
|
@@ -81,6 +84,9 @@ Summary: %{summary}
|
||
|
{% if rust_group is defined %}
|
||
|
Group: # FIXME
|
||
|
{% endif %}
|
||
|
+ {% for req in to_list(distconf.get("bin.requires"))|sort %}
|
||
|
+Requires: {{ req }}
|
||
|
+ {% endfor %}
|
||
|
|
||
|
%description -n %{crate}
|
||
|
%{summary}.
|
||
|
@@ -106,7 +112,13 @@ Group: # FIXME
|
||
|
{% do features.insert(0, None) %}
|
||
|
{% do features.insert(1, "default") %}
|
||
|
{% 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 }}
|
||
|
Summary: %{summary}
|
||
|
{% if rust_group is defined %}
|
||
|
@@ -122,6 +134,9 @@ Requires: cargo
|
||
|
Requires: {{ req }}
|
||
|
{% endfor %}
|
||
|
{% endif %}
|
||
|
+ {% for req in to_list(distconf.get("%s.requires"|format(conf_prefix)))|sort %}
|
||
|
+Requires: {{ req }}
|
||
|
+ {% endfor %}
|
||
|
|
||
|
%description {{ pkg }} %{_description}
|
||
|
|
||
|
--
|
||
|
2.19.1
|
||
|
|