changeset 17:154cb76a042f

make the build of static assets reproducible
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 05 Aug 2023 11:36:33 +0200
parents 496bac7a275b
children 1aea0a224e90
files NEWS Resources/EmbedStaticAssets.py
diffstat 2 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Jun 19 10:05:31 2023 +0200
+++ b/NEWS	Sat Aug 05 11:36:33 2023 +0200
@@ -1,6 +1,9 @@
 Pending changes in the mainline
 ===============================
 
+* Patch to make the build of static assets reproducible, following a
+  suggestion by Bernhard M. Wiedemann (bwiedemann@suse.de)
+
 
 Version 1.0 (2023-06-19)
 ========================
--- a/Resources/EmbedStaticAssets.py	Mon Jun 19 10:05:31 2023 +0200
+++ b/Resources/EmbedStaticAssets.py	Sat Aug 05 11:36:33 2023 +0200
@@ -95,6 +95,9 @@
     count = 0
 
     for root, dirs, files in os.walk(SOURCE):
+        files.sort()
+        dirs.sort()
+
         for f in files:
             fullPath = os.path.join(root, f)
             relativePath = os.path.relpath(os.path.join(root, f), SOURCE)
@@ -106,11 +109,11 @@
             if sys.version_info < (3, 0):
                 # Python 2.7
                 fileobj = io.BytesIO()
-                gzip.GzipFile(fileobj=fileobj, mode='w').write(content)
+                gzip.GzipFile(fileobj=fileobj, mode='w', mtime=0).write(content)
                 compressed = fileobj.getvalue()
             else:
                 # Python 3.x
-                compressed = gzip.compress(content)
+                compressed = gzip.compress(content, mtime=0)
 
             EncodeFileAsCString(g, variable, compressed)
             WriteChecksum(g, variable + '_md5', content)
@@ -121,7 +124,7 @@
     
     g.write('void ReadStaticAsset(std::string& target, const std::string& path)\n')
     g.write('{\n')
-    for (path, variable) in index.items():
+    for (path, variable) in sorted(index.items()):
         g.write('  if (path == "%s")\n' % path)
         g.write('  {\n')
         g.write('    Uncompress(target, %s, sizeof(%s) - 1, %s_md5);\n' % (variable, variable, variable))