File reproducible.patch of Package orthanc-volview

https://orthanc.uclouvain.be/hg/orthanc-ohif/rev/154cb76a042f

commit 908709142f200316d9a2389c7c4d789985ead598
Author: Bernhard M. Wiedemann <bwiedemann+git@suse.de>
Date:   Thu Aug 3 13:09:13 2023 +0000

    Make StaticAssets.cpp reproducible
    
    See https://reproducible-builds.org/ for why this is good
    
    For this, we drop the build time from gzip headers
    and sort entries to avoid non-deterministic filesystem readdir order.
    
    The same patch applies to orthanc-volview.
    
    This patch was done while working on reproducible builds for openSUSE.

diff --git a/Resources/EmbedStaticAssets.py b/Resources/EmbedStaticAssets.py
index 613f45f..8fbc9ba 100755
--- a/Resources/EmbedStaticAssets.py
+++ b/Resources/EmbedStaticAssets.py
@@ -95,6 +95,8 @@ static void Uncompress(std::string& target, const void* data, size_t size, const
     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)
@@ -110,7 +112,7 @@ static void Uncompress(std::string& target, const void* data, size_t size, const
                 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 +123,7 @@ static void Uncompress(std::string& target, const void* data, size_t size, const
     
     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))
openSUSE Build Service is sponsored by