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 cStringIO | 10 import cStringIO |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 THIS_DIR = os.path.abspath(os.path.dirname(__file__)) | 44 THIS_DIR = os.path.abspath(os.path.dirname(__file__)) |
45 CHROMIUM_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..', '..')) | 45 CHROMIUM_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..', '..')) |
46 THIRD_PARTY_DIR = os.path.join(CHROMIUM_DIR, 'third_party') | 46 THIRD_PARTY_DIR = os.path.join(CHROMIUM_DIR, 'third_party') |
47 LLVM_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm') | 47 LLVM_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm') |
48 LLVM_BOOTSTRAP_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm-bootstrap') | 48 LLVM_BOOTSTRAP_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm-bootstrap') |
49 LLVM_BOOTSTRAP_INSTALL_DIR = os.path.join(THIRD_PARTY_DIR, | 49 LLVM_BOOTSTRAP_INSTALL_DIR = os.path.join(THIRD_PARTY_DIR, |
50 'llvm-bootstrap-install') | 50 'llvm-bootstrap-install') |
51 CHROME_TOOLS_SHIM_DIR = os.path.join(LLVM_DIR, 'tools', 'chrometools') | 51 CHROME_TOOLS_SHIM_DIR = os.path.join(LLVM_DIR, 'tools', 'chrometools') |
52 LLVM_BUILD_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'llvm-build', | 52 LLVM_BUILD_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'llvm-build', |
53 'Release+Asserts') | 53 'Release+Asserts') |
54 COMPILER_RT_BUILD_DIR = os.path.join(LLVM_BUILD_DIR, '32bit-compiler-rt') | 54 COMPILER_RT_BUILD_DIR = os.path.join(LLVM_BUILD_DIR, 'compiler-rt') |
55 CLANG_DIR = os.path.join(LLVM_DIR, 'tools', 'clang') | 55 CLANG_DIR = os.path.join(LLVM_DIR, 'tools', 'clang') |
56 LLD_DIR = os.path.join(LLVM_DIR, 'tools', 'lld') | 56 LLD_DIR = os.path.join(LLVM_DIR, 'tools', 'lld') |
57 COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'projects', 'compiler-rt') | 57 # compiler-rt is built as part of the regular LLVM build on Windows to get |
| 58 # the 64-bit runtime, and out-of-tree elsewhere. |
| 59 # TODO(thakis): Try to unify this. |
| 60 if sys.platform == 'win32': |
| 61 COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'projects', 'compiler-rt') |
| 62 else: |
| 63 COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'compiler-rt') |
58 LIBCXX_DIR = os.path.join(LLVM_DIR, 'projects', 'libcxx') | 64 LIBCXX_DIR = os.path.join(LLVM_DIR, 'projects', 'libcxx') |
59 LIBCXXABI_DIR = os.path.join(LLVM_DIR, 'projects', 'libcxxabi') | 65 LIBCXXABI_DIR = os.path.join(LLVM_DIR, 'projects', 'libcxxabi') |
60 LLVM_BUILD_TOOLS_DIR = os.path.abspath( | 66 LLVM_BUILD_TOOLS_DIR = os.path.abspath( |
61 os.path.join(LLVM_DIR, '..', 'llvm-build-tools')) | 67 os.path.join(LLVM_DIR, '..', 'llvm-build-tools')) |
62 STAMP_FILE = os.path.join(LLVM_DIR, '..', 'llvm-build', 'cr_build_revision') | 68 STAMP_FILE = os.path.join(LLVM_DIR, '..', 'llvm-build', 'cr_build_revision') |
63 BINUTILS_DIR = os.path.join(THIRD_PARTY_DIR, 'binutils') | 69 BINUTILS_DIR = os.path.join(THIRD_PARTY_DIR, 'binutils') |
64 VERSION = '3.8.0' | 70 VERSION = '3.8.0' |
| 71 ANDROID_NDK_DIR = os.path.join( |
| 72 CHROMIUM_DIR, 'third_party', 'android_tools', 'ndk') |
65 | 73 |
66 # URL for pre-built binaries. | 74 # URL for pre-built binaries. |
67 CDS_URL = 'https://commondatastorage.googleapis.com/chromium-browser-clang' | 75 CDS_URL = 'https://commondatastorage.googleapis.com/chromium-browser-clang' |
68 | 76 |
69 LLVM_REPO_URL='https://llvm.org/svn/llvm-project' | 77 LLVM_REPO_URL='https://llvm.org/svn/llvm-project' |
70 if 'LLVM_REPO_URL' in os.environ: | 78 if 'LLVM_REPO_URL' in os.environ: |
71 LLVM_REPO_URL = os.environ['LLVM_REPO_URL'] | 79 LLVM_REPO_URL = os.environ['LLVM_REPO_URL'] |
72 | 80 |
73 | 81 |
74 def DownloadUrl(url, output_file): | 82 def DownloadUrl(url, output_file): |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 185 |
178 def CopyFile(src, dst): | 186 def CopyFile(src, dst): |
179 """Copy a file from src to dst.""" | 187 """Copy a file from src to dst.""" |
180 shutil.copy(src, dst) | 188 shutil.copy(src, dst) |
181 print "Copying %s to %s" % (src, dst) | 189 print "Copying %s to %s" % (src, dst) |
182 | 190 |
183 | 191 |
184 def CopyDirectoryContents(src, dst, filename_filter=None): | 192 def CopyDirectoryContents(src, dst, filename_filter=None): |
185 """Copy the files from directory src to dst | 193 """Copy the files from directory src to dst |
186 with an optional filename filter.""" | 194 with an optional filename filter.""" |
| 195 dst = os.path.realpath(dst) # realpath() in case dst ends in /.. |
187 if not os.path.exists(dst): | 196 if not os.path.exists(dst): |
188 os.makedirs(dst) | 197 os.makedirs(dst) |
189 for root, _, files in os.walk(src): | 198 for root, _, files in os.walk(src): |
190 for f in files: | 199 for f in files: |
191 if filename_filter and not re.match(filename_filter, f): | 200 if filename_filter and not re.match(filename_filter, f): |
192 continue | 201 continue |
193 CopyFile(os.path.join(root, f), dst) | 202 CopyFile(os.path.join(root, f), dst) |
194 | 203 |
195 | 204 |
196 def Checkout(name, url, dir): | 205 def Checkout(name, url, dir): |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 # faster, and goma relies on having matching binary hashes on client and | 324 # faster, and goma relies on having matching binary hashes on client and |
316 # server too. | 325 # server too. |
317 print 'Trying to download prebuilt clang' | 326 print 'Trying to download prebuilt clang' |
318 | 327 |
319 try: | 328 try: |
320 if os.path.exists(LLVM_BUILD_DIR): | 329 if os.path.exists(LLVM_BUILD_DIR): |
321 RmTree(LLVM_BUILD_DIR) | 330 RmTree(LLVM_BUILD_DIR) |
322 DownloadAndUnpack(cds_full_url, LLVM_BUILD_DIR) | 331 DownloadAndUnpack(cds_full_url, LLVM_BUILD_DIR) |
323 print 'clang %s unpacked' % PACKAGE_VERSION | 332 print 'clang %s unpacked' % PACKAGE_VERSION |
324 # Download the gold plugin if requested to by an environment variable. | 333 # Download the gold plugin if requested to by an environment variable. |
325 # This is used by the CFI ClusterFuzz bot. | 334 # This is used by the CFI ClusterFuzz bot, and it's required for official |
326 if 'LLVM_DOWNLOAD_GOLD_PLUGIN' in os.environ: | 335 # builds on linux. |
| 336 if 'LLVM_DOWNLOAD_GOLD_PLUGIN' in os.environ or ( |
| 337 sys.platform.startswith('linux') and |
| 338 'buildtype=Official' in sys.environ.get('GYP_DEFINES', '') and |
| 339 'branding=Chrome' in sys.environ.get('GYP_DEFINES', '')): |
327 RunCommand(['python', CHROMIUM_DIR+'/build/download_gold_plugin.py']) | 340 RunCommand(['python', CHROMIUM_DIR+'/build/download_gold_plugin.py']) |
328 WriteStampFile(PACKAGE_VERSION) | 341 WriteStampFile(PACKAGE_VERSION) |
329 return 0 | 342 return 0 |
330 except urllib2.HTTPError: | 343 except urllib2.HTTPError: |
331 print 'Did not find prebuilt clang %s, building locally' % cds_file | 344 print 'Did not find prebuilt clang %s, building locally' % cds_file |
332 | 345 |
| 346 if args.with_android and not os.path.exists(ANDROID_NDK_DIR): |
| 347 print 'Android NDK not found at ' + ANDROID_NDK_DIR |
| 348 print 'The Android NDK is needed to build a Clang whose -fsanitize=address' |
| 349 print 'works on Android. See ' |
| 350 print 'http://code.google.com/p/chromium/wiki/AndroidBuildInstructions' |
| 351 print 'for how to install the NDK, or pass --without-android.' |
| 352 return 1 |
| 353 |
333 MaybeDownloadHostGcc(args) | 354 MaybeDownloadHostGcc(args) |
334 AddCMakeToPath() | 355 AddCMakeToPath() |
335 | 356 |
336 DeleteChromeToolsShim() | 357 DeleteChromeToolsShim() |
337 | 358 |
338 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR) | 359 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR) |
339 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR) | 360 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR) |
340 if sys.platform == 'win32': | 361 if sys.platform == 'win32': |
341 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR) | 362 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR) |
342 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) | 363 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 binutils_incdir = '' | 505 binutils_incdir = '' |
485 if sys.platform.startswith('linux'): | 506 if sys.platform.startswith('linux'): |
486 binutils_incdir = os.path.join(BINUTILS_DIR, 'Linux_x64/Release/include') | 507 binutils_incdir = os.path.join(BINUTILS_DIR, 'Linux_x64/Release/include') |
487 | 508 |
488 # If building at head, define a macro that plugins can use for #ifdefing | 509 # If building at head, define a macro that plugins can use for #ifdefing |
489 # out code that builds at head, but not at LLVM_WIN_REVISION or vice versa. | 510 # out code that builds at head, but not at LLVM_WIN_REVISION or vice versa. |
490 if use_head_revision: | 511 if use_head_revision: |
491 cflags += ['-DLLVM_FORCE_HEAD_REVISION'] | 512 cflags += ['-DLLVM_FORCE_HEAD_REVISION'] |
492 cxxflags += ['-DLLVM_FORCE_HEAD_REVISION'] | 513 cxxflags += ['-DLLVM_FORCE_HEAD_REVISION'] |
493 | 514 |
| 515 # Pin MSan to the old ABI. |
| 516 # TODO(eugenis): Remove when MSan migrates to new ABI (crbug.com/560589). |
| 517 cxxflags += [ '-DMSAN_LINUX_X86_64_OLD_MAPPING' ] |
| 518 |
494 CreateChromeToolsShim() | 519 CreateChromeToolsShim() |
495 | 520 |
496 deployment_env = None | 521 deployment_env = None |
497 if deployment_target: | 522 if deployment_target: |
498 deployment_env = os.environ.copy() | 523 deployment_env = os.environ.copy() |
499 deployment_env['MACOSX_DEPLOYMENT_TARGET'] = deployment_target | 524 deployment_env['MACOSX_DEPLOYMENT_TARGET'] = deployment_target |
500 | 525 |
501 cmake_args = base_cmake_args + [ | 526 cmake_args = [] |
| 527 # TODO(thakis): Unconditionally append this to base_cmake_args instead once |
| 528 # compiler-rt can build with clang-cl on Windows (http://llvm.org/PR23698) |
| 529 cc_args = base_cmake_args if sys.platform != 'win32' else cmake_args |
| 530 if cc is not None: cc_args.append('-DCMAKE_C_COMPILER=' + cc) |
| 531 if cxx is not None: cc_args.append('-DCMAKE_CXX_COMPILER=' + cxx) |
| 532 cmake_args += base_cmake_args + [ |
502 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, | 533 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, |
503 '-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly', | 534 '-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly', |
504 '-DCMAKE_C_FLAGS=' + ' '.join(cflags), | 535 '-DCMAKE_C_FLAGS=' + ' '.join(cflags), |
505 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags), | 536 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags), |
506 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags), | 537 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags), |
507 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags), | 538 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags), |
508 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags), | 539 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags), |
509 '-DCMAKE_INSTALL_PREFIX=' + LLVM_BUILD_DIR, | 540 '-DCMAKE_INSTALL_PREFIX=' + LLVM_BUILD_DIR, |
510 '-DCHROMIUM_TOOLS_SRC=%s' % os.path.join(CHROMIUM_DIR, 'tools', 'clang'), | 541 '-DCHROMIUM_TOOLS_SRC=%s' % os.path.join(CHROMIUM_DIR, 'tools', 'clang'), |
511 '-DCHROMIUM_TOOLS=%s' % ';'.join(args.tools)] | 542 '-DCHROMIUM_TOOLS=%s' % ';'.join(args.tools)] |
512 # TODO(thakis): Unconditionally append this to base_cmake_args instead once | |
513 # compiler-rt can build with clang-cl on Windows (http://llvm.org/PR23698) | |
514 cc_args = base_cmake_args if sys.platform != 'win32' else cmake_args | |
515 if cc is not None: cc_args.append('-DCMAKE_C_COMPILER=' + cc) | |
516 if cxx is not None: cc_args.append('-DCMAKE_CXX_COMPILER=' + cxx) | |
517 | 543 |
518 if not os.path.exists(LLVM_BUILD_DIR): | 544 if not os.path.exists(LLVM_BUILD_DIR): |
519 os.makedirs(LLVM_BUILD_DIR) | 545 os.makedirs(LLVM_BUILD_DIR) |
520 os.chdir(LLVM_BUILD_DIR) | 546 os.chdir(LLVM_BUILD_DIR) |
521 RunCommand(['cmake'] + cmake_args + [LLVM_DIR], | 547 RunCommand(['cmake'] + cmake_args + [LLVM_DIR], |
522 msvc_arch='x64', env=deployment_env) | 548 msvc_arch='x64', env=deployment_env) |
523 | 549 |
524 if args.gcc_toolchain: | 550 if args.gcc_toolchain: |
525 # Copy in the right stdlibc++.so.6 so clang can start. | 551 # Copy in the right stdlibc++.so.6 so clang can start. |
526 if not os.path.exists(os.path.join(LLVM_BUILD_DIR, 'lib')): | 552 if not os.path.exists(os.path.join(LLVM_BUILD_DIR, 'lib')): |
527 os.mkdir(os.path.join(LLVM_BUILD_DIR, 'lib')) | 553 os.mkdir(os.path.join(LLVM_BUILD_DIR, 'lib')) |
528 libstdcpp = subprocess.check_output( | 554 libstdcpp = subprocess.check_output( |
529 [cxx] + cxxflags + ['-print-file-name=libstdc++.so.6']).rstrip() | 555 [cxx] + cxxflags + ['-print-file-name=libstdc++.so.6']).rstrip() |
530 CopyFile(libstdcpp, os.path.join(LLVM_BUILD_DIR, 'lib')) | 556 CopyFile(libstdcpp, os.path.join(LLVM_BUILD_DIR, 'lib')) |
531 | 557 |
532 RunCommand(['ninja'], msvc_arch='x64') | 558 RunCommand(['ninja'], msvc_arch='x64') |
533 | 559 |
534 if args.tools: | 560 if args.tools: |
535 # If any Chromium tools were built, install those now. | 561 # If any Chromium tools were built, install those now. |
536 RunCommand(['ninja', 'cr-install'], msvc_arch='x64') | 562 RunCommand(['ninja', 'cr-install'], msvc_arch='x64') |
537 | 563 |
538 if sys.platform == 'darwin': | 564 if sys.platform == 'darwin': |
539 CopyFile(os.path.join(LLVM_BUILD_DIR, 'libc++.1.dylib'), | 565 CopyFile(os.path.join(libcxxbuild, 'libc++.1.dylib'), |
540 os.path.join(LLVM_BUILD_DIR, 'bin')) | 566 os.path.join(LLVM_BUILD_DIR, 'bin')) |
541 # See http://crbug.com/256342 | 567 # See http://crbug.com/256342 |
542 RunCommand(['strip', '-x', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')]) | 568 RunCommand(['strip', '-x', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')]) |
543 elif sys.platform.startswith('linux'): | 569 elif sys.platform.startswith('linux'): |
544 RunCommand(['strip', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')]) | 570 RunCommand(['strip', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')]) |
545 | 571 |
546 # Do an x86 build of compiler-rt to get the 32-bit ASan run-time. | 572 # Do an out-of-tree build of compiler-rt. |
| 573 # On Windows, this is used to get the 32-bit ASan run-time. |
547 # TODO(hans): Remove once the regular build above produces this. | 574 # TODO(hans): Remove once the regular build above produces this. |
548 if not os.path.exists(COMPILER_RT_BUILD_DIR): | 575 # On Mac and Linux, this is used to get the regular 64-bit run-time. |
549 os.makedirs(COMPILER_RT_BUILD_DIR) | 576 # Do a clobbered build due to cmake changes. |
| 577 if os.path.isdir(COMPILER_RT_BUILD_DIR): |
| 578 RmTree(COMPILER_RT_BUILD_DIR) |
| 579 os.makedirs(COMPILER_RT_BUILD_DIR) |
550 os.chdir(COMPILER_RT_BUILD_DIR) | 580 os.chdir(COMPILER_RT_BUILD_DIR) |
551 # TODO(thakis): Add this once compiler-rt can build with clang-cl (see | 581 # TODO(thakis): Add this once compiler-rt can build with clang-cl (see |
552 # above). | 582 # above). |
553 #if args.bootstrap and sys.platform == 'win32': | 583 #if args.bootstrap and sys.platform == 'win32': |
554 # The bootstrap compiler produces 64-bit binaries by default. | 584 # The bootstrap compiler produces 64-bit binaries by default. |
555 #cflags += ['-m32'] | 585 #cflags += ['-m32'] |
556 #cxxflags += ['-m32'] | 586 #cxxflags += ['-m32'] |
557 compiler_rt_args = base_cmake_args + [ | 587 compiler_rt_args = base_cmake_args + [ |
558 '-DCMAKE_C_FLAGS=' + ' '.join(cflags), | 588 '-DCMAKE_C_FLAGS=' + ' '.join(cflags), |
559 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags)] | 589 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags)] |
560 if sys.platform != 'win32': | 590 if sys.platform != 'win32': |
561 compiler_rt_args += ['-DLLVM_CONFIG_PATH=' + | 591 compiler_rt_args += ['-DLLVM_CONFIG_PATH=' + |
562 os.path.join(LLVM_BUILD_DIR, 'bin', 'llvm-config'), | 592 os.path.join(LLVM_BUILD_DIR, 'bin', 'llvm-config'), |
563 '-DSANITIZER_MIN_OSX_VERSION="10.7"'] | 593 '-DSANITIZER_MIN_OSX_VERSION="10.7"'] |
564 RunCommand(['cmake'] + compiler_rt_args + [LLVM_DIR], | 594 # compiler-rt is part of the llvm checkout on Windows but a stand-alone |
565 msvc_arch='x86', env=deployment_env) | 595 # directory elsewhere, see the TODO above COMPILER_RT_DIR. |
| 596 RunCommand(['cmake'] + compiler_rt_args + |
| 597 [LLVM_DIR if sys.platform == 'win32' else COMPILER_RT_DIR], |
| 598 msvc_arch='x86', env=deployment_env) |
566 RunCommand(['ninja', 'compiler-rt'], msvc_arch='x86') | 599 RunCommand(['ninja', 'compiler-rt'], msvc_arch='x86') |
567 | 600 |
| 601 # Copy select output to the main tree. |
568 # TODO(hans): Make this (and the .gypi and .isolate files) version number | 602 # TODO(hans): Make this (and the .gypi and .isolate files) version number |
569 # independent. | 603 # independent. |
570 if sys.platform == 'win32': | 604 if sys.platform == 'win32': |
571 platform = 'windows' | 605 platform = 'windows' |
572 elif sys.platform == 'darwin': | 606 elif sys.platform == 'darwin': |
573 platform = 'darwin' | 607 platform = 'darwin' |
574 else: | 608 else: |
575 assert sys.platform.startswith('linux') | 609 assert sys.platform.startswith('linux') |
576 platform = 'linux' | 610 platform = 'linux' |
577 asan_rt_lib_src_dir = os.path.join(COMPILER_RT_BUILD_DIR, 'lib', 'clang', | 611 asan_rt_lib_src_dir = os.path.join(COMPILER_RT_BUILD_DIR, 'lib', platform) |
578 VERSION, 'lib', platform) | 612 if sys.platform == 'win32': |
| 613 # TODO(thakis): This too is due to compiler-rt being part of the checkout |
| 614 # on Windows, see TODO above COMPILER_RT_DIR. |
| 615 asan_rt_lib_src_dir = os.path.join(COMPILER_RT_BUILD_DIR, 'lib', 'clang', |
| 616 VERSION, 'lib', platform) |
579 asan_rt_lib_dst_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang', | 617 asan_rt_lib_dst_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang', |
580 VERSION, 'lib', platform) | 618 VERSION, 'lib', platform) |
581 CopyDirectoryContents(asan_rt_lib_src_dir, asan_rt_lib_dst_dir, | 619 # Blacklists: |
582 r'^.*-i386\.lib$') | 620 CopyDirectoryContents(os.path.join(asan_rt_lib_src_dir, '..', '..'), |
583 CopyDirectoryContents(asan_rt_lib_src_dir, asan_rt_lib_dst_dir, | 621 os.path.join(asan_rt_lib_dst_dir, '..', '..'), |
584 r'^.*-i386\.dll$') | 622 r'^.*blacklist\.txt$') |
| 623 # Headers: |
| 624 if sys.platform != 'win32': |
| 625 CopyDirectoryContents( |
| 626 os.path.join(COMPILER_RT_BUILD_DIR, 'include/sanitizer'), |
| 627 os.path.join(LLVM_BUILD_DIR, 'lib/clang', VERSION, 'include/sanitizer')) |
| 628 # Static and dynamic libraries: |
| 629 CopyDirectoryContents(asan_rt_lib_src_dir, asan_rt_lib_dst_dir) |
585 | 630 |
586 CopyFile(os.path.join(asan_rt_lib_src_dir, '..', '..', 'asan_blacklist.txt'), | |
587 os.path.join(asan_rt_lib_dst_dir, '..', '..')) | |
588 | 631 |
589 if sys.platform == 'win32': | 632 if sys.platform == 'win32': |
590 # Make an extra copy of the sanitizer headers, to be put on the include path | 633 # Make an extra copy of the sanitizer headers, to be put on the include path |
591 # of the fallback compiler. | 634 # of the fallback compiler. |
592 sanitizer_include_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang', | 635 sanitizer_include_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang', |
593 VERSION, 'include', 'sanitizer') | 636 VERSION, 'include', 'sanitizer') |
594 aux_sanitizer_include_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang', | 637 aux_sanitizer_include_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang', |
595 VERSION, 'include_sanitizer', | 638 VERSION, 'include_sanitizer', |
596 'sanitizer') | 639 'sanitizer') |
597 if not os.path.exists(aux_sanitizer_include_dir): | 640 if not os.path.exists(aux_sanitizer_include_dir): |
598 os.makedirs(aux_sanitizer_include_dir) | 641 os.makedirs(aux_sanitizer_include_dir) |
599 for _, _, files in os.walk(sanitizer_include_dir): | 642 for _, _, files in os.walk(sanitizer_include_dir): |
600 for f in files: | 643 for f in files: |
601 CopyFile(os.path.join(sanitizer_include_dir, f), | 644 CopyFile(os.path.join(sanitizer_include_dir, f), |
602 aux_sanitizer_include_dir) | 645 aux_sanitizer_include_dir) |
603 | 646 |
| 647 if args.with_android: |
| 648 make_toolchain = os.path.join( |
| 649 ANDROID_NDK_DIR, 'build', 'tools', 'make-standalone-toolchain.sh') |
| 650 for target_arch in ['aarch64', 'arm', 'i686']: |
| 651 # Make standalone Android toolchain for target_arch. |
| 652 toolchain_dir = os.path.join( |
| 653 LLVM_BUILD_DIR, 'android-toolchain-' + target_arch) |
| 654 RunCommand([ |
| 655 make_toolchain, |
| 656 '--platform=android-' + ('21' if target_arch == 'aarch64' else '19'), |
| 657 '--install-dir="%s"' % toolchain_dir, |
| 658 '--system=linux-x86_64', |
| 659 '--stl=stlport', |
| 660 '--toolchain=' + { |
| 661 'aarch64': 'aarch64-linux-android-4.9', |
| 662 'arm': 'arm-linux-androideabi-4.9', |
| 663 'i686': 'x86-4.9', |
| 664 }[target_arch]]) |
| 665 # Android NDK r9d copies a broken unwind.h into the toolchain, see |
| 666 # http://crbug.com/357890 |
| 667 for f in glob.glob(os.path.join(toolchain_dir, 'include/c++/*/unwind.h')): |
| 668 os.remove(f) |
| 669 |
| 670 # Build ASan runtime for Android in a separate build tree. |
| 671 build_dir = os.path.join(LLVM_BUILD_DIR, 'android-' + target_arch) |
| 672 if not os.path.exists(build_dir): |
| 673 os.mkdir(os.path.join(build_dir)) |
| 674 os.chdir(build_dir) |
| 675 if os.path.exists('CMakeCache.txt'): |
| 676 os.remove('CMakeCache.txt') |
| 677 |
| 678 cflags = ['--target=%s-linux-androideabi' % target_arch, |
| 679 '--sysroot=%s/sysroot' % toolchain_dir, |
| 680 '-B%s' % toolchain_dir] |
| 681 android_args = base_cmake_args + [ |
| 682 '-DCMAKE_C_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang'), |
| 683 '-DCMAKE_CXX_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang++'), |
| 684 '-DLLVM_CONFIG_PATH=' + os.path.join(LLVM_BUILD_DIR, 'bin/llvm-config'), |
| 685 '-DCMAKE_C_FLAGS=' + ' '.join(cflags), |
| 686 '-DCMAKE_CXX_FLAGS=' + ' '.join(cflags), |
| 687 '-DANDROID=1'] |
| 688 RunCommand(['cmake'] + android_args + [COMPILER_RT_DIR]) |
| 689 RunCommand(['ninja', 'libclang_rt.asan-%s-android.so' % target_arch]) |
| 690 |
| 691 # And copy it into the main build tree. |
| 692 runtime = 'libclang_rt.asan-%s-android.so' % target_arch |
| 693 for root, _, files in os.walk(build_dir): |
| 694 if runtime in files: |
| 695 shutil.copy(os.path.join(root, runtime), asan_rt_lib_dst_dir) |
| 696 |
604 # Run tests. | 697 # Run tests. |
605 if args.run_tests or use_head_revision: | 698 if args.run_tests or use_head_revision: |
606 os.chdir(LLVM_BUILD_DIR) | 699 os.chdir(LLVM_BUILD_DIR) |
607 RunCommand(GetVSVersion().SetupScript('x64') + | 700 RunCommand(['ninja', 'cr-check-all'], msvc_arch='x64') |
608 ['&&', 'ninja', 'cr-check-all']) | |
609 if args.run_tests: | 701 if args.run_tests: |
610 os.chdir(LLVM_BUILD_DIR) | 702 os.chdir(LLVM_BUILD_DIR) |
611 RunCommand(GetVSVersion().SetupScript('x64') + | 703 RunCommand(['ninja', 'check-all'], msvc_arch='x64') |
612 ['&&', 'ninja', 'check-all']) | |
613 | 704 |
614 WriteStampFile(PACKAGE_VERSION) | 705 WriteStampFile(PACKAGE_VERSION) |
615 print 'Clang update was successful.' | 706 print 'Clang update was successful.' |
616 return 0 | 707 return 0 |
617 | 708 |
618 | 709 |
619 def main(): | 710 def main(): |
620 if not sys.platform in ['win32', 'cygwin']: | 711 if not sys.platform in ['win32', 'cygwin']: |
621 # For non-Windows, fall back to update.sh. | 712 # For non-Windows, fall back to update.sh. |
622 # TODO(hans): Make update.py replace update.sh completely. | 713 # TODO(hans): Make update.py replace update.sh completely. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 'picks /opt/foo/bin/gcc') | 745 'picks /opt/foo/bin/gcc') |
655 parser.add_argument('--print-revision', action='store_true', | 746 parser.add_argument('--print-revision', action='store_true', |
656 help='print current clang revision and exit.') | 747 help='print current clang revision and exit.') |
657 parser.add_argument('--print-clang-version', action='store_true', | 748 parser.add_argument('--print-clang-version', action='store_true', |
658 help='print current clang version (e.g. x.y.z) and exit.') | 749 help='print current clang version (e.g. x.y.z) and exit.') |
659 parser.add_argument('--run-tests', action='store_true', | 750 parser.add_argument('--run-tests', action='store_true', |
660 help='run tests after building; only for local builds') | 751 help='run tests after building; only for local builds') |
661 parser.add_argument('--tools', nargs='*', | 752 parser.add_argument('--tools', nargs='*', |
662 help='select which chrome tools to build', | 753 help='select which chrome tools to build', |
663 default=['plugins', 'blink_gc_plugin']) | 754 default=['plugins', 'blink_gc_plugin']) |
| 755 parser.add_argument('--without-android', action='store_false', |
| 756 help='don\tt build Android ASan runtime (linux only)', |
| 757 dest='with_android', |
| 758 default=sys.platform.startswith('linux')) |
664 | 759 |
665 # For now, these flags are only used for the non-Windows flow, but argparser | 760 # For now, these flags are only used for the non-Windows flow, but argparser |
666 # gets mad if it sees a flag it doesn't recognize. | 761 # gets mad if it sees a flag it doesn't recognize. |
667 parser.add_argument('--no-stdin-hack', action='store_true') | 762 parser.add_argument('--no-stdin-hack', action='store_true') |
668 | 763 |
669 args = parser.parse_args() | 764 args = parser.parse_args() |
670 | 765 |
671 if args.if_needed: | 766 if args.if_needed: |
672 is_clang_required = False | 767 is_clang_required = False |
673 # clang is always used on Mac and Linux. | 768 # clang is always used on Mac and Linux. |
(...skipping 30 matching lines...) Expand all Loading... |
704 # an error message when this script is run from gn for some reason. | 799 # an error message when this script is run from gn for some reason. |
705 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) | 800 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) |
706 | 801 |
707 if use_head_revision: | 802 if use_head_revision: |
708 # Use a real revision number rather than HEAD to make sure that the stamp | 803 # Use a real revision number rather than HEAD to make sure that the stamp |
709 # file logic works. | 804 # file logic works. |
710 LLVM_WIN_REVISION = GetSvnRevision(LLVM_REPO_URL) | 805 LLVM_WIN_REVISION = GetSvnRevision(LLVM_REPO_URL) |
711 PACKAGE_VERSION = LLVM_WIN_REVISION + '-0' | 806 PACKAGE_VERSION = LLVM_WIN_REVISION + '-0' |
712 | 807 |
713 args.force_local_build = True | 808 args.force_local_build = True |
| 809 if 'OS=android' not in os.environ.get('GYP_DEFINES', ''): |
| 810 # Only build the Android ASan rt on ToT bots when targetting Android. |
| 811 args.with_android = False |
714 | 812 |
715 return UpdateClang(args) | 813 return UpdateClang(args) |
716 | 814 |
717 | 815 |
718 if __name__ == '__main__': | 816 if __name__ == '__main__': |
719 sys.exit(main()) | 817 sys.exit(main()) |
OLD | NEW |