Blame SOURCES/check-pyc-timestamps.py
|
|
93c559 |
"""Checks if all *.pyc files have later mtime than their *.py files."""
|
|
|
93c559 |
|
|
|
93c559 |
import os
|
|
|
93c559 |
import sys
|
|
|
93c559 |
from importlib.util import cache_from_source
|
|
|
93c559 |
from pathlib import Path
|
|
|
93c559 |
|
|
|
93c559 |
|
|
|
93c559 |
RPM_BUILD_ROOT = os.environ.get('RPM_BUILD_ROOT', '')
|
|
|
93c559 |
|
|
|
93c559 |
# ...cpython-3X.pyc
|
|
|
93c559 |
# ...cpython-3X.opt-1.pyc
|
|
|
93c559 |
# ...cpython-3X.opt-2.pyc
|
|
|
93c559 |
LEVELS = (None, 1, 2)
|
|
|
93c559 |
|
|
|
93c559 |
# list of globs of test and other files that we expect not to have bytecode
|
|
|
93c559 |
not_compiled = [
|
|
|
93c559 |
'/usr/bin/*',
|
|
|
93c559 |
'*/test/bad_coding.py',
|
|
|
93c559 |
'*/test/bad_coding2.py',
|
|
|
93c559 |
'*/test/badsyntax_*.py',
|
|
|
93c559 |
'*/lib2to3/tests/data/bom.py',
|
|
|
93c559 |
'*/lib2to3/tests/data/crlf.py',
|
|
|
93c559 |
'*/lib2to3/tests/data/different_encoding.py',
|
|
|
93c559 |
'*/lib2to3/tests/data/false_encoding.py',
|
|
|
93c559 |
'*/lib2to3/tests/data/py2_test_grammar.py',
|
|
|
93c559 |
'*.debug-gdb.py',
|
|
|
93c559 |
]
|
|
|
93c559 |
|
|
|
93c559 |
|
|
|
93c559 |
def bytecode_expected(path):
|
|
|
93c559 |
path = Path(path[len(RPM_BUILD_ROOT):])
|
|
|
93c559 |
for glob in not_compiled:
|
|
|
93c559 |
if path.match(glob):
|
|
|
93c559 |
return False
|
|
|
93c559 |
return True
|
|
|
93c559 |
|
|
|
93c559 |
|
|
|
93c559 |
failed = 0
|
|
|
93c559 |
compiled = (path for path in sys.argv[1:] if bytecode_expected(path))
|
|
|
93c559 |
for path in compiled:
|
|
|
93c559 |
to_check = (cache_from_source(path, optimization=opt) for opt in LEVELS)
|
|
|
93c559 |
f_mtime = os.path.getmtime(path)
|
|
|
93c559 |
for pyc in to_check:
|
|
|
93c559 |
c_mtime = os.path.getmtime(pyc)
|
|
|
93c559 |
if c_mtime < f_mtime:
|
|
|
93c559 |
print('Failed bytecompilation timestamps check: '
|
|
|
93c559 |
f'Bytecode file {pyc} is older than source file {path}',
|
|
|
93c559 |
file=sys.stderr)
|
|
|
93c559 |
failed += 1
|
|
|
93c559 |
|
|
|
93c559 |
if failed:
|
|
|
93c559 |
print(f'\n{failed} files failed bytecompilation timestamps check.',
|
|
|
93c559 |
file=sys.stderr)
|
|
|
93c559 |
sys.exit(1)
|