[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
03/09: gnu: python-2: Honor 'SOURCE_DATE_EPOCH'.
From: |
Ludovic Courtès |
Subject: |
03/09: gnu: python-2: Honor 'SOURCE_DATE_EPOCH'. |
Date: |
Sat, 21 Nov 2015 09:58:53 +0000 |
civodul pushed a commit to branch tk-update
in repository guix.
commit 12cc66f3c61627ec82772579e4a1ac8dfd9b0a7e
Author: Ludovic Courtès <address@hidden>
Date: Sat Nov 14 00:08:35 2015 +0100
gnu: python-2: Honor 'SOURCE_DATE_EPOCH'.
* gnu/packages/patches/python-2.7-source-date-epoch.patch: New file.
* gnu/packages/python.scm (python-2)[source]: Use it.
[arguments]: Set SOURCE_DATE_EPOCH in 'patch-lib-shells' phase.
* guix/build/python-build-system.scm (set-SOURCE-DATE-EPOCH): New
procedure.
(%standard-phases): Add it.
* gnu-system.am (dist_patch_DATA): Add patch.
---
gnu-system.am | 1 +
.../patches/python-2.7-source-date-epoch.patch | 33 ++++++++++++++++++++
gnu/packages/python.scm | 9 +++++-
guix/build/python-build-system.scm | 7 ++++
4 files changed, 49 insertions(+), 1 deletions(-)
diff --git a/gnu-system.am b/gnu-system.am
index 630a4c8..78659a9 100644
--- a/gnu-system.am
+++ b/gnu-system.am
@@ -665,6 +665,7 @@ dist_patch_DATA =
\
gnu/packages/patches/pybugz-stty.patch \
gnu/packages/patches/pyqt-configure.patch \
gnu/packages/patches/python-2.7-search-paths.patch \
+ gnu/packages/patches/python-2.7-source-date-epoch.patch \
gnu/packages/patches/python-3-search-paths.patch \
gnu/packages/patches/python-disable-ssl-test.patch \
gnu/packages/patches/python-fix-tests.patch \
diff --git a/gnu/packages/patches/python-2.7-source-date-epoch.patch
b/gnu/packages/patches/python-2.7-source-date-epoch.patch
new file mode 100644
index 0000000..be1f8e0
--- /dev/null
+++ b/gnu/packages/patches/python-2.7-source-date-epoch.patch
@@ -0,0 +1,33 @@
+Honor the 'SOURCE_DATE_EPOCH' environment variable to allow for
+determinitic builds.
+
+--- a/Lib/py_compile.py
++++ b/Lib/py_compile.py
+@@ -105,7 +105,10 @@ def compile(file, cfile=None, dfile=None, doraise=False):
+ """
+ with open(file, 'U') as f:
+ try:
+- timestamp = long(os.fstat(f.fileno()).st_mtime)
++ if 'SOURCE_DATE_EPOCH' in os.environ:
++ timestamp = long(os.environ['SOURCE_DATE_EPOCH'])
++ else:
++ timestamp = long(os.fstat(f.fileno()).st_mtime)
+ except AttributeError:
+ timestamp = long(os.stat(file).st_mtime)
+ codestring = f.read()
+diff --git a/Python/import.c b/Python/import.c
+index e47ce63..7eecf9c 100644
+--- a/Python/import.c
++++ b/Python/import.c
+@@ -945,6 +945,11 @@ write_compiled_module(PyCodeObject *co, char *cpathname,
struct stat *srcstat, t
+ /* Now write the true mtime (as a 32-bit field) */
+ fseek(fp, 4L, 0);
+ assert(mtime <= 0xFFFFFFFF);
++ if (Py_GETENV("SOURCE_DATE_EPOCH") != NULL) {
++ const char *epoch = Py_GETENV("SOURCE_DATE_EPOCH");
++ mtime = atoi(epoch);
++ }
++
+ PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
+ fflush(fp);
+ fclose(fp);
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index ecf02dd..9cf07e4 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -91,7 +91,9 @@
(sha256
(base32
"1h7zbrf9pkj29hlm18b10548ch9757f75m64l47sy75rh43p7lqw"))
- (patches (list (search-patch "python-2.7-search-paths.patch")))))
+ (patches (map search-patch
+ '("python-2.7-search-paths.patch"
+ "python-2.7-source-date-epoch.patch")))))
(build-system gnu-build-system)
(arguments
`(#:tests? #f
@@ -157,6 +159,11 @@
"Lib/distutils/tests/test_spawn.py"
"Lib/test/test_subprocess.py"))
(("/bin/sh") (which "sh")))
+
+ ;; Use zero as the timestamp in .pyc files so that builds are
+ ;; deterministic. TODO: Remove it when this variable is set in
+ ;; gnu-build-system.scm.
+ (setenv "SOURCE_DATE_EPOCH" "0")
#t))
(add-before
'check 'pre-check
diff --git a/guix/build/python-build-system.scm
b/guix/build/python-build-system.scm
index 1ae42c0..6775cc4 100644
--- a/guix/build/python-build-system.scm
+++ b/guix/build/python-build-system.scm
@@ -136,11 +136,18 @@ installed with setuptools."
#t))
#t))
+(define* (set-SOURCE-DATE-EPOCH #:rest _)
+ "Set the 'SOURCE_DATE_EPOCH' environment variable."
+ ;; Use zero as the timestamp in .pyc files so that builds are deterministic.
+ ;; TODO: Remove it when this variable is set in GNU:%STANDARD-PHASES.
+ (setenv "SOURCE_DATE_EPOCH" "0"))
+
(define %standard-phases
;; 'configure' and 'build' phases are not needed. Everything is done during
;; 'install'.
(modify-phases gnu:%standard-phases
(add-after 'unpack 'ensure-no-mtimes-pre-1980 ensure-no-mtimes-pre-1980)
+ (add-after 'unpack 'set-SOURCE-DATE-EPOCH set-SOURCE-DATE-EPOCH)
(delete 'configure)
(replace 'install install)
(replace 'check check)
- branch tk-update created (now d7572b4), Ludovic Courtès, 2015/11/21
- 01/09: tk: Hardcode path to TK_LIBRARY., Ludovic Courtès, 2015/11/21
- 02/09: gnu: tcl: Produce 'tclIndex' files deterministically., Ludovic Courtès, 2015/11/21
- 05/09: gnu: python: Make 'sys.version' deterministic., Ludovic Courtès, 2015/11/21
- 03/09: gnu: python-2: Honor 'SOURCE_DATE_EPOCH'.,
Ludovic Courtès <=
- 06/09: gnu: python: Factorize configure flags with minimal variants., Ludovic Courtès, 2015/11/21
- 08/09: gnu: python: Clarify and shorten the list of built-time modules., Ludovic Courtès, 2015/11/21
- 04/09: gnu: python: Set SOURCE_DATE_EPOCH to 1 instead of 0., Ludovic Courtès, 2015/11/21
- 07/09: gnu: python: Do not record configure flags., Ludovic Courtès, 2015/11/21
- 09/09: gnu: python: Move tkinter to "tk" output., Ludovic Courtès, 2015/11/21