Index: build/toolchain/win/setup_toolchain.py |
diff --git a/build/toolchain/win/setup_toolchain.py b/build/toolchain/win/setup_toolchain.py |
index a766cc1541573c8527e4c6c2efd6b72e0012177e..e13940964bbad6bd6484ca3488477221590a9183 100644 |
--- a/build/toolchain/win/setup_toolchain.py |
+++ b/build/toolchain/win/setup_toolchain.py |
@@ -147,11 +147,23 @@ def _CopyTool(source_path): |
tool_source = source_file.readlines() |
# Add header and write it out to the current directory (which should be the |
- # root build dir). |
- with open("gyp-win-tool", 'w') as tool_file: |
- tool_file.write(''.join([tool_source[0], |
- '# Generated by setup_toolchain.py do not edit.\n'] |
- + tool_source[1:])) |
+ # root build dir). Don't write the file if a matching file already exists |
+ # because that causes a cascade of unnecessary rebuilds. |
+ match = False |
+ contents = ''.join([tool_source[0], |
+ '# Generated by setup_toolchain.py do not edit.\n'] |
+ + tool_source[1:]) |
+ out_path = 'gyp-win-tool' |
+ try: |
+ with open(out_path, 'rb') as read_tool_file: |
+ existing_contents = read_tool_file.read() |
+ if existing_contents == contents: |
+ match = True |
+ except: |
+ pass |
+ if not match: |
+ with open(out_path, 'wb') as write_tool_file: |
+ write_tool_file.write(contents) |
def main(): |