| 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 """This script is used to download prebuilt clang binaries. | 6 """This script is used to download prebuilt clang binaries. |
| 7 | 7 |
| 8 It is also used by package.py to build the prebuilt clang binaries.""" | 8 It is also used by package.py to build the prebuilt clang binaries.""" |
| 9 | 9 |
| 10 import argparse | 10 import argparse |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'compiler-rt') | 62 COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'compiler-rt') |
| 63 LIBCXX_DIR = os.path.join(LLVM_DIR, 'projects', 'libcxx') | 63 LIBCXX_DIR = os.path.join(LLVM_DIR, 'projects', 'libcxx') |
| 64 LIBCXXABI_DIR = os.path.join(LLVM_DIR, 'projects', 'libcxxabi') | 64 LIBCXXABI_DIR = os.path.join(LLVM_DIR, 'projects', 'libcxxabi') |
| 65 LLVM_BUILD_TOOLS_DIR = os.path.abspath( | 65 LLVM_BUILD_TOOLS_DIR = os.path.abspath( |
| 66 os.path.join(LLVM_DIR, '..', 'llvm-build-tools')) | 66 os.path.join(LLVM_DIR, '..', 'llvm-build-tools')) |
| 67 STAMP_FILE = os.path.normpath( | 67 STAMP_FILE = os.path.normpath( |
| 68 os.path.join(LLVM_DIR, '..', 'llvm-build', 'cr_build_revision')) | 68 os.path.join(LLVM_DIR, '..', 'llvm-build', 'cr_build_revision')) |
| 69 BINUTILS_DIR = os.path.join(THIRD_PARTY_DIR, 'binutils') | 69 BINUTILS_DIR = os.path.join(THIRD_PARTY_DIR, 'binutils') |
| 70 BINUTILS_BIN_DIR = os.path.join(BINUTILS_DIR, BINUTILS_DIR, | 70 BINUTILS_BIN_DIR = os.path.join(BINUTILS_DIR, BINUTILS_DIR, |
| 71 'Linux_x64', 'Release', 'bin') | 71 'Linux_x64', 'Release', 'bin') |
| 72 BFD_PLUGINS_DIR = os.path.join(BINUTILS_DIR, 'Linux_x64', 'Release', |
| 73 'lib', 'bfd-plugins') |
| 72 VERSION = '4.0.0' | 74 VERSION = '4.0.0' |
| 73 ANDROID_NDK_DIR = os.path.join( | 75 ANDROID_NDK_DIR = os.path.join( |
| 74 CHROMIUM_DIR, 'third_party', 'android_tools', 'ndk') | 76 CHROMIUM_DIR, 'third_party', 'android_tools', 'ndk') |
| 75 | 77 |
| 76 # URL for pre-built binaries. | 78 # URL for pre-built binaries. |
| 77 CDS_URL = os.environ.get('CDS_CLANG_BUCKET_OVERRIDE', | 79 CDS_URL = os.environ.get('CDS_CLANG_BUCKET_OVERRIDE', |
| 78 'https://commondatastorage.googleapis.com/chromium-browser-clang') | 80 'https://commondatastorage.googleapis.com/chromium-browser-clang') |
| 79 | 81 |
| 80 LLVM_REPO_URL='https://llvm.org/svn/llvm-project' | 82 LLVM_REPO_URL='https://llvm.org/svn/llvm-project' |
| 81 if 'LLVM_REPO_URL' in os.environ: | 83 if 'LLVM_REPO_URL' in os.environ: |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 | 550 |
| 549 # Build LLVM gold plugin with LTO. That speeds up the linker by ~10%. | 551 # Build LLVM gold plugin with LTO. That speeds up the linker by ~10%. |
| 550 # We only use LTO for Linux now. | 552 # We only use LTO for Linux now. |
| 551 if args.bootstrap and args.lto_gold_plugin: | 553 if args.bootstrap and args.lto_gold_plugin: |
| 552 print 'Building LTO LLVM Gold plugin' | 554 print 'Building LTO LLVM Gold plugin' |
| 553 if os.path.exists(LLVM_LTO_GOLD_PLUGIN_DIR): | 555 if os.path.exists(LLVM_LTO_GOLD_PLUGIN_DIR): |
| 554 RmTree(LLVM_LTO_GOLD_PLUGIN_DIR) | 556 RmTree(LLVM_LTO_GOLD_PLUGIN_DIR) |
| 555 EnsureDirExists(LLVM_LTO_GOLD_PLUGIN_DIR) | 557 EnsureDirExists(LLVM_LTO_GOLD_PLUGIN_DIR) |
| 556 os.chdir(LLVM_LTO_GOLD_PLUGIN_DIR) | 558 os.chdir(LLVM_LTO_GOLD_PLUGIN_DIR) |
| 557 | 559 |
| 560 # Create a symlink to LLVMgold.so build in the previous step so that ar |
| 561 # and ranlib could find it while linking LLVMgold.so with LTO. |
| 562 EnsureDirExists(BFD_PLUGINS_DIR) |
| 563 RunCommand(['ln', '-sf', |
| 564 os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'lib', 'LLVMgold.so'), |
| 565 os.path.join(BFD_PLUGINS_DIR, 'LLVMgold.so')]) |
| 566 |
| 558 lto_cflags = ['-flto'] | 567 lto_cflags = ['-flto'] |
| 559 lto_ldflags = ['-fuse-ld=lld'] | 568 lto_ldflags = ['-fuse-ld=gold'] |
| 560 if args.gcc_toolchain: | 569 if args.gcc_toolchain: |
| 561 # Tell the bootstrap compiler to use a specific gcc prefix to search | 570 # Tell the bootstrap compiler to use a specific gcc prefix to search |
| 562 # for standard library headers and shared object files. | 571 # for standard library headers and shared object files. |
| 563 lto_cflags += ['--gcc-toolchain=' + args.gcc_toolchain] | 572 lto_cflags += ['--gcc-toolchain=' + args.gcc_toolchain] |
| 564 lto_cmake_args = base_cmake_args + [ | 573 lto_cmake_args = base_cmake_args + [ |
| 565 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, | 574 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, |
| 566 '-DCMAKE_AR=' + os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, | |
| 567 'bin', 'llvm-ar'), | |
| 568 '-DCMAKE_RANLIB=' + os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, | |
| 569 'bin', 'llvm-ranlib'), | |
| 570 '-DLLVM_ENABLE_LTO=ON', | |
| 571 '-DCMAKE_C_COMPILER=' + cc, | 575 '-DCMAKE_C_COMPILER=' + cc, |
| 572 '-DCMAKE_CXX_COMPILER=' + cxx, | 576 '-DCMAKE_CXX_COMPILER=' + cxx, |
| 573 '-DCMAKE_C_FLAGS=' + ' '.join(lto_cflags), | 577 '-DCMAKE_C_FLAGS=' + ' '.join(lto_cflags), |
| 574 '-DCMAKE_CXX_FLAGS=' + ' '.join(lto_cflags + ['-std=c++11']), | 578 '-DCMAKE_CXX_FLAGS=' + ' '.join(lto_cflags), |
| 575 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(lto_ldflags), | 579 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(lto_ldflags), |
| 576 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(lto_ldflags), | 580 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(lto_ldflags), |
| 577 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(lto_ldflags)] | 581 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(lto_ldflags)] |
| 578 | 582 |
| 583 # We need to use the proper binutils which support LLVM Gold plugin. |
| 584 lto_env = os.environ.copy() |
| 585 lto_env['PATH'] = BINUTILS_BIN_DIR + os.pathsep + lto_env.get('PATH', '') |
| 586 |
| 579 RmCmakeCache('.') | 587 RmCmakeCache('.') |
| 580 RunCommand(['cmake'] + lto_cmake_args + [LLVM_DIR]) | 588 RunCommand(['cmake'] + lto_cmake_args + [LLVM_DIR], env=lto_env) |
| 581 RunCommand(['ninja', 'LLVMgold']) | 589 RunCommand(['ninja', 'LLVMgold'], env=lto_env) |
| 582 | 590 |
| 583 | 591 |
| 584 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is | 592 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is |
| 585 # needed, on OS X it requires libc++. clang only automatically links to libc++ | 593 # needed, on OS X it requires libc++. clang only automatically links to libc++ |
| 586 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run | 594 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run |
| 587 # on OS X versions as old as 10.7. | 595 # on OS X versions as old as 10.7. |
| 588 deployment_target = '' | 596 deployment_target = '' |
| 589 | 597 |
| 590 if sys.platform == 'darwin' and args.bootstrap: | 598 if sys.platform == 'darwin' and args.bootstrap: |
| 591 # When building on 10.9, /usr/include usually doesn't exist, and while | 599 # When building on 10.9, /usr/include usually doesn't exist, and while |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 args.force_local_build = True | 903 args.force_local_build = True |
| 896 if 'OS=android' not in os.environ.get('GYP_DEFINES', ''): | 904 if 'OS=android' not in os.environ.get('GYP_DEFINES', ''): |
| 897 # Only build the Android ASan rt on ToT bots when targetting Android. | 905 # Only build the Android ASan rt on ToT bots when targetting Android. |
| 898 args.with_android = False | 906 args.with_android = False |
| 899 | 907 |
| 900 return UpdateClang(args) | 908 return UpdateClang(args) |
| 901 | 909 |
| 902 | 910 |
| 903 if __name__ == '__main__': | 911 if __name__ == '__main__': |
| 904 sys.exit(main()) | 912 sys.exit(main()) |
| OLD | NEW |