From 1003acba8f68cdf171e67f477a0775e835bf7b5b Mon Sep 17 00:00:00 2001 From: Jaakko Manninen Date: Thu, 9 Jan 2025 01:35:49 -0800 Subject: [PATCH] Skip writing gclient_args.gni if contents are unchanged to avoid causing rebuild Running a gclient sync will touch the gclient_args.gni even if unchanged, especially on Windows resulting in an unnecessarily large rebuild of around 20k items. This skips writing the file if the contents are identical to what we're about to write. R=jojwang@google.com, sokcevic@chromium.org Change-Id: Iccf3fc8eeeb114fdf29bf944a8204e47489bc0a4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6157476 Reviewed-by: Josip Sokcevic Commit-Queue: Junji Watanabe Reviewed-by: Junji Watanabe --- gclient.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gclient.py b/gclient.py index fb5a9c6c5..2b6471e72 100755 --- a/gclient.py +++ b/gclient.py @@ -1431,8 +1431,18 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): if self._use_relative_paths: path_prefix = os.path.join(path_prefix, self.name) - with open(os.path.join(path_prefix, self._gn_args_file), 'wb') as f: - f.write('\n'.join(lines).encode('utf-8', 'replace')) + gn_args_path = os.path.join(path_prefix, self._gn_args_file) + + new_content = '\n'.join(lines).encode('utf-8', 'replace') + + if os.path.exists(gn_args_path): + with open(gn_args_path, 'rb') as f: + old_content = f.read() + if old_content == new_content: + return + + with open(gn_args_path, 'wb') as f: + f.write(new_content) @gclient_utils.lockedmethod def _run_is_done(self, file_list):