Blob Blame History Raw
From 09a496c65e5f91767336daddd0c9aa13d22160d5 Mon Sep 17 00:00:00 2001
From: Fabio Valentini <decathorpe@gmail.com>
Date: Oct 31 2022 14:26:11 +0000
Subject: rust2rpm: fix crash in sorting of binary targets


The "sort" Jinja2 filter doesn't work because the bins are objects,
not strings. This commit changes the sorting to happen correctly,
before binary targets are passed to the template for rendering.

---

diff --git a/rust2rpm/generator.py b/rust2rpm/generator.py
index e01c1b5..76875f7 100644
--- a/rust2rpm/generator.py
+++ b/rust2rpm/generator.py
@@ -1,3 +1,4 @@
+import operator
 import time
 
 import jinja2
@@ -52,6 +53,9 @@ def spec_file_render(
     is_bin = len(bins) > 0
     is_lib = len(libs) > 0
 
+    # sort binaries by name for consistent ordering
+    bins.sort(key=operator.attrgetter("name"))
+
     kwargs = {
         "generator_version": __version__,
         "target": args.target,
diff --git a/rust2rpm/templates/main.spec b/rust2rpm/templates/main.spec
index b39df3b..13b9bfd 100644
--- a/rust2rpm/templates/main.spec
+++ b/rust2rpm/templates/main.spec
@@ -124,7 +124,7 @@ Requires:       {{ req }}
   {% for file in doc_files %}
 %doc {{ file }}
   {% endfor %}
-  {% for bin in bins | sort %}
+  {% for bin in bins %}
 %{_bindir}/{{ bin.name }}
   {% endfor %}
   {% if not only_main %}