diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/tools/clang/scripts/build.py | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/tools/clang/scripts/build.py')
-rwxr-xr-x | chromium/tools/clang/scripts/build.py | 102 |
1 files changed, 49 insertions, 53 deletions
diff --git a/chromium/tools/clang/scripts/build.py b/chromium/tools/clang/scripts/build.py index 2425e0b705b..3f2af8b3cf9 100755 --- a/chromium/tools/clang/scripts/build.py +++ b/chromium/tools/clang/scripts/build.py @@ -14,6 +14,7 @@ from __future__ import print_function import argparse import glob +import io import json import os import pipes @@ -215,7 +216,7 @@ def CreateChromeToolsShim(): tool detection logic munges them in a weird way.""" assert not any(i in os.path.basename(CHROME_TOOLS_SHIM_DIR) for i in '-_') os.mkdir(CHROME_TOOLS_SHIM_DIR) - with file(os.path.join(CHROME_TOOLS_SHIM_DIR, 'CMakeLists.txt'), 'w') as f: + with open(os.path.join(CHROME_TOOLS_SHIM_DIR, 'CMakeLists.txt'), 'w') as f: f.write('# Automatically generated by tools/clang/scripts/update.py. ' + 'Do not edit.\n') f.write('# Since tools/clang is located in another directory, use the \n') @@ -326,7 +327,8 @@ def VerifyVersionOfBuiltClangMatchesVERSION(): clang = os.path.join(LLVM_BUILD_DIR, 'bin', 'clang') if sys.platform == 'win32': clang += '-cl.exe' - version_out = subprocess.check_output([clang, '--version']) + version_out = subprocess.check_output([clang, '--version'], + universal_newlines=True) version_out = re.match(r'clang version ([0-9.]+)', version_out).group(1) if version_out != RELEASE_VERSION: print(('unexpected clang version %s (not %s), ' @@ -339,33 +341,29 @@ def CopyLibstdcpp(args, build_dir): if not args.gcc_toolchain: return # Find libstdc++.so.6 - libstdcpp = subprocess.check_output( - [os.path.join(args.gcc_toolchain, 'bin', 'g++'), - '-print-file-name=libstdc++.so.6']).rstrip() + libstdcpp = subprocess.check_output([ + os.path.join(args.gcc_toolchain, 'bin', 'g++'), + '-print-file-name=libstdc++.so.6' + ], + universal_newlines=True).rstrip() # Copy libstdc++.so.6 into the build dir so that the built binaries can find # it. Binaries get their rpath set to $origin/../lib/. For clang, lld, # etc. that live in the bin/ directory, this means they expect to find the .so - # in their neighbouring lib/ dir. For other tools however, this doesn't work - # since those exeuctables are spread out into different directories. - # TODO(hans): Unit tests don't get rpath set at all, unittests/ copying - # below doesn't help at the moment. + # in their neighbouring lib/ dir. + # For unit tests we pass -Wl,-rpath to the linker pointing to the lib64 dir + # in the gcc toolchain, via LLVM_LOCAL_RPATH below. + # The two fuzzer tests are weird in that they copy the fuzzer binary from bin/ + # into the test tree under a different name. To make the relative rpath in + # them work, copy libstdc++ to the copied location for now. + # TODO(thakis): Instead, make the upstream lit.local.cfg.py for these 2 tests + # check if the binary contains an rpath and if so disable the tests. for d in ['lib', 'test/tools/llvm-isel-fuzzer/lib', - 'test/tools/llvm-opt-fuzzer/lib', - 'unittests/CodeGen/lib', - 'unittests/DebugInfo/lib', - 'unittests/ExecutionEngine/lib', - 'unittests/Support/lib', - 'unittests/Target/lib', - 'unittests/Transforms/lib', - 'unittests/lib', - 'unittests/tools/lib', - 'unittests/tools/llvm-exegesis/lib']: + 'test/tools/llvm-opt-fuzzer/lib']: EnsureDirExists(os.path.join(build_dir, d)) CopyFile(libstdcpp, os.path.join(build_dir, d)) - def gn_arg(v): if v == 'True': return True @@ -437,7 +435,16 @@ def main(): # Don't buffer stdout, so that print statements are immediately flushed. - sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) + # LLVM tests print output without newlines, so with buffering they won't be + # immediately printed. + major, _, _, _, _ = sys.version_info + if major == 3: + # Python3 only allows unbuffered output for binary streams. This + # workaround comes from https://stackoverflow.com/a/181654/4052492. + sys.stdout = io.TextIOWrapper(open(sys.stdout.fileno(), 'wb', 0), + write_through=True) + else: + sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) # The gnuwin package also includes curl, which is needed to interact with the # github API below. @@ -478,14 +485,6 @@ def main(): # LLVM_ENABLE_LLD). cc, cxx, lld = None, None, None - if args.gcc_toolchain: - # Use the specified gcc installation for building. - cc = os.path.join(args.gcc_toolchain, 'bin', 'gcc') - cxx = os.path.join(args.gcc_toolchain, 'bin', 'g++') - if not os.access(cc, os.X_OK): - print('Invalid --gcc-toolchain: ' + args.gcc_toolchain) - return 1 - cflags = [] cxxflags = [] ldflags = [] @@ -519,6 +518,18 @@ def main(): '-DLLVM_INCLUDE_GO_TESTS=OFF', ] + if args.gcc_toolchain: + # Use the specified gcc installation for building. + cc = os.path.join(args.gcc_toolchain, 'bin', 'gcc') + cxx = os.path.join(args.gcc_toolchain, 'bin', 'g++') + if not os.access(cc, os.X_OK): + print('Invalid --gcc-toolchain: ' + args.gcc_toolchain) + return 1 + base_cmake_args += [ + '-DLLVM_LOCAL_RPATH=' + os.path.join(args.gcc_toolchain, 'lib64') + ] + + if sys.platform == 'darwin': # For libc++, we only want the headers. base_cmake_args.extend([ @@ -531,7 +542,7 @@ def main(): if args.gcc_toolchain: # Don't use the custom gcc toolchain when building compiler-rt tests; those # tests are built with the just-built Clang, and target both i386 and x86_64 - # for example, so should ust the system's libstdc++. + # for example, so should use the system's libstdc++. base_cmake_args.append( '-DCOMPILER_RT_TEST_COMPILER_CFLAGS=--gcc-toolchain=') @@ -867,28 +878,10 @@ def main(): CopyDirectoryContents(rt_lib_src_dir, rt_lib_dst_dir) if args.with_android: - make_toolchain = os.path.join( - ANDROID_NDK_DIR, 'build', 'tools', 'make_standalone_toolchain.py') # TODO(thakis): Now that the NDK uses clang, try to build all archs in - # one LLVM build instead of making 3 different toolchains and building - # 3 times. + # one LLVM build instead of building 3 times. + toolchain_dir = ANDROID_NDK_DIR + '/toolchains/llvm/prebuilt/linux-x86_64' for target_arch in ['aarch64', 'arm', 'i686']: - # Make standalone Android toolchain for target_arch. - toolchain_dir = os.path.join( - LLVM_BUILD_DIR, 'android-toolchain-' + target_arch) - api_level = '21' if target_arch == 'aarch64' else '19' - RunCommand([ - make_toolchain, - '--api=' + api_level, - '--force', - '--install-dir=%s' % toolchain_dir, - '--stl=libc++', - '--arch=' + { - 'aarch64': 'arm64', - 'arm': 'arm', - 'i686': 'x86', - }[target_arch]]) - # Build compiler-rt runtimes needed for Android in a separate build tree. build_dir = os.path.join(LLVM_BUILD_DIR, 'android-' + target_arch) if not os.path.exists(build_dir): @@ -897,10 +890,13 @@ def main(): target_triple = target_arch if target_arch == 'arm': target_triple = 'armv7' + api_level = '21' if target_arch == 'aarch64' else '19' target_triple += '-linux-android' + api_level - cflags = ['--target=%s' % target_triple, - '--sysroot=%s/sysroot' % toolchain_dir, - '-B%s' % toolchain_dir] + cflags = [ + '--target=' + target_triple, + '--sysroot=%s/sysroot' % toolchain_dir, + '--gcc-toolchain=' + toolchain_dir, + ] android_args = base_cmake_args + [ '-DCMAKE_C_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang'), '-DCMAKE_CXX_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang++'), |