1 #!/usr/bin/env python 2 # 3 # Copyright 2016 Google Inc. 4 # 5 # Use of this source code is governed by a BSD-style license that can be 6 # found in the LICENSE file. 7 8 9 """Create a Clang toolchain for Linux hosts.""" 10 11 12 import argparse 13 import os 14 import subprocess 15 import tempfile 16 17 REPO = "https://llvm.googlesource.com/" 18 BRANCH = "release_39" 19 20 def create_asset(target_dir): 21 # Build Clang, lld, compiler-rt (sanitizer support) and libc++. 22 os.chdir(tempfile.mkdtemp()) 23 subprocess.check_call(["git", "clone", "-b", BRANCH, REPO + "llvm"]) 24 os.chdir("llvm/tools") 25 subprocess.check_call(["git", "clone", "-b", BRANCH, REPO + "clang"]) 26 subprocess.check_call(["git", "clone", "-b", BRANCH, REPO + "lld"]) 27 os.chdir("../projects") 28 subprocess.check_call(["git", "clone", "-b", BRANCH, REPO + "compiler-rt"]) 29 subprocess.check_call(["git", "clone", "-b", BRANCH, REPO + "libcxx"]) 30 subprocess.check_call(["git", "clone", "-b", BRANCH, REPO + "libcxxabi"]) 31 os.chdir("..") 32 os.mkdir("out") 33 os.chdir("out") 34 subprocess.check_call(["cmake", "..", "-G", "Ninja", 35 "-DCMAKE_BUILD_TYPE=MinSizeRel", 36 "-DCMAKE_INSTALL_PREFIX=" + target_dir, 37 "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON", 38 "-DLLVM_ENABLE_TERMINFO=OFF"]) 39 subprocess.check_call(["ninja", "install"]) 40 41 # Copy a couple extra files we need. 42 subprocess.check_call(["cp", "bin/llvm-symbolizer", target_dir + "/bin"]) 43 libstdcpp = subprocess.check_output(["c++", 44 "-print-file-name=libstdc++.so.6"]) 45 subprocess.check_call(["cp", libstdcpp.strip(), target_dir + "/lib"]) 46 47 # Finally, build libc++ for MSAN bots using the Clang we just built. 48 os.mkdir("../msan_out") 49 os.chdir("../msan_out") 50 subprocess.check_call(["cmake", "..", "-G", "Ninja", 51 "-DCMAKE_BUILD_TYPE=MinSizeRel", 52 "-DCMAKE_C_COMPILER=" + target_dir + "/bin/clang", 53 "-DCMAKE_CXX_COMPILER=" + target_dir + "/bin/clang++", 54 "-DLLVM_USE_SANITIZER=MemoryWithOrigins"]) 55 subprocess.check_call(["ninja", "cxx"]) 56 subprocess.check_call(["cp", "-r", "lib", target_dir + "/msan"]) 57 58 59 def main(): 60 parser = argparse.ArgumentParser() 61 parser.add_argument('--target_dir', '-t', required=True) 62 args = parser.parse_args() 63 create_asset(args.target_dir) 64 65 66 if __name__ == '__main__': 67 main() 68