From cf5494aa893811ac2fbac9f585d5ad875fafaada Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Tue, 26 May 2026 10:03:28 -0700 Subject: [PATCH] [build] Make generating the VM's version strings work with Ninja's restat feature. If the version is unchanged, don't write to the file. Ninja will notice the modification time is unchanged and avoid rebuilding the target's dependents. In particular, this means merely adding or amending a commit will no longer make the VM and all SDK snapshots dirty. Change-Id: I25617c6c584d1d1094a339fe14716d18b28c688f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506101 Reviewed-by: Alexander Aprelev Commit-Queue: Ryan Macnak --- tools/make_version.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/make_version.py b/tools/make_version.py index c25966f5bdb..208f93468c7 100755 --- a/tools/make_version.py +++ b/tools/make_version.py @@ -130,8 +130,13 @@ def main(): args.no_sdk_hash, args.version_file) if args.output: - with open(args.output, 'w') as fh: - fh.write(version) + # If the output already exists and there is no change, don't even + # write to the file. Ninja will notice the output's modified time + # is unchanged and avoid rebuilding dependents. + if not os.path.exists(args.output) or open( + args.output).read() != version: + with open(args.output, 'w') as fh: + fh.write(version) else: sys.stdout.write(version)