• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
12import argparse
13import os
14import subprocess
15import tempfile
16
17REPO = "https://llvm.googlesource.com/"
18BRANCH = "release_70"
19
20def create_asset(target_dir):
21  # CMake will sometimes barf if we pass it a relative path.
22  target_dir = os.path.abspath(target_dir)
23
24  # Build Clang, lld, compiler-rt (sanitizer support) and libc++.
25  os.chdir(tempfile.mkdtemp())
26  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
27                         BRANCH, REPO + "llvm"])
28  os.chdir("llvm/tools")
29  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
30                         BRANCH, REPO + "clang"])
31  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
32                         BRANCH, REPO + "lld"])
33  os.chdir("clang/tools")
34  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
35                         BRANCH, REPO + "clang-tools-extra", "extra"])
36
37  os.chdir("../../../projects")
38  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
39                         BRANCH, REPO + "compiler-rt"])
40  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
41                         BRANCH, REPO + "libcxx"])
42  subprocess.check_call(["git", "clone", "--depth", "1", "-b",
43                         BRANCH, REPO + "libcxxabi"])
44  os.chdir("..")
45  os.mkdir("out")
46  os.chdir("out")
47  subprocess.check_call(["cmake", "..", "-G", "Ninja",
48                         "-DCMAKE_BUILD_TYPE=MinSizeRel",
49                         "-DCMAKE_INSTALL_PREFIX=" + target_dir,
50                         "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON",
51                         "-DLLVM_ENABLE_TERMINFO=OFF"])
52  subprocess.check_call(["ninja", "install"])
53
54  # Copy a couple extra files we need.
55  subprocess.check_call(["cp", "bin/llvm-symbolizer", target_dir + "/bin"])
56  subprocess.check_call(["cp", "bin/llvm-profdata", target_dir + "/bin"])
57  subprocess.check_call(["cp", "bin/llvm-cov", target_dir + "/bin"])
58  libstdcpp = subprocess.check_output(["c++",
59                                       "-print-file-name=libstdc++.so.6"])
60  subprocess.check_call(["cp", libstdcpp.strip(), target_dir + "/lib"])
61
62  # Finally, build libc++ for MSAN bots using the Clang we just built.
63  os.mkdir("../msan_out")
64  os.chdir("../msan_out")
65  subprocess.check_call(["cmake", "..", "-G", "Ninja",
66                         "-DCMAKE_BUILD_TYPE=MinSizeRel",
67                         "-DCMAKE_C_COMPILER="   + target_dir + "/bin/clang",
68                         "-DCMAKE_CXX_COMPILER=" + target_dir + "/bin/clang++",
69                         "-DLLVM_USE_SANITIZER=MemoryWithOrigins"])
70  subprocess.check_call(["ninja", "cxx"])
71  subprocess.check_call(["cp", "-r", "lib",  target_dir + "/msan"])
72
73
74def main():
75  parser = argparse.ArgumentParser()
76  parser.add_argument('--target_dir', '-t', required=True)
77  args = parser.parse_args()
78  create_asset(args.target_dir)
79
80
81if __name__ == '__main__':
82  main()
83