summaryrefslogtreecommitdiff
path: root/gnu/packages
diff options
context:
space:
mode:
authorRicardo Wurmus <ricardo.wurmus@mdc-berlin.de>2018-03-04 20:32:28 +0100
committerRicardo Wurmus <rekado@elephly.net>2018-03-15 09:25:46 +0100
commit9b7e389d41b217a12283f5b0a83e8122b088c67a (patch)
tree6f6aa0be00543bc9b04314a26b73e4e06ebe94de /gnu/packages
parentf529dfec74c2f5cbfe9cda65f9ee4b02fe12dbf9 (diff)
downloadpatches-9b7e389d41b217a12283f5b0a83e8122b088c67a.tar
patches-9b7e389d41b217a12283f5b0a83e8122b088c67a.tar.gz
gnu: python-3.6: Reset timestamps in pyc files.
* gnu/packages/python.scm (python-3.6)[arguments]: Add build phases to patch the bytecode generator to reset the embedded timestamp in pyc files; add build phase to rebuild the bytecode files.
Diffstat (limited to 'gnu/packages')
-rw-r--r--gnu/packages/python.scm70
1 files changed, 68 insertions, 2 deletions
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index d091157d8a..dbb5ccb52e 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -363,8 +363,74 @@ data types.")
;; versions of Python.
"Lib/test/test_socket.py"))
#t))))
- (arguments (substitute-keyword-arguments (package-arguments python-2)
- ((#:tests? _) #t)))
+ (arguments
+ (substitute-keyword-arguments (package-arguments python-2)
+ ((#:tests? _) #t)
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (add-after 'unpack 'patch-timestamp-for-pyc-files
+ (lambda _
+ ;; We set DETERMINISTIC_BUILD to only override the mtime when
+ ;; building with Guix, lest we break auto-compilation in
+ ;; environments.
+ (setenv "DETERMINISTIC_BUILD" "1")
+ (substitute* "Lib/py_compile.py"
+ (("source_stats\\['mtime'\\]")
+ "(1 if 'DETERMINISTIC_BUILD' in os.environ else source_stats['mtime'])"))
+
+ ;; Use deterministic hashes for strings, bytes, and datetime
+ ;; objects.
+ (setenv "PYTHONHASHSEED" "0")
+
+ ;; Reset mtime when validating bytecode header.
+ (substitute* "Lib/importlib/_bootstrap_external.py"
+ (("source_mtime = int\\(source_stats\\['mtime'\\]\\)")
+ "source_mtime = 1"))
+ #t))
+ ;; These tests fail because of our change to the bytecode
+ ;; validation. They fail because expected exceptions do not get
+ ;; thrown. This seems to be no problem.
+ (add-after 'unpack 'disable-broken-bytecode-tests
+ (lambda _
+ (substitute* "Lib/test/test_importlib/source/test_file_loader.py"
+ (("test_bad_marshal")
+ "disable_test_bad_marshal")
+ (("test_no_marshal")
+ "disable_test_no_marshal")
+ (("test_non_code_marshal")
+ "disable_test_non_code_marshal"))
+ #t))
+ ;; Unset DETERMINISTIC_BUILD to allow for tests that check that
+ ;; stale pyc files are rebuilt.
+ (add-before 'check 'allow-non-deterministic-compilation
+ (lambda _ (unsetenv "DETERMINISTIC_BUILD") #t))
+ ;; We need to rebuild all pyc files for three different
+ ;; optimization levels to replace all files that were not built
+ ;; deterministically.
+
+ ;; FIXME: Without this phase we have close to 2000 files that
+ ;; differ across different builds of this package. With this phase
+ ;; there are about 500 files left that differ.
+ (add-after 'install 'rebuild-bytecode
+ (lambda* (#:key outputs #:allow-other-keys)
+ (setenv "DETERMINISTIC_BUILD" "1")
+ (let ((out (assoc-ref outputs "out")))
+ (for-each
+ (lambda (opt)
+ (format #t "Compiling with optimization level: ~a\n"
+ (if (null? opt) "none" (car opt)))
+ (for-each (lambda (file)
+ (apply invoke
+ `(,(string-append out "/bin/python3")
+ ,@opt
+ "-m" "compileall"
+ "-f" ; force rebuild
+ ;; Don't build lib2to3, because it's Python 2 code.
+ ;; Also don't build obviously broken test code.
+ "-x" "(lib2to3|test/bad.*)"
+ ,file)))
+ (find-files out "\\.py$")))
+ (list '() '("-O") '("-OO"))))))))))
(native-search-paths
(list (search-path-specification
(variable "PYTHONPATH")