Keep the times a passing phone build leaves on tracked files

Generated tracked files such as src/apps/app_codec.zi are rewritten with the
same content during a build. Recording their final times after a pass keeps
the next no-change phone install from rebuilding the app packages and
reconfiguring CMake.
This commit is contained in:
waozi committed 2026-10-30 02:26:06 -03:00
1 parent 566f2bee8e
commit 2bbbe943f7
2 files changed
+47 -17

No files matched your search

+44 -17
View File
@@ -22,36 +22,53 @@ def remove_read_only(function, path, error):
function(path)
def restore_unchanged_times(git, root, record):
"""Give each file whose content matches the last run its earlier time.
Materializing writes every file anew, so make and CMake would rebuild
everything. The record maps each path to its blob and the time it first
held that blob; changed files keep the current time."""
previous = json.loads(record.read_text()) if record.exists() else {}
current = {}
def tracked_files(git):
"""Yield each tracked file's path and its mode and blob."""
for entry in git("ls-files", "--stage", "-z").split(b"\0"):
if not entry or entry.startswith(b"160000 "):
continue
info, path = entry.split(b"\t", 1)
mode, blob = info.split()[:2]
name = os.fsdecode(path)
identity = mode.decode() + " " + blob.decode()
yield os.fsdecode(path), mode.decode() + " " + blob.decode()
def write_times(record, times):
record.parent.mkdir(parents=True, exist_ok=True)
temporary = record.with_name(record.name + ".tmp")
temporary.write_text(json.dumps(times))
temporary.replace(record)
def restore_unchanged_times(git, root, record):
"""Give each file whose content matches the last run its earlier time.
Materializing writes every file anew, so make and CMake would rebuild
everything. The record maps each path to its blob and its time; changed
files keep the current time. It is written before building, so a failed
build cannot leave outputs that look newer than a later content change."""
previous = json.loads(record.read_text()) if record.exists() else {}
current = {}
for name, identity in tracked_files(git):
known = previous.get(name)
if known and known[0] == identity:
os.utime(root / name, ns=(known[1], known[1]), follow_symlinks=False)
current[name] = known
else:
current[name] = [identity, (root / name).lstat().st_mtime_ns]
record.parent.mkdir(parents=True, exist_ok=True)
temporary = record.with_name(record.name + ".tmp")
temporary.write_text(json.dumps(current))
temporary.replace(record)
write_times(record, current)
print("release-ready: kept the times of unchanged files", flush=True)
def prepare(root, revision, times_record=None):
root = Path(root).resolve(strict=True)
def record_final_times(git, root, record):
"""After a passing build, keep the times the build left, such as those of
generated tracked files it rewrote with the same content."""
times = {name: [identity, (root / name).lstat().st_mtime_ns]
for name, identity in tracked_files(git)}
write_times(record, times)
def overlay_git(root):
"""Return Git for root once it is proven to be a private release overlay."""
filesystem = subprocess.check_output(
["stat", "-f", "-c", "%T", root], text=True).strip()
mounts = [line.split() for line in Path("/proc/self/mountinfo").read_text().splitlines()]
@@ -67,6 +84,12 @@ def prepare(root, revision, times_record=None):
["git", "-c", "safe.directory=" + str(root), "-c", "core.hooksPath=/dev/null",
"-C", str(root), *arguments])
return git
def prepare(root, revision, times_record=None):
root = Path(root).resolve(strict=True)
git = overlay_git(root)
commit = git("rev-parse", revision + "^{commit}").decode().strip()
git("config", "--global", "--add", "safe.directory", str(root))
git("lfs", "install", "--skip-repo")
@@ -95,7 +118,11 @@ def prepare(root, revision, times_record=None):
if __name__ == "__main__":
try:
prepare(sys.argv[1], sys.argv[2], sys.argv[3] if len(sys.argv) > 3 else None)
if sys.argv[1] == "--record-times":
root = Path(sys.argv[2]).resolve(strict=True)
record_final_times(overlay_git(root), root, root / sys.argv[3])
else:
prepare(sys.argv[1], sys.argv[2], sys.argv[3] if len(sys.argv) > 3 else None)
except (OSError, ValueError, subprocess.CalledProcessError) as error:
print("release-ready: " + str(error), file=sys.stderr)
sys.exit(2)
+3
View File
@@ -114,6 +114,9 @@ if [ -n "$failed" ]; then
exit 1
fi
git diff --exit-code "$RELEASE_READY_COMMIT" -- .
if [ -n "$RELEASE_READY_INCREMENTAL" ]; then
python3 -c "$RELEASE_READY_SNAPSHOT" --record-times /src build/incremental/source-times.json
fi
if [ "$#" -gt 0 ]; then
printf "\nrelease-ready: make %s passed\n" "$*"
else