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