diff options
Diffstat (limited to 'tools/stale_build.py')
| -rw-r--r-- | tools/stale_build.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/stale_build.py b/tools/stale_build.py new file mode 100644 index 000000000..0945e5fed --- /dev/null +++ b/tools/stale_build.py | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | """Which sources of a runtime/test program are newer than a built copy of it. | ||
| 2 | |||
| 3 | make_game.py (vk_pipeline_check) and first_light.py (vk_harness) take a program already in runtime/build when there | ||
| 4 | is one. After a pull that changed the program, that copy is from the old sources and would run silently. The | ||
| 5 | sources are runtime/test/<name>.cpp and the headers it pulls in with #include "..." (followed through other | ||
| 6 | headers): a change to any of them recompiles and relinks the program, so a current build is never older than them. | ||
| 7 | runtime/CMakeLists.txt isn't one: a change there that doesn't concern the program leaves it as it was. | ||
| 8 | """ | ||
| 9 | import os | ||
| 10 | import re | ||
| 11 | |||
| 12 | _INCLUDE = re.compile(r'^\s*#\s*include\s*"([^"]+)"', re.MULTILINE) | ||
| 13 | |||
| 14 | |||
| 15 | def program_sources(root, name): | ||
| 16 | """The files program `name` of runtime/test is built from, as far as they exist in this checkout.""" | ||
| 17 | runtime = os.path.join(root, "runtime") | ||
| 18 | pending = [os.path.join(runtime, "test", name + ".cpp")] | ||
| 19 | found = [] | ||
| 20 | seen = set() | ||
| 21 | while pending: | ||
| 22 | path = os.path.normpath(pending.pop()) | ||
| 23 | if path in seen or not os.path.isfile(path): | ||
| 24 | continue | ||
| 25 | seen.add(path) | ||
| 26 | found.append(path) | ||
| 27 | try: | ||
| 28 | with open(path, encoding="utf-8", errors="replace") as f: | ||
| 29 | text = f.read() | ||
| 30 | except OSError: | ||
| 31 | continue | ||
| 32 | pending.extend(os.path.join(os.path.dirname(path), inc) for inc in _INCLUDE.findall(text)) | ||
| 33 | return found | ||
| 34 | |||
| 35 | |||
| 36 | def newer_sources(exe, root, name): | ||
| 37 | """The sources of program `name` changed after `exe` was built, relative to `root`; empty when `exe` is current | ||
| 38 | or isn't there to compare.""" | ||
| 39 | try: | ||
| 40 | built = os.path.getmtime(exe) | ||
| 41 | except OSError: | ||
| 42 | return [] | ||
| 43 | newer = [] | ||
| 44 | for path in program_sources(root, name): | ||
| 45 | try: | ||
| 46 | if os.path.getmtime(path) > built: | ||
| 47 | newer.append(os.path.relpath(path, root).replace(os.sep, "/")) | ||
| 48 | except OSError: | ||
| 49 | pass | ||
| 50 | return newer | ||