Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: build/toolchain/mac/setup_toolchain.py

Issue 1928303003: Only write gyp-mac-tool when needed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 import stat 6 import stat
7 import sys 7 import sys
8 8
9 def CopyTool(source_path): 9 def CopyTool(source_path):
10 """Copies the given tool to the current directory, including a warning not 10 """Copies the given tool to the current directory, including a warning not
11 to edit it.""" 11 to edit it."""
12 with open(source_path) as source_file: 12 with open(source_path) as source_file:
13 tool_source = source_file.readlines() 13 tool_source = source_file.readlines()
14 14
15 # Add header and write it out to the current directory (which should be the 15 # Add header and write it out to the current directory (which should be the
16 # root build dir). 16 # root build dir). Don't write the file if a matching file already exists
17 # because that causes a cascade of unnecessary rebuilds.
18 match = False
19 contents = ''.join([tool_source[0],
20 '# Generated by setup_toolchain.py do not edit.\n']
21 + tool_source[1:])
17 out_path = 'gyp-mac-tool' 22 out_path = 'gyp-mac-tool'
18 with open(out_path, 'w') as tool_file: 23 try:
19 tool_file.write(''.join([tool_source[0], 24 with open(out_path, 'rb') as read_tool_file:
20 '# Generated by setup_toolchain.py do not edit.\n'] 25 existing_contents = read_tool_file.read()
21 + tool_source[1:])) 26 if existing_contents == contents:
27 match = True
28 except:
29 pass
30 if not match:
31 with open(out_path, 'wb') as write_tool_file:
32 write_tool_file.write(contents)
22 st = os.stat(out_path) 33 st = os.stat(out_path)
23 os.chmod(out_path, st.st_mode | stat.S_IEXEC) 34 if (st.st_mode & stat.S_IEXEC) == 0:
35 # Only chmod when necessary.
36 os.chmod(out_path, st.st_mode | stat.S_IEXEC)
24 37
25 # Find the tool source, it's the first argument, and copy it. 38 # Find the tool source, it's the first argument, and copy it.
26 if len(sys.argv) != 2: 39 if len(sys.argv) != 2:
27 print "Need one argument (mac_tool source path)." 40 print "Need one argument (mac_tool source path)."
28 sys.exit(1) 41 sys.exit(1)
29 CopyTool(sys.argv[1]) 42 CopyTool(sys.argv[1])
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698