Skip to content

Commit d7bfe06

Browse files
authored
Merge pull request SCons#4552 from mwichmann/repro-build-notes
Reproducible builds info updated
2 parents a99da7c + aaee789 commit d7bfe06

File tree

5 files changed

+44
-24
lines changed

5 files changed

+44
-24
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
8585
Now matches the annotation and docstring (which were prematurely
8686
updated in 4.6). All SCons usage except unit test was already fully
8787
consistent with a bool.
88+
- Updated the notes about reproducible builds with SCons and the example.
8889
- The Clone() method now respects the variables argument (fixes #3590)
8990

9091

README.rst

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,19 @@ notifications and other GitHub events (``#github-update``),
249249
if those are of interest. See the website for more contact information:
250250
https://scons.org/contact.html.
251251

252+
Reproducible Builds
253+
===================
254+
SCons itself is set up to do "reproducible builds"
255+
(see (https://reproducible-builds.org/specs/source-date-epoch/)
256+
if environment variables ``SOURCE_DATE_EPOCH`` is set - that is,
257+
fields in the package which could change each time the package is
258+
constructed are forced to constant values.
259+
260+
To support other projects which wish to do the same, a sample script
261+
is provided which can be placed in a site directory, which imports
262+
``SOURCE_DATE_EPOCH`` and sets it in the execution environment of
263+
every created construction envirionment. There's also an installer
264+
script (POSIX shell only). See packaging/etc/README.txt for more details.
252265

253266
Donations
254267
=========
@@ -258,15 +271,6 @@ software, or hardware) to support continued work on the project. Information
258271
is available at https://www.scons.org/donate.html
259272
or the GitHub Sponsors button on https://github.com/scons/scons.
260273

261-
Reproducible Builds
262-
===================
263-
In order to suppor those users who which to produce reproducible builds
264-
(https://reproducible-builds.org/specs/source-date-epoch/) we're now including
265-
logic to force SCons to propagate SOURCE_DATE_EPOCH from your shell environment for
266-
all SCons builds to support reproducible builds we're now providing an example
267-
site_init.py and a script to install it in your ~/.scons. See packaging/etc/README.txt
268-
for more info
269-
270274
For More Information
271275
====================
272276

RELEASE.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ DOCUMENTATION
8383
- Restructured API Docs build so main package contents are listed
8484
before contents of package submodules.
8585
- Updated manpage description of Command "builder" and function.
86+
- Updated the notes about reproducible builds with SCons and the example.
8687

8788

8889

packaging/etc/README.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
This directory contains a number of scripts/files useful when building/packageing SCons
1+
This directory contains helpers for doing reproducible builds with SCons.
2+
3+
To force SCons to propagate SOURCE_DATE_EPOCH from the shell running SCons,
4+
the reproducible_site_init.py file can be installed (as site_init.py)
5+
in any site directory - either in the project itself, or more globally.
6+
See the manpage for default site directories or how to set your own path:
7+
https://scons.org/doc/production/HTML/scons-man.html#opt-site-dir.
8+
This code will make sure SOURCE_DATE_EPOCH is set in the execution
9+
environment, meaning any external commands run by SCons will have it
10+
in their environment. Any logic in your build system itself will still
11+
need to examine this variable.
12+
13+
The shell script reproducible_install.sh can be used to install the
14+
Python site file in your user site directory ($HOME/.scons/site_scons).
15+
It is careful to not overwrite any existing site_init.py there. This
16+
only works for a POSIX shell.
217

3-
To force SCons to propagate SOURCE_DATE_EPOCH from the shell running SCons we're providing
4-
a script to create a ~/.scons/site_scons/site_init.py.
5-
Note that reproducible_install.sh will NOT overwite an existing ~/.scons/site_scons/site_init.py
618
This supports https://reproducible-builds.org/specs/source-date-epoch/
7-
If you wanted to include this in your build tree you would place in site_scons/site_init.py relative
8-
to your SConstruct.
9-
* reproducible_install.sh
10-
* reproducible_site_init.py
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
2-
Use this file as your ~/.site_scons/scons_init.py to enable reprodicble builds as described at
2+
Use this file as your site_init.py in a site directory,
3+
to enable reprodicble builds as described at
34
https://reproducible-builds.org/specs/source-date-epoch/
45
"""
56

@@ -8,17 +9,22 @@
89

910
old_init = SCons.Environment.Base.__init__
1011

11-
print("Adding logic to propagate SOURCE_DATE_EPOCH from the shell environment when building with SCons")
12+
print(
13+
"Adding logic to propagate SOURCE_DATE_EPOCH from the shell environment when building with SCons"
14+
)
1215

1316

1417
def new_init(self, **kw):
15-
"""
16-
This logic will add SOURCE_DATE_EPOCH to the execution environment used to run
17-
all the build commands.
18+
"""Replacement Environment initializer.
19+
20+
When this is monkey-patched into :class:`SCons.Environment.Base` it adds
21+
``SOURCE_DATE_EPOCH`` to the execution environment used to run
22+
all external build commands; the original iinitializer is called first.
1823
"""
1924
old_init(self, **kw)
20-
if 'SOURCE_DATE_EPOCH' in os.environ:
21-
self._dict['ENV']['SOURCE_DATE_EPOCH'] = os.environ['SOURCE_DATE_EPOCH']
25+
epoch = os.environ.get("SOURCE_DATE_EPOCH")
26+
if epoch is not None:
27+
self._dict["ENV"]["SOURCE_DATE_EPOCH"] = epoch
2228

2329

2430
SCons.Environment.Base.__init__ = new_init

0 commit comments

Comments
 (0)