diff options
author | Evgeny Egorochkin <phreedom@yandex.ru> | 2013-06-22 08:52:27 +0300 |
---|---|---|
committer | Evgeny Egorochkin <phreedom@yandex.ru> | 2013-06-22 09:45:01 +0300 |
commit | 09e6ae577bcd7eb8d8e142fc473798f938cbae1c (patch) | |
tree | 65e5a69fdc019388d7842ef4650b1f766c4ef4e5 /pkgs/development/interpreters/python | |
parent | a3bf1ca3b19d326ba6d7733541ec175061a44729 (diff) | |
download | nixlib-09e6ae577bcd7eb8d8e142fc473798f938cbae1c.tar nixlib-09e6ae577bcd7eb8d8e142fc473798f938cbae1c.tar.gz nixlib-09e6ae577bcd7eb8d8e142fc473798f938cbae1c.tar.bz2 nixlib-09e6ae577bcd7eb8d8e142fc473798f938cbae1c.tar.lz nixlib-09e6ae577bcd7eb8d8e142fc473798f938cbae1c.tar.xz nixlib-09e6ae577bcd7eb8d8e142fc473798f938cbae1c.tar.zst nixlib-09e6ae577bcd7eb8d8e142fc473798f938cbae1c.zip |
Python: add DETERMINISTIC_BUILD env var. If set, python doesn't write timestamps to pyc files. Tested by
building argparse, compiling from cli, compiling using py_compile.
Diffstat (limited to 'pkgs/development/interpreters/python')
-rw-r--r-- | pkgs/development/interpreters/python/2.7/default.nix | 4 | ||||
-rw-r--r-- | pkgs/development/interpreters/python/2.7/deterministic-build.patch | 36 |
2 files changed, 40 insertions, 0 deletions
diff --git a/pkgs/development/interpreters/python/2.7/default.nix b/pkgs/development/interpreters/python/2.7/default.nix index 4110f2502dcf..ccb423ef32e4 100644 --- a/pkgs/development/interpreters/python/2.7/default.nix +++ b/pkgs/development/interpreters/python/2.7/default.nix @@ -25,6 +25,10 @@ let # doesn't work in Nix because Nix changes the mtime of files in # the Nix store to 1. So treat that as a special case. ./nix-store-mtime.patch + + # patch python to put zero timestamp into pyc + # if DETERMINISTIC_BUILD env var is set + ./deterministic-build.patch ]; postPatch = stdenv.lib.optionalString (stdenv.gcc.libc != null) '' diff --git a/pkgs/development/interpreters/python/2.7/deterministic-build.patch b/pkgs/development/interpreters/python/2.7/deterministic-build.patch new file mode 100644 index 000000000000..98d9d339fa11 --- /dev/null +++ b/pkgs/development/interpreters/python/2.7/deterministic-build.patch @@ -0,0 +1,36 @@ +diff -ur orig/Lib/py_compile.py new/Lib/py_compile.py +--- orig/Lib/py_compile.py ++++ new/Lib/py_compile.py +@@ -122,7 +122,10 @@ + cfile = file + (__debug__ and 'c' or 'o') + with open(cfile, 'wb') as fc: + fc.write('\0\0\0\0') +- wr_long(fc, timestamp) ++ if "DETERMINISTIC_BUILD" in os.environ: ++ fc.write('\0\0\0\0') ++ else: ++ wr_long(fc, timestamp) + marshal.dump(codeobject, fc) + fc.flush() + fc.seek(0, 0) +diff -ur orig/Python/import.c new/Python/import.c +--- orig/Python/import.c ++++ new/Python/import.c +@@ -939,10 +939,12 @@ + return; + } + /* Now write the true mtime (as a 32-bit field) */ +- fseek(fp, 4L, 0); +- assert(mtime <= 0xFFFFFFFF); +- PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION); +- fflush(fp); ++ if (Py_GETENV("DETERMINISTIC_BUILD") == NULL) { ++ fseek(fp, 4L, 0); ++ assert(mtime <= 0xFFFFFFFF); ++ PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION); ++ fflush(fp); ++ } + fclose(fp); + if (Py_VerboseFlag) + PySys_WriteStderr("# wrote %s\n", cpathname); + |