Skip to contentSkip to conversation

gentpl.py: ensure output is deterministic

PATCH In review Alexander Kanavin 2 participants 4 messages Jun 1, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 gentpl.py: ensure output is deterministic

The output of the SOURCES lines in grub-core/Makefile.core.am, generated from grub-core/Makefile.core.def with gentpl.py is not deterministic due to missing sorting of the list used to generate it. Add such a sort.

---
 gentpl.py | 1 +
 1 file changed, 1 insertion(+)
gentpl.py +1 -0
index d0470b3b2..bfab2113a 100644
@@ -569,6 +569,7 @@ def foreach_platform_value(defn, platform, suffix, closure):
     for group in RMAP[platform]:
         for value in defn.find_all(group + suffix):
             r.append(closure(value))
+    r.sort()
     return ''.join(r)
 
 def platform_conditional(platform, closure):
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/3 grub-core/genmoddep.awk: ensure output is deterministic

The output in moddep.lst generated from syminfo.lst using genmoddep.awk is not deterministic since the order of the dependencies on each line can vary depending on how awk sorts the values in the array.

Be deterministic in the output by sorting the dependencies on each line.

---
 grub-core/genmoddep.awk | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
grub-core/genmoddep.awk +3 -1
index 04c2863e5..247436392 100644
@@ -59,7 +59,9 @@ END {
     }
     modlist = ""
     depcount[mod] = 0
-    for (depmod in uniqmods) {
+    n = asorti(uniqmods, w)
+    for (i = 1; i <= n; i++) {
+      depmod = w[i]
       modlist = modlist " " depmod;
       inverse_dependencies[depmod] = inverse_dependencies[depmod] " " mod
       depcount[mod]++
Signature · 1 line
2.30.2
#2 lore raw

PATCH 3/3 util/import_unicode.py: ensure output is deterministic

In reply to Alexander Kanavin

Ensure the generated unidata.c file is deterministic by sorting the keys of the dict.

---
 util/import_unicode.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/import_unicode.py +1 -1
index 08f80591e..1f434a069 100644
@@ -174,7 +174,7 @@ infile.close ()
 
 outfile.write ("struct grub_unicode_arabic_shape grub_unicode_arabic_shapes[] = {\n ")
 
-for x in arabicsubst:
+for x in sorted(arabicsubst):
     try:
         if arabicsubst[x]['join'] == "DUAL":
             outfile.write ("{0x%x, 0x%x, 0x%x, 0x%x, 0x%x},\n " % (arabicsubst[x][0], arabicsubst[x][1], arabicsubst[x][2], arabicsubst[x][3], arabicsubst[x][4]))
Signature · 1 line
2.30.2