Support .rust2rpm.conf

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
epel9
Igor Gnatenko 6 years ago
parent a31cf1d2ba
commit ae59ba471d
No known key found for this signature in database
GPG Key ID: 695714BD1BBC5F4C

@ -1,7 +1,7 @@
From 0dc9fc182edf0791ca697f587e48dd39948d63c1 Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
Date: Mon, 10 Sep 2018 23:37:40 +0200
Subject: [PATCH 1/8] name spec/patch_file by real crate name
Subject: [PATCH 01/10] name spec/patch_file by real crate name
When renaming using patch file, we really want to change file names too.

@ -1,7 +1,7 @@
From 561280a0ea35f226ef243526be2bbb656db44af6 Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
Date: Mon, 10 Sep 2018 23:40:18 +0200
Subject: [PATCH 2/8] generate %doc statements
Subject: [PATCH 02/10] generate %doc statements
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
---

@ -1,7 +1,7 @@
From 2050880140d4953b9ebdc7211e30df3ccf5dd61d Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
Date: Tue, 11 Sep 2018 00:06:50 +0200
Subject: [PATCH 3/8] do better for renamed crates
Subject: [PATCH 03/10] do better for renamed crates
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
---

@ -1,7 +1,7 @@
From e6e9cbbb71199c2773b47fa21f1c917a167c1743 Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
Date: Tue, 11 Sep 2018 10:43:53 +0200
Subject: [PATCH 4/8] remove pre-3.6 leftovers
Subject: [PATCH 04/10] remove pre-3.6 leftovers
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
---

@ -1,7 +1,7 @@
From 2f12c83d14afe71e9efed2d1be62e1e610e602e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Fri, 17 Aug 2018 10:03:48 +0200
Subject: [PATCH 5/8] Remove half-downloaded crate on ^C
Subject: [PATCH 05/10] Remove half-downloaded crate on ^C
Subsequent invocations would fail with an error about a corrupted file.
We don't have support for resuming a failed download, so let's remove the

@ -1,7 +1,7 @@
From 5a1cde5b8dcaea74ebb2050879036bf46df63adc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Fri, 17 Aug 2018 10:18:59 +0200
Subject: [PATCH 6/8] Throw an error if -s is used without a crate
Subject: [PATCH 06/10] Throw an error if -s is used without a crate
In the future we might want to be smarter and find the crate, but let's at least
not ignore the option completely.

@ -1,7 +1,7 @@
From d7caa1148d5fcac70030e3fb1eb698927e69960f Mon Sep 17 00:00:00 2001
From 6f95899a21799054165858cacbe588a2a8bc6020 Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
Date: Fri, 26 Oct 2018 11:20:13 +0200
Subject: [PATCH 7/8] split features into subpackages
Subject: [PATCH 07/10] split features into subpackages
References: https://discussion.fedoraproject.org/t/rfc-new-crates-packaging-design-features-have-their-own-subpackages/563?u=ignatenkobrain
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>

@ -1,7 +1,7 @@
From 129d556d19d2e41135f5e98ed028d7d00e66b524 Mon Sep 17 00:00:00 2001
From a5fd01ecd0fd600a096c060ddfe77a21f54b045f Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
Date: Tue, 30 Oct 2018 20:37:38 +0100
Subject: [PATCH 8/8] add support for dependencies with same name
Subject: [PATCH 08/10] add support for dependencies with same name
Reported-by: Josh Stone <jistone@redhat.com>
References: https://internals.rust-lang.org/t/optional-dependencies-with-same-name/8728

@ -0,0 +1,148 @@
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

@ -0,0 +1,94 @@
From 00ed1ce05d9dd4c8042f27ca959350ce34fb1be5 Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
Date: Wed, 31 Oct 2018 17:00:58 +0100
Subject: [PATCH 10/10] trivial: use f-strings everywhere
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
---
rust2rpm/__main__.py | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py
index 18fac5c..b4eb624 100644
--- a/rust2rpm/__main__.py
+++ b/rust2rpm/__main__.py
@@ -79,7 +79,7 @@ def detect_packager():
if git is not None:
name = subprocess.check_output([git, "config", "user.name"], universal_newlines=True).strip()
email = subprocess.check_output([git, "config", "user.email"], universal_newlines=True).strip()
- return "{} <{}>".format(name, email)
+ return f"{name} <{email}>"
return None
@@ -108,23 +108,23 @@ def local_crate(crate, version):
def download(crate, version):
if version is None:
# Now we need to get latest version
- url = requests.compat.urljoin(API_URL, "crates/{}/versions".format(crate))
+ url = requests.compat.urljoin(API_URL, f"crates/{crate}/versions")
req = requests.get(url)
req.raise_for_status()
versions = req.json()["versions"]
version = next(version["num"] for version in versions if not version["yanked"])
os.makedirs(CACHEDIR, exist_ok=True)
- cratef_base = "{}-{}.crate".format(crate, version)
+ cratef_base = f"{crate}-{version}.crate"
cratef = os.path.join(CACHEDIR, cratef_base)
if not os.path.isfile(cratef):
- url = requests.compat.urljoin(API_URL, "crates/{}/{}/download#".format(crate, version))
+ url = requests.compat.urljoin(API_URL, f"crates/{crate}/{version}/download#")
req = requests.get(url, stream=True)
req.raise_for_status()
total = int(req.headers["Content-Length"])
with remove_on_error(cratef), \
open(cratef, "wb") as f:
- for chunk in tqdm.tqdm(req.iter_content(), "Downloading {}".format(cratef_base),
+ for chunk in tqdm.tqdm(req.iter_content(), f"Downloading {cratef_base}".format(cratef_base),
total=total, unit="B", unit_scale=True):
f.write(chunk)
return cratef, crate, version
@@ -132,14 +132,14 @@ def download(crate, version):
@contextlib.contextmanager
def toml_from_crate(cratef, crate, version):
with tempfile.TemporaryDirectory() as tmpdir:
- target_dir = "{}/".format(tmpdir)
+ target_dir = f"{tmpdir}/"
with tarfile.open(cratef, "r") as archive:
for n in archive.getnames():
if not os.path.abspath(os.path.join(target_dir, n)).startswith(target_dir):
raise Exception("Unsafe filenames!")
archive.extractall(target_dir)
- toml_relpath = "{}-{}/Cargo.toml".format(crate, version)
- toml = "{}/{}".format(tmpdir, toml_relpath)
+ toml_relpath = f"{crate}-{version}/Cargo.toml"
+ toml = f"{tmpdir}/{toml_relpath}"
if not os.path.isfile(toml):
raise IOError("crate does not contain Cargo.toml file")
yield toml
@@ -270,7 +270,7 @@ def main():
kwargs["include_provides"] = True
kwargs["include_requires"] = True
else:
- assert False, "Unknown target {!r}".format(args.target)
+ assert False, f"Unknown target {args.target!r}"
if args.target == "mageia":
kwargs["pkg_release"] = "%mkrel 1"
@@ -303,10 +303,10 @@ def main():
spec_file = f"rust-{metadata.name}.spec"
spec_contents = template.render(md=metadata, patch_file=patch_file, **kwargs)
if args.stdout:
- print("# {}".format(spec_file))
+ print(f"# {spec_file}")
print(spec_contents)
if patch_file is not None:
- print("# {}".format(patch_file))
+ print(f"# {patch_file}")
print("".join(diff), end="")
else:
with open(spec_file, "w") as fobj:
--
2.19.1

@ -4,7 +4,7 @@
Name: rust-packaging
Version: 6
Release: 14%{?dist}
Release: 15%{?dist}
Summary: RPM macros for building Rust packages on various architectures
License: MIT
@ -19,6 +19,8 @@ Patch0006: 0006-Throw-an-error-if-s-is-used-without-a-crate.patch
# Still in PR
Patch0007: 0007-split-features-into-subpackages.patch
Patch0008: 0008-add-support-for-dependencies-with-same-name.patch
Patch0009: 0009-add-support-for-feeding-user-configuration.patch
Patch0010: 0010-trivial-use-f-strings-everywhere.patch
BuildArch: noarch
ExclusiveArch: %{rust_arches} noarch
@ -80,6 +82,9 @@ py.test-%{python3_version} -vv test.py
%{python3_sitelib}/rust2rpm/
%changelog
* Fri Nov 02 2018 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 6-15
- Support .rust2rpm.conf
* Wed Oct 31 2018 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 6-14
- Fix syntax error

Loading…
Cancel
Save