OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Windows can't run .sh files, so this is a Python implementation of | 6 """Windows can't run .sh files, so this is a Python implementation of |
7 update.sh. This script should replace update.sh on all platforms eventually.""" | 7 update.sh. This script should replace update.sh on all platforms eventually.""" |
8 | 8 |
9 import argparse | 9 import argparse |
10 import os | 10 import os |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 def WriteStampFile(s): | 58 def WriteStampFile(s): |
59 """Write s to the stamp file.""" | 59 """Write s to the stamp file.""" |
60 if not os.path.exists(LLVM_BUILD_DIR): | 60 if not os.path.exists(LLVM_BUILD_DIR): |
61 os.makedirs(LLVM_BUILD_DIR) | 61 os.makedirs(LLVM_BUILD_DIR) |
62 with open(STAMP_FILE, 'w') as f: | 62 with open(STAMP_FILE, 'w') as f: |
63 f.write(s) | 63 f.write(s) |
64 | 64 |
65 | 65 |
66 def PrintRevision(): | 66 def PrintRevision(): |
67 """Print the current Clang revision.""" | 67 """Print the current Clang revision.""" |
68 # gyp runs update.py --print-revision even when clang=1 isn't set. | |
69 # It won't use the value, but we must not error. | |
70 if not re.search(r'\b(clang|asan)=1', os.environ.get('GYP_DEFINES', '')): | |
71 print "0" | |
72 return | |
73 | |
74 # TODO(hans): This needs an update when we move to prebuilt Clang binaries. | 68 # TODO(hans): This needs an update when we move to prebuilt Clang binaries. |
75 svn_info = subprocess.check_output(['svn', 'info', LLVM_DIR]) | 69 svn_info = subprocess.check_output(['svn', 'info', LLVM_DIR]) |
76 m = re.search(r'Revision: (\d+)', svn_info) | 70 m = re.search(r'Revision: (\d+)', svn_info) |
77 assert m | 71 assert m |
78 print m.group(1) | 72 print m.group(1) |
79 | 73 |
80 | 74 |
81 def RmTree(dir): | 75 def RmTree(dir): |
82 """Delete dir.""" | 76 """Delete dir.""" |
83 def ChmodAndRetry(func, path, _): | 77 def ChmodAndRetry(func, path, _): |
84 # Subversion can leave read-only files around. | 78 # Subversion can leave read-only files around. |
85 if not os.access(path, os.W_OK): | 79 if not os.access(path, os.W_OK): |
86 os.chmod(path, stat.S_IWUSR) | 80 os.chmod(path, stat.S_IWUSR) |
87 return func(path) | 81 return func(path) |
88 raise | 82 raise |
89 | 83 |
90 shutil.rmtree(dir, onerror=ChmodAndRetry) | 84 shutil.rmtree(dir, onerror=ChmodAndRetry) |
91 | 85 |
92 | 86 |
| 87 def ClobberChromiumBuildFiles(): |
| 88 """Clobber Chomium build files.""" |
| 89 print 'Clobbering Chromium build files...' |
| 90 out_dir = os.path.join(CHROMIUM_DIR, 'out') |
| 91 if os.path.isdir(out_dir): |
| 92 RmTree(out_dir) |
| 93 print 'Removed Chromium out dir: %s.' % (out_dir) |
| 94 |
| 95 |
93 def RunCommand(command, fail_hard=True): | 96 def RunCommand(command, fail_hard=True): |
94 """Run command and return success (True) or failure; or if fail_hard is | 97 """Run command and return success (True) or failure; or if fail_hard is |
95 True, exit on failure.""" | 98 True, exit on failure.""" |
96 | 99 |
97 print 'Running %s' % (str(command)) | 100 print 'Running %s' % (str(command)) |
98 if subprocess.call(command, shell=True) == 0: | 101 if subprocess.call(command, shell=True) == 0: |
99 return True | 102 return True |
100 print 'Failed.' | 103 print 'Failed.' |
101 if fail_hard: | 104 if fail_hard: |
102 sys.exit(1) | 105 sys.exit(1) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 return '' | 218 return '' |
216 | 219 |
217 | 220 |
218 def UpdateClang(args): | 221 def UpdateClang(args): |
219 print 'Updating Clang to %s...' % (LLVM_WIN_REVISION) | 222 print 'Updating Clang to %s...' % (LLVM_WIN_REVISION) |
220 if LLVM_WIN_REVISION != 'HEAD' and ReadStampFile() == LLVM_WIN_REVISION: | 223 if LLVM_WIN_REVISION != 'HEAD' and ReadStampFile() == LLVM_WIN_REVISION: |
221 print 'Already up to date.' | 224 print 'Already up to date.' |
222 return 0 | 225 return 0 |
223 | 226 |
224 AddCMakeToPath() | 227 AddCMakeToPath() |
| 228 if args.clobber: |
| 229 ClobberChromiumBuildFiles() |
| 230 |
225 # Reset the stamp file in case the build is unsuccessful. | 231 # Reset the stamp file in case the build is unsuccessful. |
226 WriteStampFile('') | 232 WriteStampFile('') |
227 | 233 |
228 DeleteChromeToolsShim(); | 234 DeleteChromeToolsShim(); |
229 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR) | 235 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR) |
230 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR) | 236 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR) |
231 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR) | 237 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR) |
232 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) | 238 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) |
233 CreateChromeToolsShim(); | 239 CreateChromeToolsShim(); |
234 | 240 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 301 |
296 # This script is called by gclient. gclient opens its hooks subprocesses | 302 # This script is called by gclient. gclient opens its hooks subprocesses |
297 # with (stdout=subprocess.PIPE, stderr=subprocess.STDOUT) and then does | 303 # with (stdout=subprocess.PIPE, stderr=subprocess.STDOUT) and then does |
298 # custom output processing that breaks printing '\r' characters for | 304 # custom output processing that breaks printing '\r' characters for |
299 # single-line updating status messages as printed by curl and wget. | 305 # single-line updating status messages as printed by curl and wget. |
300 # Work around this by setting stderr of the update.sh process to stdin (!): | 306 # Work around this by setting stderr of the update.sh process to stdin (!): |
301 # gclient doesn't redirect stdin, and while stdin itself is read-only, a | 307 # gclient doesn't redirect stdin, and while stdin itself is read-only, a |
302 # dup()ed sys.stdin is writable, try | 308 # dup()ed sys.stdin is writable, try |
303 # fd2 = os.dup(sys.stdin.fileno()); os.write(fd2, 'hi') | 309 # fd2 = os.dup(sys.stdin.fileno()); os.write(fd2, 'hi') |
304 # TODO: Fix gclient instead, http://crbug.com/95350 | 310 # TODO: Fix gclient instead, http://crbug.com/95350 |
305 try: | |
306 stderr = os.fdopen(os.dup(sys.stdin.fileno())) | |
307 except: | |
308 stderr = sys.stderr | |
309 return subprocess.call( | 311 return subprocess.call( |
310 [os.path.join(os.path.dirname(__file__), 'update.sh')] + sys.argv[1:], | 312 [os.path.join(os.path.dirname(__file__), 'update.sh')] + sys.argv[1:], |
311 stderr=stderr) | 313 stderr=os.fdopen(os.dup(sys.stdin.fileno()))) |
312 | 314 |
313 parser = argparse.ArgumentParser(description='Build Clang.') | 315 parser = argparse.ArgumentParser(description='Build Clang.') |
| 316 parser.add_argument('--no-clobber', dest='clobber', action='store_false') |
314 parser.add_argument('--tools', nargs='*', default=['plugins']) | 317 parser.add_argument('--tools', nargs='*', default=['plugins']) |
315 # For now, this flag is only used for the non-Windows flow, but argparser gets | 318 # For now, this flag is only used for the non-Windows flow, but argparser gets |
316 # mad if it sees a flag it doesn't recognize. | 319 # mad if it sees a flag it doesn't recognize. |
317 parser.add_argument('--if-needed', action='store_true') | 320 parser.add_argument('--if-needed', action='store_true') |
318 parser.add_argument('--print-revision', action='store_true') | 321 parser.add_argument('--print-revision', action='store_true') |
319 | 322 |
320 args = parser.parse_args() | 323 args = parser.parse_args() |
321 | 324 |
322 if args.print_revision: | 325 if args.print_revision: |
323 PrintRevision() | 326 PrintRevision() |
324 return 0 | 327 return 0 |
325 | 328 |
326 if not re.search(r'\b(clang|asan)=1', os.environ.get('GYP_DEFINES', '')): | 329 if not re.search(r'\b(clang|asan)=1', os.environ.get('GYP_DEFINES', '')): |
327 print 'Skipping Clang update (clang=1 was not set in GYP_DEFINES).' | 330 print 'Skipping Clang update (clang=1 was not set in GYP_DEFINES).' |
328 return 0 | 331 return 0 |
329 | 332 |
330 if re.search(r'\b(make_clang_dir)=', os.environ.get('GYP_DEFINES', '')): | 333 if re.search(r'\b(make_clang_dir)=', os.environ.get('GYP_DEFINES', '')): |
331 print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).' | 334 print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).' |
332 return 0 | 335 return 0 |
333 | 336 |
334 return UpdateClang(args) | 337 return UpdateClang(args) |
335 | 338 |
336 | 339 |
337 if __name__ == '__main__': | 340 if __name__ == '__main__': |
338 sys.exit(main()) | 341 sys.exit(main()) |
OLD | NEW |