From 197150ee2e862edcd46f7ab02c9e4d17e49ca75d Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Wed, 31 Oct 2018 18:03:21 +0100 Subject: [PATCH] add support for feeding user configuration Signed-off-by: Igor Gnatenko --- 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..c691274 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(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_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}