diff options
author | Bernhard M. Wiedemann <githubbmw@lsmod.de> | 2018-01-24 21:26:18 (GMT) |
---|---|---|
committer | Brett Cannon <brettcannon@users.noreply.github.com> | 2018-01-24 21:26:18 (GMT) |
commit | ccbe5818af20f8c12043f5c30c277a74714405e0 (patch) | |
tree | 5ca77fca24e3ec927647334dfb5e882560546039 /Lib/test | |
parent | 6f6eb35f9bee18f54945f09664344f2d118ed89f (diff) | |
download | cpython-ccbe5818af20f8c12043f5c30c277a74714405e0.zip cpython-ccbe5818af20f8c12043f5c30c277a74714405e0.tar.gz cpython-ccbe5818af20f8c12043f5c30c277a74714405e0.tar.bz2 |
bpo-29708: Setting SOURCE_DATE_EPOCH forces hash-based .pyc files (GH-5200)
To support reproducible builds, the setting of of SOURCE_DATE_EPOCH triggers the py_compile module -- and by extension, compileall -- to forcibly compile with hash-based .pyc files. This eliminates the possibility of timestamp-based .pyc files which vary between builds.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_py_compile.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py index bcb686c..8fc0b33 100644 --- a/Lib/test/test_py_compile.py +++ b/Lib/test/test_py_compile.py @@ -98,6 +98,18 @@ class PyCompileTests(unittest.TestCase): self.assertFalse(os.path.exists( importlib.util.cache_from_source(bad_coding))) + def test_source_date_epoch(self): + testtime = 123456789 + with support.EnvironmentVarGuard() as env: + env["SOURCE_DATE_EPOCH"] = str(testtime) + py_compile.compile(self.source_path, self.pyc_path) + self.assertTrue(os.path.exists(self.pyc_path)) + self.assertFalse(os.path.exists(self.cache_path)) + with open(self.pyc_path, 'rb') as fp: + flags = importlib._bootstrap_external._classify_pyc( + fp.read(), 'test', {}) + self.assertEqual(flags, 0b11) + @unittest.skipIf(sys.flags.optimize > 0, 'test does not work with -O') def test_double_dot_no_clobber(self): # http://bugs.python.org/issue22966 |