writeEngineStampIfChanged function
Writes the engine stamp for impellercExec to stampUri, skipping the
write when the on-disk content already matches.
Skipping matters because hook runners flag any tracked file modified during the build and would otherwise rerun the hook on every build. For the same reason a genuine rewrite backdates the stamp's mtime; change detection is content-hash based, so the mtime carries no information.
Implementation
Future<void> writeEngineStampIfChanged({
required Uri stampUri,
required Uri impellercExec,
int? glesLanguageVersion,
}) async {
final contents = await engineStampJson(
impellercExec: impellercExec,
glesLanguageVersion: glesLanguageVersion,
);
final file = File.fromUri(stampUri);
if (await file.exists() && await file.readAsString() == contents) {
return;
}
await file.writeAsString(contents);
try {
file.setLastModifiedSync(DateTime.utc(2000));
} on FileSystemException {
// Backdating is best-effort; without it the runner reruns the hook once
// more before the stamp settles.
}
}