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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 def ChmodAndRetry(func, path, _): | 77 def ChmodAndRetry(func, path, _): |
78 # Subversion can leave read-only files around. | 78 # Subversion can leave read-only files around. |
79 if not os.access(path, os.W_OK): | 79 if not os.access(path, os.W_OK): |
80 os.chmod(path, stat.S_IWUSR) | 80 os.chmod(path, stat.S_IWUSR) |
81 return func(path) | 81 return func(path) |
82 raise | 82 raise |
83 | 83 |
84 shutil.rmtree(dir, onerror=ChmodAndRetry) | 84 shutil.rmtree(dir, onerror=ChmodAndRetry) |
85 | 85 |
86 | 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 | |
96 def RunCommand(command, fail_hard=True): | 87 def RunCommand(command, fail_hard=True): |
97 """Run command and return success (True) or failure; or if fail_hard is | 88 """Run command and return success (True) or failure; or if fail_hard is |
98 True, exit on failure.""" | 89 True, exit on failure.""" |
99 | 90 |
100 print 'Running %s' % (str(command)) | 91 print 'Running %s' % (str(command)) |
101 if subprocess.call(command, shell=True) == 0: | 92 if subprocess.call(command, shell=True) == 0: |
102 return True | 93 return True |
103 print 'Failed.' | 94 print 'Failed.' |
104 if fail_hard: | 95 if fail_hard: |
105 sys.exit(1) | 96 sys.exit(1) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 return '' | 209 return '' |
219 | 210 |
220 | 211 |
221 def UpdateClang(args): | 212 def UpdateClang(args): |
222 print 'Updating Clang to %s...' % (LLVM_WIN_REVISION) | 213 print 'Updating Clang to %s...' % (LLVM_WIN_REVISION) |
223 if LLVM_WIN_REVISION != 'HEAD' and ReadStampFile() == LLVM_WIN_REVISION: | 214 if LLVM_WIN_REVISION != 'HEAD' and ReadStampFile() == LLVM_WIN_REVISION: |
224 print 'Already up to date.' | 215 print 'Already up to date.' |
225 return 0 | 216 return 0 |
226 | 217 |
227 AddCMakeToPath() | 218 AddCMakeToPath() |
228 if args.clobber: | |
229 ClobberChromiumBuildFiles() | |
230 | |
231 # Reset the stamp file in case the build is unsuccessful. | 219 # Reset the stamp file in case the build is unsuccessful. |
232 WriteStampFile('') | 220 WriteStampFile('') |
233 | 221 |
234 DeleteChromeToolsShim(); | 222 DeleteChromeToolsShim(); |
235 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR) | 223 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR) |
236 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR) | 224 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR) |
237 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR) | 225 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR) |
238 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) | 226 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) |
239 CreateChromeToolsShim(); | 227 CreateChromeToolsShim(); |
240 | 228 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 289 |
302 # This script is called by gclient. gclient opens its hooks subprocesses | 290 # This script is called by gclient. gclient opens its hooks subprocesses |
303 # with (stdout=subprocess.PIPE, stderr=subprocess.STDOUT) and then does | 291 # with (stdout=subprocess.PIPE, stderr=subprocess.STDOUT) and then does |
304 # custom output processing that breaks printing '\r' characters for | 292 # custom output processing that breaks printing '\r' characters for |
305 # single-line updating status messages as printed by curl and wget. | 293 # single-line updating status messages as printed by curl and wget. |
306 # Work around this by setting stderr of the update.sh process to stdin (!): | 294 # Work around this by setting stderr of the update.sh process to stdin (!): |
307 # gclient doesn't redirect stdin, and while stdin itself is read-only, a | 295 # gclient doesn't redirect stdin, and while stdin itself is read-only, a |
308 # dup()ed sys.stdin is writable, try | 296 # dup()ed sys.stdin is writable, try |
309 # fd2 = os.dup(sys.stdin.fileno()); os.write(fd2, 'hi') | 297 # fd2 = os.dup(sys.stdin.fileno()); os.write(fd2, 'hi') |
310 # TODO: Fix gclient instead, http://crbug.com/95350 | 298 # TODO: Fix gclient instead, http://crbug.com/95350 |
| 299 try: |
| 300 stderr = os.fdopen(os.dup(sys.stdin.fileno())) |
| 301 except: |
| 302 stderr = sys.stderr |
311 return subprocess.call( | 303 return subprocess.call( |
312 [os.path.join(os.path.dirname(__file__), 'update.sh')] + sys.argv[1:], | 304 [os.path.join(os.path.dirname(__file__), 'update.sh')] + sys.argv[1:], |
313 stderr=os.fdopen(os.dup(sys.stdin.fileno()))) | 305 stderr=stderr) |
314 | 306 |
315 parser = argparse.ArgumentParser(description='Build Clang.') | 307 parser = argparse.ArgumentParser(description='Build Clang.') |
316 parser.add_argument('--no-clobber', dest='clobber', action='store_false') | |
317 parser.add_argument('--tools', nargs='*', default=['plugins']) | 308 parser.add_argument('--tools', nargs='*', default=['plugins']) |
318 # For now, this flag is only used for the non-Windows flow, but argparser gets | 309 # For now, this flag is only used for the non-Windows flow, but argparser gets |
319 # mad if it sees a flag it doesn't recognize. | 310 # mad if it sees a flag it doesn't recognize. |
320 parser.add_argument('--if-needed', action='store_true') | 311 parser.add_argument('--if-needed', action='store_true') |
321 parser.add_argument('--print-revision', action='store_true') | 312 parser.add_argument('--print-revision', action='store_true') |
322 | 313 |
323 args = parser.parse_args() | 314 args = parser.parse_args() |
324 | 315 |
325 if args.print_revision: | 316 if args.print_revision: |
326 PrintRevision() | 317 PrintRevision() |
327 return 0 | 318 return 0 |
328 | 319 |
329 if not re.search(r'\b(clang|asan)=1', os.environ.get('GYP_DEFINES', '')): | 320 if not re.search(r'\b(clang|asan)=1', os.environ.get('GYP_DEFINES', '')): |
330 print 'Skipping Clang update (clang=1 was not set in GYP_DEFINES).' | 321 print 'Skipping Clang update (clang=1 was not set in GYP_DEFINES).' |
331 return 0 | 322 return 0 |
332 | 323 |
333 if re.search(r'\b(make_clang_dir)=', os.environ.get('GYP_DEFINES', '')): | 324 if re.search(r'\b(make_clang_dir)=', os.environ.get('GYP_DEFINES', '')): |
334 print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).' | 325 print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).' |
335 return 0 | 326 return 0 |
336 | 327 |
337 return UpdateClang(args) | 328 return UpdateClang(args) |
338 | 329 |
339 | 330 |
340 if __name__ == '__main__': | 331 if __name__ == '__main__': |
341 sys.exit(main()) | 332 sys.exit(main()) |
OLD | NEW |