[Debian-pan-maintainers] Bug#1076507: mccode: please make the build (mostly) reproducible

Chris Lamb lamby at debian.org
Wed Jul 17 14:13:20 BST 2024


Source: mccode
Version: 0.0~git20240714172335.05614ae+ds5-2
Severity: wishlist
Tags: patch
User: reproducible-builds at lists.alioth.debian.org
Usertags: timestamps filesystem
X-Debbugs-Cc: reproducible-bugs at lists.alioth.debian.org

Hi,

Whilst working on the Reproducible Builds effort [0], we noticed that
mccode could not be built reproducibly.

This is because it embeds the current time (via the documentation)
and filesystem path in the mccode_config.json.

A patch attached that normalises the filesystem paths in .json files
and uses SOURCE_DATE_EPOCH to seed the date in the documentation.

This does not make the build entirely reproducible, however.

 [0] https://reproducible-builds.org/


Regards,

-- 
      ,''`.
     : :'  :     Chris Lamb
     `. `'`      lamby at debian.org / chris-lamb.co.uk
       `-
-------------- next part --------------
--- a/debian/patches/0009-Reproducible-builds.patch	1970-01-01 01:00:00.000000000 +0100
--- b/debian/patches/0009-Reproducible-builds.patch	2024-07-17 12:42:10.359758705 +0100
@@ -0,0 +1,54 @@
+Description: Make the build reproducible
+Author: Chris Lamb <lamby at debian.org>
+Last-Update: 2024-07-17
+
+--- mccode-0.0~git20240714172335.05614ae+ds5.orig/tools/Python/mcdoc/mcdoc.py
++++ mccode-0.0~git20240714172335.05614ae+ds5/tools/Python/mcdoc/mcdoc.py
+@@ -15,7 +15,8 @@ import sys
+ import os
+ import re
+ import subprocess
+-from datetime import datetime
++import datetime
++import time
+ from os.path import join, basename
+ 
+ sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
+@@ -34,6 +35,10 @@ class OverviewDocWriter:
+         self.instr_info_local_lst = instr_info_local_lst
+         self.mccode_libdir = mccode_libdir
+         self.text = ''
++        self.gendate = datetime.datetime.fromtimestamp(
++            int(os.environ.get('SOURCE_DATE_EPOCH', time.time())),
++            tz=datetime.timezone.utc,
++        )
+     
+     def create(self):
+         ''' action code for create overview page! '''
+@@ -148,7 +153,7 @@ class OverviewDocWriter:
+         text = text.replace('%TAB_LINES_INSTR_LOCAL%', local_instr_tab)
+         text = text.replace('%LINK_FILECOLON_DATA%', 'file://%s/data' % self.mccode_libdir)
+         text = text.replace('%LINK_FILECOLON_SHARE%', 'file://%s/share' % self.mccode_libdir)
+-        text = text.replace('%GENDATE%', '{0:%Y-%m-%d %H:%M:%S}'.format(datetime.now()))
++        text = text.replace('%GENDATE%', '{0:%Y-%m-%d %H:%M:%S}'.format(self.gendate))
+ 
+         #some McXtrace specific edits
+         if (mccode_config.get_mccode_prefix() == 'mx'):
+@@ -452,7 +457,7 @@ class InstrDocWriter:
+             lstr = lstr + self.lnk_str % l + '\n'
+         h = h.replace(t[12], lstr)
+         
+-        h = h.replace(t[13], '{0:%Y-%m-%d %H:%M:%S}'.format(datetime.now()))
++        h = h.replace(t[13], '{0:%Y-%m-%d %H:%M:%S}'.format(self.gendate))
+ 
+         self.text = h
+         return self.text
+@@ -625,7 +630,7 @@ class CompDocWriter:
+             lstr = lstr + self.lnk_str % l + '\n'
+         h = h.replace(t[12], lstr)
+ 
+-        h = h.replace(t[13], '{0:%Y-%m-%d %H:%M:%S}'.format(datetime.now()))
++        h = h.replace(t[13], '{0:%Y-%m-%d %H:%M:%S}'.format(self.gendate))
+ 
+         self.text = h
+         return self.text
--- a/debian/patches/series	2024-07-17 10:23:51.185028817 +0100
--- b/debian/patches/series	2024-07-17 11:57:58.764503421 +0100
@@ -5,3 +5,4 @@
 0005-Include-debian.cmake.patch
 0006-Stop-installing-postinst-and-errmsg-files.patch
 0007-Fix-installation-path-for-a-few-scripts.patch
+0009-Reproducible-builds.patch
--- a/debian/rules	2024-07-17 10:23:51.185028817 +0100
--- b/debian/rules	2024-07-17 11:13:38.741568507 +0100
@@ -159,6 +159,9 @@
 	mv debian/mcstas/usr/share/mcstas/mcstas-module       debian/mcxtrace/etc/modulefiles/
 	chmod -x debian/mcxtrace/etc/modulefiles/* debian/mcxtrace/etc/modulefiles/*
 
+	# reproducible build
+	find debian -name mccode_config.json -print0 | xargs -0rt sed -i -e "s@$(CURDIR)@/builddir at g"
+
 	# add editor highlight syntaxing
 	mkdir -p debian/mcstas-comps/usr/share/gtksourceview-4/language-specs/
 	mkdir -p debian/mcxtrace-comps/usr/share/gtksourceview-4/language-specs/


More information about the Debian-pan-maintainers mailing list