Index: build/toolchain/mac/setup_toolchain.py |
diff --git a/build/toolchain/mac/setup_toolchain.py b/build/toolchain/mac/setup_toolchain.py |
index 431078fb1802d7f93adb310f8b917c4cc1c8162e..98b50bebcbab3bb6d14826dc5c8f05fbc0cf1664 100644 |
--- a/build/toolchain/mac/setup_toolchain.py |
+++ b/build/toolchain/mac/setup_toolchain.py |
@@ -13,14 +13,27 @@ 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). |
+ # 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-mac-tool' |
- with open(out_path, 'w') as tool_file: |
- tool_file.write(''.join([tool_source[0], |
- '# Generated by setup_toolchain.py do not edit.\n'] |
- + tool_source[1:])) |
+ 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) |
st = os.stat(out_path) |
- os.chmod(out_path, st.st_mode | stat.S_IEXEC) |
+ if (st.st_mode & stat.S_IEXEC) == 0: |
+ # Only chmod when necessary. |
+ os.chmod(out_path, st.st_mode | stat.S_IEXEC) |
# Find the tool source, it's the first argument, and copy it. |
if len(sys.argv) != 2: |