Menu

#294 Enable reproducible builds by propgating SOURCE_DATE_EPOCH

3.x Stable
closed-accepted
f0rt
5
2020-08-11
2019-07-13
f0rt
No

Reproducible builds can be achieved by utilizing the timestamp defined by the SOURCE_DATE_EPOCH environment variable.

The following patch enables the propgation of the SOURCE_DATE_EPOCH environment variable and consequently reproducible builds.

Index: SConstruct
===================================================================
--- a/SConstruct    (revision 7102)
+++ b/SConstruct    (working copy)
@@ -63,20 +63,28 @@
 #######  Build Environment                                         ###
 ######################################################################

+import os
 path = ARGUMENTS.get('PATH', '')
 toolset = ARGUMENTS.get('TOOLSET', '')
-arch = ARGUMENTS.get('TARGET_ARCH', 'x86')
+defenv = {
+   'TARGET_ARCH': ARGUMENTS.get('TARGET_ARCH', 'x86'),
+   'ENV': {}
+}

-if toolset and path:
-   defenv = Environment(TARGET_ARCH = arch, ENV = {'PATH' : path}, TOOLS = toolset.split(',') + ['zip'])
+if 'SOURCE_DATE_EPOCH' in os.environ:
+   defenv['ENV']['SOURCE_DATE_EPOCH'] = os.environ['SOURCE_DATE_EPOCH']
+if path:
+   defenv['ENV']['PATH'] = path
+elif len(defenv['ENV']) == 0:
+   del defenv['ENV']
 else:
-   if path:
-       defenv = Environment(TARGET_ARCH = arch, ENV = {'PATH' : path})
-   if toolset:
-       defenv = Environment(TARGET_ARCH = arch, TOOLS = toolset.split(',') + ['zip'])
-if not toolset and not path:
-   defenv = Environment(TARGET_ARCH = arch)
+   # Propgate PATH if at least one environment variable is set
+   defenv['ENV']['PATH'] = os.environ['PATH']

+if toolset:
+   defenv['TOOLS'] = toolset.split(',') + ['zip']
+
+defenv = Environment(**defenv)
 Export('defenv')

 ######################################################################
@@ -89,7 +97,6 @@
 #######  Options                                                   ###
 ######################################################################

-import os
 default_doctype = 'html'
 if defenv.WhereIs('hhc', os.environ['PATH']):
    default_doctype = 'chm'

Discussion

  • Anders

    Anders - 2019-07-31
    • labels: review --> review, reproducible builds
     
  • Anders

    Anders - 2020-06-21

    Why should the presence of SOURCE_DATE_EPOCH trigger the usage of os.environ['PATH']?

     
  • f0rt

    f0rt - 2020-06-23

    As far as I recall setting just the SOURCE_DATE_EPOCH in the ENV directory is not the same for the PATH environment if no ENV directory at all is provided to the Environment object creation.

     
    • Anders

      Anders - 2020-06-25

      I don't know the details of how that ENV is handled in SCons. We don't really need to set so early anyway, we just need it set before we start calling external tools. We also have to manually patch the timestamp in PE files for older compiler versions.

       
  • Anders

    Anders - 2020-06-27
    • status: open --> closed-accepted
     
  • Jason

    Jason - 2020-08-11

    I found an issue on Fedora 32:

    scons: Reading SConscript files ...
    /home/jason/mxe/nsis-code-7212-NSIS-trunk/SConstruct:216: SyntaxWarning: "is not" with a literal. Did you mean "!="?
      if defenv.get('SOURCE_DATE_EPOCH','') is not '':
    /home/jason/mxe/nsis-code-7212-NSIS-trunk/SCons/utils.py:265: SyntaxWarning: "is not" with a literal. Did you mean "!="?
      if env.get('SOURCE_DATE_EPOCH','') is not '':
    
     
    • Anders

      Anders - 2020-08-11

      I think this is new in Python 3.8, thanks.

       

Log in to post a comment.