debug
diff --git a/mypyc/build.py b/mypyc/build.py index fad0995..09787b7 100644 --- a/mypyc/build.py +++ b/mypyc/build.py
@@ -285,22 +285,30 @@ """ # We encode it ourselves and open the files as binary to avoid windows # newline translation + from stat import ST_MTIME + encoded_contents = contents.encode('utf-8') try: with open(path, 'rb') as f: old_contents = f.read() # type: Optional[bytes] + old_mtime = os.stat(path)[ST_MTIME] except IOError: old_contents = None + old_mtime = 0 if old_contents != encoded_contents: with open(path, 'wb') as f: f.write(encoded_contents) + + new_mtime = os.stat(path)[ST_MTIME] + + print("Wrote", path, old_mtime, new_mtime) # Fudge the mtime forward because otherwise when two builds happen close # together (like in a test) setuptools might not realize the source is newer # than the new artifact. # XXX: This is bad though. - new_mtime = os.stat(path).st_mtime + 1 - os.utime(path, times=(new_mtime, new_mtime)) + #new_mtime = os.stat(path).st_mtime + 1 + # os.utime(path, times=(new_mtime, new_mtime)) def construct_groups(
diff --git a/mypyc/test/test_run.py b/mypyc/test/test_run.py index cd999d5..188367e 100644 --- a/mypyc/test/test_run.py +++ b/mypyc/test/test_run.py
@@ -7,7 +7,6 @@ import re import subprocess import contextlib -import time import shutil import sys from typing import Any, Iterator, List, cast @@ -45,6 +44,7 @@ from mypyc.build import mypycify setup(name='test_run_output', + verbose=True, ext_modules=mypycify({}, separate={}, skip_cgen_input={!r}, strip_asserts=False, multi_file={}), ) @@ -100,6 +100,15 @@ os.chdir(dir) +def fudge_dir_mtimes(dir: str, delta: int) -> None: + for dirpath, _, filenames in os.walk(dir): + for name in filenames: + # if name.endswith(('.c', '.h')): continue + path = os.path.join(dirpath, name) + new_mtime = os.stat(path).st_mtime + delta + os.utime(path, times=(new_mtime, new_mtime)) + + class TestRun(MypycDataSuite): """Test cases that build a C extension and run code.""" files = files @@ -135,8 +144,10 @@ steps = [] for operations in steps: - if sys.platform.startswith('win'): - time.sleep(1) + # To make sure that any new changes get picked up as being + # new by distutils, shift the mtime of all of the + # generated artifacts back by a second. + fudge_dir_mtimes(WORKDIR, -2) step += 1 with chdir_manager('..'): @@ -232,7 +243,7 @@ with open(setup_file, 'w', encoding='utf-8') as f: f.write(setup_format.format(module_paths, separate, cfiles, self.multi_file)) - if not run_setup(setup_file, ['build_ext', '--inplace']): + if not run_setup(setup_file, ['--verbose', 'build_ext', '--inplace']): if testcase.config.getoption('--mypyc-showc'): show_c(cfiles) assert False, "Compilation failed"