diff options
author | Ludovic Courtès <ludo@gnu.org> | 2015-11-14 00:08:35 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2015-11-29 22:59:28 +0100 |
commit | dedc8320701b3f5d23ccc213c1c0381e00b33785 (patch) | |
tree | 133d1909dd2a2ae83440d9674a6ae5d0fe3afcab /gnu | |
parent | f8e7fdc4165afa8c54638bcc8c40da91bf7c9618 (diff) | |
download | guix-dedc8320701b3f5d23ccc213c1c0381e00b33785.tar.gz |
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.
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/packages/patches/python-2.7-source-date-epoch.patch | 33 | ||||
-rw-r--r-- | gnu/packages/python.scm | 9 |
2 files changed, 41 insertions, 1 deletions
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 0000000000..be1f8e010e --- /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 001d00e9be..07725c727a 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -92,7 +92,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 @@ -158,6 +160,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 |