2015-01-19 04:44:05 +03:00
|
|
|
#!/usr/bin/python2.7
|
2012-06-20 19:14:08 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
2012-06-21 19:13:04 +04:00
|
|
|
import platform
|
2013-04-11 22:59:59 +04:00
|
|
|
import json
|
2013-07-10 23:35:57 +04:00
|
|
|
import argparse
|
2015-09-15 17:16:51 +03:00
|
|
|
import tempfile
|
|
|
|
import glob
|
|
|
|
import errno
|
2016-10-26 23:18:23 +03:00
|
|
|
import re
|
2015-09-15 17:16:51 +03:00
|
|
|
from contextlib import contextmanager
|
2015-09-14 01:57:38 +03:00
|
|
|
import sys
|
2016-10-26 23:18:24 +03:00
|
|
|
import which
|
2012-06-20 19:14:08 +04:00
|
|
|
|
2015-09-14 01:57:38 +03:00
|
|
|
DEBUG = os.getenv("DEBUG")
|
2013-07-09 17:56:28 +04:00
|
|
|
|
2016-02-07 01:21:43 +03:00
|
|
|
|
|
|
|
def symlink(source, link_name):
|
|
|
|
os_symlink = getattr(os, "symlink", None)
|
|
|
|
if callable(os_symlink):
|
|
|
|
os_symlink(source, link_name)
|
|
|
|
else:
|
|
|
|
if os.path.isdir(source):
|
|
|
|
# Fall back to copying the directory :(
|
|
|
|
copy_dir_contents(source, link_name)
|
|
|
|
|
|
|
|
|
2012-06-20 19:14:08 +04:00
|
|
|
def check_run(args):
|
2015-09-14 01:57:38 +03:00
|
|
|
global DEBUG
|
|
|
|
if DEBUG:
|
|
|
|
print >> sys.stderr, ' '.join(args)
|
2012-06-20 19:14:08 +04:00
|
|
|
r = subprocess.call(args)
|
|
|
|
assert r == 0
|
|
|
|
|
2013-07-09 17:56:28 +04:00
|
|
|
|
2012-06-20 19:14:08 +04:00
|
|
|
def run_in(path, args):
|
|
|
|
d = os.getcwd()
|
2015-09-14 01:57:38 +03:00
|
|
|
global DEBUG
|
|
|
|
if DEBUG:
|
|
|
|
print >> sys.stderr, 'cd "%s"' % path
|
2012-06-20 19:14:08 +04:00
|
|
|
os.chdir(path)
|
|
|
|
check_run(args)
|
2015-09-14 01:57:38 +03:00
|
|
|
if DEBUG:
|
|
|
|
print >> sys.stderr, 'cd "%s"' % d
|
2012-06-20 19:14:08 +04:00
|
|
|
os.chdir(d)
|
|
|
|
|
2013-07-09 17:56:28 +04:00
|
|
|
|
2013-07-10 23:35:57 +04:00
|
|
|
def patch(patch, srcdir):
|
2012-06-20 19:14:08 +04:00
|
|
|
patch = os.path.realpath(patch)
|
2013-07-10 23:35:57 +04:00
|
|
|
check_run(['patch', '-d', srcdir, '-p1', '-i', patch, '--fuzz=0',
|
2012-06-20 19:14:08 +04:00
|
|
|
'-s'])
|
|
|
|
|
2013-07-09 17:56:28 +04:00
|
|
|
|
2017-01-03 06:23:08 +03:00
|
|
|
def import_clang_tidy(source_dir):
|
2016-12-18 09:03:10 +03:00
|
|
|
clang_plugin_path = os.path.join(os.path.dirname(sys.argv[0]),
|
|
|
|
'..', 'clang-plugin')
|
|
|
|
clang_tidy_path = os.path.join(source_dir,
|
|
|
|
'tools/clang/tools/extra/clang-tidy')
|
|
|
|
sys.path.append(clang_plugin_path)
|
|
|
|
from import_mozilla_checks import do_import
|
|
|
|
do_import(clang_plugin_path, clang_tidy_path)
|
|
|
|
|
|
|
|
|
2017-01-03 17:25:21 +03:00
|
|
|
def build_package(package_build_dir, cmake_args):
|
2012-06-20 19:14:08 +04:00
|
|
|
if not os.path.exists(package_build_dir):
|
|
|
|
os.mkdir(package_build_dir)
|
2017-01-03 17:25:21 +03:00
|
|
|
run_in(package_build_dir, ["cmake"] + cmake_args)
|
2015-07-11 04:22:55 +03:00
|
|
|
run_in(package_build_dir, ["ninja", "install"])
|
2012-06-20 19:14:08 +04:00
|
|
|
|
2013-07-09 17:56:28 +04:00
|
|
|
|
2015-09-15 17:16:51 +03:00
|
|
|
@contextmanager
|
|
|
|
def updated_env(env):
|
2012-06-20 19:14:08 +04:00
|
|
|
old_env = os.environ.copy()
|
|
|
|
os.environ.update(env)
|
2015-09-15 17:16:51 +03:00
|
|
|
yield
|
2012-06-20 19:14:08 +04:00
|
|
|
os.environ.clear()
|
|
|
|
os.environ.update(old_env)
|
|
|
|
|
2013-07-09 17:56:28 +04:00
|
|
|
|
2012-06-20 19:14:08 +04:00
|
|
|
def build_tar_package(tar, name, base, directory):
|
|
|
|
name = os.path.realpath(name)
|
2016-02-07 01:21:43 +03:00
|
|
|
# On Windows, we have to convert this into an msys path so that tar can
|
|
|
|
# understand it.
|
|
|
|
if is_windows():
|
2016-10-26 23:18:23 +03:00
|
|
|
name = name.replace('\\', '/')
|
|
|
|
def f(match):
|
|
|
|
return '/' + match.group(1).lower()
|
2016-11-15 07:22:44 +03:00
|
|
|
name = re.sub(r'^([A-Za-z]):', f, name)
|
2015-07-11 06:11:11 +03:00
|
|
|
run_in(base, [tar,
|
2015-10-13 21:20:39 +03:00
|
|
|
"-c",
|
|
|
|
"-%s" % ("J" if ".xz" in name else "j"),
|
|
|
|
"-f",
|
2015-07-11 06:11:11 +03:00
|
|
|
name, directory])
|
2012-06-20 19:14:08 +04:00
|
|
|
|
2013-07-09 17:56:28 +04:00
|
|
|
|
2015-09-15 17:16:51 +03:00
|
|
|
def copy_dir_contents(src, dest):
|
|
|
|
for f in glob.glob("%s/*" % src):
|
|
|
|
try:
|
|
|
|
destname = "%s/%s" % (dest, os.path.basename(f))
|
2016-02-07 01:21:43 +03:00
|
|
|
if os.path.isdir(f):
|
|
|
|
shutil.copytree(f, destname)
|
|
|
|
else:
|
|
|
|
shutil.copy2(f, destname)
|
2015-09-15 17:16:51 +03:00
|
|
|
except OSError as e:
|
|
|
|
if e.errno == errno.ENOTDIR:
|
|
|
|
shutil.copy2(f, destname)
|
|
|
|
elif e.errno == errno.EEXIST:
|
|
|
|
if os.path.isdir(f):
|
|
|
|
copy_dir_contents(f, destname)
|
|
|
|
else:
|
|
|
|
os.remove(destname)
|
|
|
|
shutil.copy2(f, destname)
|
|
|
|
else:
|
|
|
|
raise Exception('Directory not copied. Error: %s' % e)
|
|
|
|
|
|
|
|
|
|
|
|
def mkdir_p(path):
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST or not os.path.isdir(path):
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
2017-01-03 06:23:08 +03:00
|
|
|
def delete(path):
|
|
|
|
if os.path.isdir(path):
|
|
|
|
shutil.rmtree(path)
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
os.unlink(path)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2016-04-08 07:14:07 +03:00
|
|
|
def install_libgcc(gcc_dir, clang_dir):
|
2016-04-13 02:00:11 +03:00
|
|
|
out = subprocess.check_output([os.path.join(gcc_dir, "bin", "gcc"),
|
|
|
|
'-print-libgcc-file-name'])
|
|
|
|
|
|
|
|
libgcc_dir = os.path.dirname(out.rstrip())
|
|
|
|
clang_lib_dir = os.path.join(clang_dir, "lib", "gcc",
|
|
|
|
"x86_64-unknown-linux-gnu",
|
|
|
|
os.path.basename(libgcc_dir))
|
|
|
|
mkdir_p(clang_lib_dir)
|
|
|
|
copy_dir_contents(libgcc_dir, clang_lib_dir)
|
|
|
|
libgcc_dir = os.path.join(gcc_dir, "lib64")
|
|
|
|
clang_lib_dir = os.path.join(clang_dir, "lib")
|
|
|
|
copy_dir_contents(libgcc_dir, clang_lib_dir)
|
|
|
|
include_dir = os.path.join(gcc_dir, "include")
|
|
|
|
clang_include_dir = os.path.join(clang_dir, "include")
|
|
|
|
copy_dir_contents(include_dir, clang_include_dir)
|
2015-09-15 17:16:51 +03:00
|
|
|
|
|
|
|
|
2016-12-09 12:02:06 +03:00
|
|
|
def install_import_library(build_dir, clang_dir):
|
|
|
|
shutil.copy2(os.path.join(build_dir, "lib", "clang.lib"),
|
|
|
|
os.path.join(clang_dir, "lib"))
|
|
|
|
|
|
|
|
|
2016-02-07 01:21:43 +03:00
|
|
|
def svn_co(source_dir, url, directory, revision):
|
2016-10-26 23:18:23 +03:00
|
|
|
run_in(source_dir, ["svn", "co", "-q", "-r", revision, url, directory])
|
2012-06-20 19:14:08 +04:00
|
|
|
|
|
|
|
|
2015-07-11 04:52:39 +03:00
|
|
|
def svn_update(directory, revision):
|
2016-10-26 23:18:23 +03:00
|
|
|
run_in(directory, ["svn", "update", "-q", "-r", revision])
|
2017-01-03 17:20:17 +03:00
|
|
|
run_in(directory, ["svn", "revert", "-q", "-R", revision])
|
2015-07-11 04:52:39 +03:00
|
|
|
|
|
|
|
|
2017-02-03 06:16:08 +03:00
|
|
|
def get_platform():
|
|
|
|
p = platform.system()
|
|
|
|
if p == "Darwin":
|
|
|
|
return "macosx64"
|
|
|
|
elif p == "Linux":
|
|
|
|
if platform.architecture() == "AMD64":
|
|
|
|
return "linux64"
|
|
|
|
else:
|
|
|
|
return "linux32"
|
|
|
|
elif p == "Windows":
|
|
|
|
if platform.architecture() == "AMD64":
|
|
|
|
return "win64"
|
|
|
|
else:
|
|
|
|
return "win32"
|
|
|
|
else:
|
|
|
|
raise NotImplementedError("Not supported platform")
|
|
|
|
|
|
|
|
|
2013-07-10 23:35:57 +04:00
|
|
|
def is_darwin():
|
|
|
|
return platform.system() == "Darwin"
|
2012-08-27 18:20:46 +04:00
|
|
|
|
2013-07-09 17:56:28 +04:00
|
|
|
|
2016-02-07 01:21:43 +03:00
|
|
|
def is_linux():
|
|
|
|
return platform.system() == "Linux"
|
|
|
|
|
|
|
|
|
|
|
|
def is_windows():
|
|
|
|
return platform.system() == "Windows"
|
|
|
|
|
|
|
|
|
2017-01-19 22:15:56 +03:00
|
|
|
def build_one_stage(cc, cxx, asm, ld, ar, ranlib,
|
2017-01-03 00:59:55 +03:00
|
|
|
src_dir, stage_dir, build_libcxx,
|
|
|
|
osx_cross_compile, build_type, assertions,
|
2017-01-19 04:20:55 +03:00
|
|
|
python_path, gcc_dir, libcxx_include_dir):
|
2015-07-11 04:43:37 +03:00
|
|
|
if not os.path.exists(stage_dir):
|
|
|
|
os.mkdir(stage_dir)
|
2012-06-20 19:14:08 +04:00
|
|
|
|
|
|
|
build_dir = stage_dir + "/build"
|
2012-06-21 16:48:09 +04:00
|
|
|
inst_dir = stage_dir + "/clang"
|
2012-06-20 19:14:08 +04:00
|
|
|
|
2017-01-03 17:25:21 +03:00
|
|
|
# If CMake has already been run, it may have been run with different
|
|
|
|
# arguments, so we need to re-run it. Make sure the cached copy of the
|
|
|
|
# previous CMake run is cleared before running it again.
|
|
|
|
if os.path.exists(build_dir + "/CMakeCache.txt"):
|
2017-01-05 08:39:19 +03:00
|
|
|
os.remove(build_dir + "/CMakeCache.txt")
|
2017-01-05 09:00:14 +03:00
|
|
|
if os.path.exists(build_dir + "/CMakeFiles"):
|
|
|
|
shutil.rmtree(build_dir + "/CMakeFiles")
|
2015-07-11 04:43:37 +03:00
|
|
|
|
2016-10-26 23:18:23 +03:00
|
|
|
# cmake doesn't deal well with backslashes in paths.
|
|
|
|
def slashify_path(path):
|
|
|
|
return path.replace('\\', '/')
|
|
|
|
|
2015-07-11 04:22:55 +03:00
|
|
|
cmake_args = ["-GNinja",
|
2016-10-26 23:18:23 +03:00
|
|
|
"-DCMAKE_C_COMPILER=%s" % slashify_path(cc[0]),
|
|
|
|
"-DCMAKE_CXX_COMPILER=%s" % slashify_path(cxx[0]),
|
2017-01-19 22:15:56 +03:00
|
|
|
"-DCMAKE_ASM_COMPILER=%s" % slashify_path(asm[0]),
|
2017-01-03 00:59:55 +03:00
|
|
|
"-DCMAKE_LINKER=%s" % slashify_path(ld[0]),
|
|
|
|
"-DCMAKE_AR=%s" % slashify_path(ar),
|
2016-04-07 09:04:13 +03:00
|
|
|
"-DCMAKE_C_FLAGS=%s" % ' '.join(cc[1:]),
|
|
|
|
"-DCMAKE_CXX_FLAGS=%s" % ' '.join(cxx[1:]),
|
2017-01-19 22:15:56 +03:00
|
|
|
"-DCMAKE_ASM_FLAGS=%s" % ' '.join(asm[1:]),
|
2017-01-03 00:59:55 +03:00
|
|
|
"-DCMAKE_EXE_LINKER_FLAGS=%s" % ' '.join(ld[1:]),
|
|
|
|
"-DCMAKE_SHARED_LINKER_FLAGS=%s" % ' '.join(ld[1:]),
|
2015-07-13 03:03:51 +03:00
|
|
|
"-DCMAKE_BUILD_TYPE=%s" % build_type,
|
2015-07-11 04:22:55 +03:00
|
|
|
"-DLLVM_TARGETS_TO_BUILD=X86;ARM",
|
2015-07-13 03:03:51 +03:00
|
|
|
"-DLLVM_ENABLE_ASSERTIONS=%s" % ("ON" if assertions else "OFF"),
|
2016-10-26 23:18:23 +03:00
|
|
|
"-DPYTHON_EXECUTABLE=%s" % slashify_path(python_path),
|
2015-07-11 04:22:55 +03:00
|
|
|
"-DCMAKE_INSTALL_PREFIX=%s" % inst_dir,
|
|
|
|
"-DLLVM_TOOL_LIBCXX_BUILD=%s" % ("ON" if build_libcxx else "OFF"),
|
2015-10-10 03:04:51 +03:00
|
|
|
"-DLIBCXX_LIBCPPABI_VERSION=\"\"",
|
2015-07-11 04:22:55 +03:00
|
|
|
src_dir];
|
2016-11-16 09:00:06 +03:00
|
|
|
if is_windows():
|
|
|
|
cmake_args.insert(-1, "-DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON")
|
2017-01-03 06:05:18 +03:00
|
|
|
cmake_args.insert(-1, "-DLLVM_USE_CRT_RELEASE=MT")
|
2017-01-03 00:59:55 +03:00
|
|
|
if ranlib is not None:
|
|
|
|
cmake_args += ["-DCMAKE_RANLIB=%s" % slashify_path(ranlib)]
|
|
|
|
if osx_cross_compile:
|
|
|
|
cmake_args += ["-DCMAKE_SYSTEM_NAME=Darwin",
|
|
|
|
"-DCMAKE_SYSTEM_VERSION=10.10",
|
|
|
|
"-DLLVM_ENABLE_THREADS=OFF",
|
2017-01-19 04:20:55 +03:00
|
|
|
"-DLIBCXXABI_LIBCXX_INCLUDES=%s" % libcxx_include_dir,
|
2017-01-03 00:59:55 +03:00
|
|
|
"-DCMAKE_OSX_SYSROOT=%s" % slashify_path(os.getenv("CROSS_SYSROOT")),
|
|
|
|
"-DCMAKE_FIND_ROOT_PATH=%s" % slashify_path(os.getenv("CROSS_CCTOOLS_PATH")),
|
|
|
|
"-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER",
|
|
|
|
"-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY",
|
|
|
|
"-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY",
|
|
|
|
"-DCMAKE_MACOSX_RPATH=@executable_path",
|
|
|
|
"-DCMAKE_OSX_ARCHITECTURES=x86_64",
|
|
|
|
"-DDARWIN_osx_ARCHS=x86_64",
|
2017-01-23 08:26:42 +03:00
|
|
|
"-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-apple-darwin11"]
|
2017-01-03 17:25:21 +03:00
|
|
|
build_package(build_dir, cmake_args)
|
2013-07-10 23:35:57 +04:00
|
|
|
|
2016-04-08 07:18:02 +03:00
|
|
|
if is_linux():
|
|
|
|
install_libgcc(gcc_dir, inst_dir)
|
2016-12-09 12:02:06 +03:00
|
|
|
# For some reasons the import library clang.lib of clang.exe is not
|
|
|
|
# installed, so we copy it by ourselves.
|
|
|
|
if is_windows():
|
|
|
|
install_import_library(build_dir, inst_dir)
|
2016-04-08 07:18:02 +03:00
|
|
|
|
2017-01-03 00:59:55 +03:00
|
|
|
# Return the absolute path of a build tool. We first look to see if the
|
|
|
|
# variable is defined in the config file, and if so we make sure it's an
|
|
|
|
# absolute path to an existing tool, otherwise we look for a program in
|
|
|
|
# $PATH named "key".
|
|
|
|
#
|
|
|
|
# This expects the name of the key in the config file to match the name of
|
|
|
|
# the tool in the default toolchain on the system (for example, "ld" on Unix
|
|
|
|
# and "link" on Windows).
|
|
|
|
def get_tool(config, key):
|
|
|
|
f = None
|
|
|
|
if key in config:
|
|
|
|
f = config[key]
|
|
|
|
if os.path.isabs(f):
|
|
|
|
if not os.path.exists(f):
|
|
|
|
raise ValueError("%s must point to an existing path" % key)
|
|
|
|
return f
|
2016-10-26 23:18:24 +03:00
|
|
|
|
|
|
|
# Assume that we have the name of some program that should be on PATH.
|
|
|
|
try:
|
2017-01-03 00:59:55 +03:00
|
|
|
return which.which(f) if f else which.which(key)
|
2016-10-26 23:18:24 +03:00
|
|
|
except which.WhichError:
|
|
|
|
raise ValueError("%s not found on PATH" % f)
|
|
|
|
|
2017-01-03 06:23:08 +03:00
|
|
|
|
|
|
|
# This function is intended to be called on the final build directory when
|
|
|
|
# building clang-tidy. Its job is to remove all of the files which won't
|
|
|
|
# be used for clang-tidy to reduce the download size. Currently when this
|
|
|
|
# function finishes its job, it will leave final_dir with a layout like this:
|
|
|
|
#
|
|
|
|
# clang/
|
|
|
|
# bin/
|
|
|
|
# clang-tidy
|
|
|
|
# include/
|
|
|
|
# * (nothing will be deleted here)
|
|
|
|
# lib/
|
|
|
|
# clang/
|
|
|
|
# 4.0.0/
|
|
|
|
# include/
|
|
|
|
# * (nothing will be deleted here)
|
|
|
|
# share/
|
|
|
|
# clang/
|
|
|
|
# clang-tidy-diff.py
|
|
|
|
# run-clang-tidy.py
|
|
|
|
def prune_final_dir_for_clang_tidy(final_dir):
|
|
|
|
# Make sure we only have what we expect.
|
|
|
|
dirs = ("bin", "include", "lib", "libexec", "msbuild-bin", "share", "tools")
|
|
|
|
for f in glob.glob("%s/*" % final_dir):
|
|
|
|
if os.path.basename(f) not in dirs:
|
|
|
|
raise Exception("Found unknown file %s in the final directory" % f)
|
|
|
|
if not os.path.isdir(f):
|
|
|
|
raise Exception("Expected %s to be a directory" %f)
|
|
|
|
|
|
|
|
# In bin/, only keep clang-tidy.
|
|
|
|
re_clang_tidy = re.compile(r"^clang-tidy(\.exe)?$", re.I)
|
|
|
|
for f in glob.glob("%s/bin/*" % final_dir):
|
|
|
|
if re_clang_tidy.search(os.path.basename(f)) is None:
|
|
|
|
delete(f)
|
|
|
|
|
|
|
|
# Keep include/ intact.
|
|
|
|
|
|
|
|
# In lib/, only keep lib/clang/N.M.O/include.
|
|
|
|
re_ver_num = re.compile(r"^\d+\.\d+\.\d+$", re.I)
|
|
|
|
for f in glob.glob("%s/lib/*" % final_dir):
|
|
|
|
if os.path.basename(f) != "clang":
|
|
|
|
delete(f)
|
|
|
|
for f in glob.glob("%s/lib/clang/*" % final_dir):
|
|
|
|
if re_ver_num.search(os.path.basename(f)) is None:
|
|
|
|
delete(f)
|
|
|
|
for f in glob.glob("%s/lib/clang/*/*" % final_dir):
|
|
|
|
if os.path.basename(f) != "include":
|
|
|
|
delete(f)
|
|
|
|
|
|
|
|
# Completely remove libexec/, msbuilld-bin and tools, if it exists.
|
|
|
|
shutil.rmtree(os.path.join(final_dir, "libexec"))
|
|
|
|
for d in ("msbuild-bin", "tools"):
|
|
|
|
d = os.path.join(final_dir, d)
|
|
|
|
if os.path.exists(d):
|
|
|
|
shutil.rmtree(d)
|
|
|
|
|
|
|
|
# In share/, only keep share/clang/*tidy*
|
|
|
|
re_clang_tidy = re.compile(r"tidy", re.I)
|
|
|
|
for f in glob.glob("%s/share/*" % final_dir):
|
|
|
|
if os.path.basename(f) != "clang":
|
|
|
|
delete(f)
|
|
|
|
for f in glob.glob("%s/share/clang/*" % final_dir):
|
|
|
|
if re_clang_tidy.search(os.path.basename(f)) is None:
|
|
|
|
delete(f)
|
|
|
|
|
|
|
|
|
2013-07-10 23:35:57 +04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
# The directories end up in the debug info, so the easy way of getting
|
|
|
|
# a reproducible build is to run it in a know absolute directory.
|
|
|
|
# We use a directory in /builds/slave because the mozilla infrastructure
|
|
|
|
# cleans it up automatically.
|
|
|
|
base_dir = "/builds/slave/moz-toolchain"
|
2016-02-07 01:21:43 +03:00
|
|
|
if is_windows():
|
2016-10-26 23:18:23 +03:00
|
|
|
# TODO: Because Windows taskcluster builds are run with distinct
|
|
|
|
# user IDs for each job, we can't store things in some globally
|
|
|
|
# accessible directory: one job will run, checkout LLVM to that
|
|
|
|
# directory, and then if another job runs, the new user won't be
|
|
|
|
# able to access the previously-checked out code--or be able to
|
|
|
|
# delete it. So on Windows, we build in the task-specific home
|
|
|
|
# directory; we will eventually add -fdebug-prefix-map options
|
|
|
|
# to the LLVM build to bring back reproducibility.
|
|
|
|
base_dir = os.path.join(os.getcwd(), 'llvm-sources')
|
2013-07-10 23:35:57 +04:00
|
|
|
|
|
|
|
source_dir = base_dir + "/src"
|
|
|
|
build_dir = base_dir + "/build"
|
|
|
|
|
|
|
|
llvm_source_dir = source_dir + "/llvm"
|
|
|
|
clang_source_dir = source_dir + "/clang"
|
2016-12-18 09:03:10 +03:00
|
|
|
extra_source_dir = source_dir + "/extra"
|
2013-07-10 23:35:57 +04:00
|
|
|
compiler_rt_source_dir = source_dir + "/compiler-rt"
|
2015-01-19 04:44:05 +03:00
|
|
|
libcxx_source_dir = source_dir + "/libcxx"
|
2016-08-05 16:46:38 +03:00
|
|
|
libcxxabi_source_dir = source_dir + "/libcxxabi"
|
2013-07-10 23:35:57 +04:00
|
|
|
|
|
|
|
if is_darwin():
|
|
|
|
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.7'
|
|
|
|
|
2016-02-07 01:21:43 +03:00
|
|
|
exe_ext = ""
|
|
|
|
if is_windows():
|
|
|
|
exe_ext = ".exe"
|
|
|
|
|
|
|
|
cc_name = "clang"
|
|
|
|
cxx_name = "clang++"
|
|
|
|
if is_windows():
|
|
|
|
cc_name = "clang-cl"
|
|
|
|
cxx_name = "clang-cl"
|
|
|
|
|
2013-07-10 23:35:57 +04:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('-c', '--config', required=True,
|
|
|
|
type=argparse.FileType('r'),
|
|
|
|
help="Clang configuration file")
|
2015-07-13 03:14:59 +03:00
|
|
|
parser.add_argument('--clean', required=False,
|
|
|
|
action='store_true',
|
|
|
|
help="Clean the build directory")
|
2013-07-10 23:35:57 +04:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
config = json.load(args.config)
|
2015-07-13 03:14:59 +03:00
|
|
|
|
|
|
|
if args.clean:
|
|
|
|
shutil.rmtree(build_dir)
|
|
|
|
os.sys.exit(0)
|
|
|
|
|
2013-07-10 23:35:57 +04:00
|
|
|
llvm_revision = config["llvm_revision"]
|
|
|
|
llvm_repo = config["llvm_repo"]
|
|
|
|
clang_repo = config["clang_repo"]
|
2016-12-18 09:03:10 +03:00
|
|
|
extra_repo = config.get("extra_repo")
|
2013-07-10 23:35:57 +04:00
|
|
|
compiler_repo = config["compiler_repo"]
|
2015-01-19 04:44:05 +03:00
|
|
|
libcxx_repo = config["libcxx_repo"]
|
2016-08-05 16:46:38 +03:00
|
|
|
libcxxabi_repo = config.get("libcxxabi_repo")
|
2015-07-11 06:11:11 +03:00
|
|
|
stages = 3
|
|
|
|
if "stages" in config:
|
|
|
|
stages = int(config["stages"])
|
|
|
|
if stages not in (1, 2, 3):
|
|
|
|
raise ValueError("We only know how to build 1, 2, or 3 stages")
|
2015-07-13 03:03:51 +03:00
|
|
|
build_type = "Release"
|
|
|
|
if "build_type" in config:
|
|
|
|
build_type = config["build_type"]
|
|
|
|
if build_type not in ("Release", "Debug", "RelWithDebInfo", "MinSizeRel"):
|
|
|
|
raise ValueError("We only know how to do Release, Debug, RelWithDebInfo or MinSizeRel builds")
|
2015-07-13 03:17:49 +03:00
|
|
|
build_libcxx = False
|
|
|
|
if "build_libcxx" in config:
|
|
|
|
build_libcxx = config["build_libcxx"]
|
|
|
|
if build_libcxx not in (True, False):
|
|
|
|
raise ValueError("Only boolean values are accepted for build_libcxx.")
|
2017-01-03 06:23:08 +03:00
|
|
|
build_clang_tidy = False
|
|
|
|
if "build_clang_tidy" in config:
|
|
|
|
build_clang_tidy = config["build_clang_tidy"]
|
|
|
|
if build_clang_tidy not in (True, False):
|
|
|
|
raise ValueError("Only boolean values are accepted for build_clang_tidy.")
|
2017-01-03 00:59:55 +03:00
|
|
|
osx_cross_compile = False
|
|
|
|
if "osx_cross_compile" in config:
|
|
|
|
osx_cross_compile = config["osx_cross_compile"]
|
|
|
|
if osx_cross_compile not in (True, False):
|
|
|
|
raise ValueError("Only boolean values are accepted for osx_cross_compile.")
|
|
|
|
if osx_cross_compile and not is_linux():
|
|
|
|
raise ValueError("osx_cross_compile can only be used on Linux.")
|
2015-07-13 03:03:51 +03:00
|
|
|
assertions = False
|
|
|
|
if "assertions" in config:
|
|
|
|
assertions = config["assertions"]
|
|
|
|
if assertions not in (True, False):
|
|
|
|
raise ValueError("Only boolean values are accepted for assertions.")
|
2015-09-11 16:26:24 +03:00
|
|
|
python_path = None
|
|
|
|
if "python_path" not in config:
|
|
|
|
raise ValueError("Config file needs to set python_path")
|
|
|
|
python_path = config["python_path"]
|
2015-09-11 16:37:14 +03:00
|
|
|
gcc_dir = None
|
|
|
|
if "gcc_dir" in config:
|
|
|
|
gcc_dir = config["gcc_dir"]
|
|
|
|
if not os.path.exists(gcc_dir):
|
|
|
|
raise ValueError("gcc_dir must point to an existing path")
|
2016-02-07 01:21:43 +03:00
|
|
|
if is_linux() and gcc_dir is None:
|
2015-09-11 16:37:14 +03:00
|
|
|
raise ValueError("Config file needs to set gcc_dir")
|
2017-01-03 00:59:55 +03:00
|
|
|
cc = get_tool(config, "cc")
|
|
|
|
cxx = get_tool(config, "cxx")
|
2017-01-19 22:15:56 +03:00
|
|
|
asm = get_tool(config, "ml" if is_windows() else "as")
|
2017-01-03 00:59:55 +03:00
|
|
|
ld = get_tool(config, "link" if is_windows() else "ld")
|
|
|
|
ar = get_tool(config, "lib" if is_windows() else "ar")
|
|
|
|
ranlib = None if is_windows() else get_tool(config, "ranlib")
|
2013-07-10 23:35:57 +04:00
|
|
|
|
|
|
|
if not os.path.exists(source_dir):
|
|
|
|
os.makedirs(source_dir)
|
2017-01-20 20:54:56 +03:00
|
|
|
|
|
|
|
def checkout_or_update(repo, checkout_dir):
|
|
|
|
if os.path.exists(checkout_dir):
|
|
|
|
svn_update(checkout_dir, llvm_revision)
|
2017-01-03 17:20:17 +03:00
|
|
|
else:
|
2017-01-20 20:54:56 +03:00
|
|
|
svn_co(source_dir, repo, checkout_dir, llvm_revision)
|
|
|
|
|
|
|
|
checkout_or_update(llvm_repo, llvm_source_dir)
|
|
|
|
checkout_or_update(clang_repo, clang_source_dir)
|
|
|
|
checkout_or_update(compiler_repo, compiler_rt_source_dir)
|
|
|
|
checkout_or_update(libcxx_repo, libcxx_source_dir)
|
|
|
|
if libcxxabi_repo:
|
|
|
|
checkout_or_update(libcxxabi_repo, libcxxabi_source_dir)
|
2017-01-03 17:20:17 +03:00
|
|
|
if extra_repo:
|
2017-01-20 20:54:56 +03:00
|
|
|
checkout_or_update(extra_repo, extra_source_dir)
|
2017-02-03 06:16:08 +03:00
|
|
|
for p in config.get("patches", {}).get(get_platform(), []):
|
2017-01-03 17:20:17 +03:00
|
|
|
patch(p, source_dir)
|
2013-07-10 23:35:57 +04:00
|
|
|
|
2016-02-07 01:21:43 +03:00
|
|
|
symlinks = [(source_dir + "/clang",
|
|
|
|
llvm_source_dir + "/tools/clang"),
|
2016-12-18 09:03:10 +03:00
|
|
|
(source_dir + "/extra",
|
|
|
|
llvm_source_dir + "/tools/clang/tools/extra"),
|
2016-02-07 01:21:43 +03:00
|
|
|
(source_dir + "/compiler-rt",
|
|
|
|
llvm_source_dir + "/projects/compiler-rt"),
|
|
|
|
(source_dir + "/libcxx",
|
2016-08-05 16:46:38 +03:00
|
|
|
llvm_source_dir + "/projects/libcxx"),
|
|
|
|
(source_dir + "/libcxxabi",
|
|
|
|
llvm_source_dir + "/projects/libcxxabi")]
|
2016-02-07 01:21:43 +03:00
|
|
|
for l in symlinks:
|
|
|
|
# On Windows, we have to re-copy the whole directory every time.
|
|
|
|
if not is_windows() and os.path.islink(l[1]):
|
|
|
|
continue
|
2017-01-03 06:23:08 +03:00
|
|
|
delete(l[1]);
|
2016-08-05 16:46:38 +03:00
|
|
|
if os.path.exists(l[0]):
|
|
|
|
symlink(l[0], l[1])
|
2016-02-07 01:21:43 +03:00
|
|
|
|
2017-01-03 06:23:08 +03:00
|
|
|
if build_clang_tidy:
|
|
|
|
import_clang_tidy(llvm_source_dir)
|
2016-12-18 09:03:10 +03:00
|
|
|
|
2015-07-11 04:43:37 +03:00
|
|
|
if not os.path.exists(build_dir):
|
|
|
|
os.makedirs(build_dir)
|
2013-07-10 23:35:57 +04:00
|
|
|
|
2017-01-19 04:20:55 +03:00
|
|
|
libcxx_include_dir = os.path.join(llvm_source_dir, "projects",
|
|
|
|
"libcxx", "include")
|
|
|
|
|
2013-07-10 23:35:57 +04:00
|
|
|
stage1_dir = build_dir + '/stage1'
|
|
|
|
stage1_inst_dir = stage1_dir + '/clang'
|
|
|
|
|
2015-07-11 06:11:11 +03:00
|
|
|
final_stage_dir = stage1_dir
|
|
|
|
|
2013-07-10 23:35:57 +04:00
|
|
|
if is_darwin():
|
2016-04-07 09:04:13 +03:00
|
|
|
extra_cflags = []
|
|
|
|
extra_cxxflags = ["-stdlib=libc++"]
|
|
|
|
extra_cflags2 = []
|
|
|
|
extra_cxxflags2 = ["-stdlib=libc++"]
|
2017-01-19 22:15:56 +03:00
|
|
|
extra_asmflags = []
|
2017-01-03 00:59:55 +03:00
|
|
|
extra_ldflags = []
|
2016-02-07 01:21:43 +03:00
|
|
|
elif is_linux():
|
2016-04-07 09:04:13 +03:00
|
|
|
extra_cflags = ["-static-libgcc"]
|
|
|
|
extra_cxxflags = ["-static-libgcc", "-static-libstdc++"]
|
2016-04-08 07:18:02 +03:00
|
|
|
extra_cflags2 = ["-fPIC"]
|
2016-06-08 08:12:33 +03:00
|
|
|
extra_cxxflags2 = ["-fPIC", "-static-libstdc++"]
|
2017-01-19 22:15:56 +03:00
|
|
|
extra_asmflags = []
|
2017-01-03 00:59:55 +03:00
|
|
|
extra_ldflags = []
|
2014-03-28 22:06:13 +04:00
|
|
|
|
2015-09-11 16:37:14 +03:00
|
|
|
if os.environ.has_key('LD_LIBRARY_PATH'):
|
|
|
|
os.environ['LD_LIBRARY_PATH'] = '%s/lib64/:%s' % (gcc_dir, os.environ['LD_LIBRARY_PATH']);
|
|
|
|
else:
|
|
|
|
os.environ['LD_LIBRARY_PATH'] = '%s/lib64/' % gcc_dir
|
2016-02-07 01:21:43 +03:00
|
|
|
elif is_windows():
|
2016-04-07 09:04:13 +03:00
|
|
|
extra_cflags = []
|
|
|
|
extra_cxxflags = []
|
2016-10-26 23:18:23 +03:00
|
|
|
# clang-cl would like to figure out what it's supposed to be emulating
|
|
|
|
# by looking at an MSVC install, but we don't really have that here.
|
|
|
|
# Force things on.
|
2016-04-07 09:04:13 +03:00
|
|
|
extra_cflags2 = []
|
2016-12-16 03:27:03 +03:00
|
|
|
extra_cxxflags2 = ['-fms-compatibility-version=19.00.24213', '-Xclang', '-std=c++14']
|
2017-01-19 22:15:56 +03:00
|
|
|
extra_asmflags = []
|
2017-01-03 00:59:55 +03:00
|
|
|
extra_ldflags = []
|
|
|
|
|
|
|
|
if osx_cross_compile:
|
|
|
|
# undo the damage done in the is_linux() block above, and also simulate
|
|
|
|
# the is_darwin() block above.
|
|
|
|
extra_cflags = []
|
|
|
|
extra_cxxflags = ["-stdlib=libc++"]
|
|
|
|
extra_cxxflags2 = ["-stdlib=libc++"]
|
|
|
|
|
2017-01-23 08:26:42 +03:00
|
|
|
extra_flags = ["-target", "x86_64-apple-darwin11", "-mlinker-version=137",
|
2017-01-03 00:59:55 +03:00
|
|
|
"-B", "%s/bin" % os.getenv("CROSS_CCTOOLS_PATH"),
|
|
|
|
"-isysroot", os.getenv("CROSS_SYSROOT"),
|
|
|
|
# technically the sysroot flag there should be enough to deduce this,
|
|
|
|
# but clang needs some help to figure this out.
|
|
|
|
"-I%s/usr/include" % os.getenv("CROSS_SYSROOT"),
|
|
|
|
"-iframework", "%s/System/Library/Frameworks" % os.getenv("CROSS_SYSROOT")]
|
|
|
|
extra_cflags += extra_flags
|
|
|
|
extra_cxxflags += extra_flags
|
|
|
|
extra_cflags2 += extra_flags
|
|
|
|
extra_cxxflags2 += extra_flags
|
2017-01-19 22:15:56 +03:00
|
|
|
extra_asmflags += extra_flags
|
2017-01-03 00:59:55 +03:00
|
|
|
extra_ldflags = ["-Wl,-syslibroot,%s" % os.getenv("CROSS_SYSROOT"),
|
|
|
|
"-Wl,-dead_strip"]
|
2013-07-10 23:35:57 +04:00
|
|
|
|
2015-01-19 04:44:05 +03:00
|
|
|
build_one_stage(
|
2016-04-07 09:04:13 +03:00
|
|
|
[cc] + extra_cflags,
|
|
|
|
[cxx] + extra_cxxflags,
|
2017-01-19 22:15:56 +03:00
|
|
|
[asm] + extra_asmflags,
|
2017-01-03 00:59:55 +03:00
|
|
|
[ld] + extra_ldflags,
|
2017-02-03 06:16:08 +03:00
|
|
|
ar, ranlib,
|
2017-01-03 00:59:55 +03:00
|
|
|
llvm_source_dir, stage1_dir, build_libcxx, osx_cross_compile,
|
2017-01-19 04:20:55 +03:00
|
|
|
build_type, assertions, python_path, gcc_dir, libcxx_include_dir)
|
2013-07-10 23:35:57 +04:00
|
|
|
|
2015-07-11 06:11:11 +03:00
|
|
|
if stages > 1:
|
|
|
|
stage2_dir = build_dir + '/stage2'
|
|
|
|
stage2_inst_dir = stage2_dir + '/clang'
|
|
|
|
final_stage_dir = stage2_dir
|
|
|
|
build_one_stage(
|
2016-04-07 09:04:13 +03:00
|
|
|
[stage1_inst_dir + "/bin/%s%s" %
|
|
|
|
(cc_name, exe_ext)] + extra_cflags2,
|
|
|
|
[stage1_inst_dir + "/bin/%s%s" %
|
|
|
|
(cxx_name, exe_ext)] + extra_cxxflags2,
|
2017-01-19 22:15:56 +03:00
|
|
|
[stage1_inst_dir + "/bin/%s%s" %
|
|
|
|
(cc_name, exe_ext)] + extra_asmflags,
|
2017-01-03 00:59:55 +03:00
|
|
|
[ld] + extra_ldflags,
|
2017-02-03 06:16:08 +03:00
|
|
|
ar, ranlib,
|
2017-01-03 00:59:55 +03:00
|
|
|
llvm_source_dir, stage2_dir, build_libcxx, osx_cross_compile,
|
2017-01-19 04:20:55 +03:00
|
|
|
build_type, assertions, python_path, gcc_dir, libcxx_include_dir)
|
2015-09-15 17:16:51 +03:00
|
|
|
|
2016-04-08 07:18:02 +03:00
|
|
|
if stages > 2:
|
|
|
|
stage3_dir = build_dir + '/stage3'
|
|
|
|
final_stage_dir = stage3_dir
|
|
|
|
build_one_stage(
|
|
|
|
[stage2_inst_dir + "/bin/%s%s" %
|
|
|
|
(cc_name, exe_ext)] + extra_cflags2,
|
|
|
|
[stage2_inst_dir + "/bin/%s%s" %
|
|
|
|
(cxx_name, exe_ext)] + extra_cxxflags2,
|
2017-01-19 22:15:56 +03:00
|
|
|
[stage2_inst_dir + "/bin/%s%s" %
|
|
|
|
(cc_name, exe_ext)] + extra_asmflags,
|
2017-01-03 00:59:55 +03:00
|
|
|
[ld] + extra_ldflags,
|
2017-02-03 06:16:08 +03:00
|
|
|
ar, ranlib,
|
2017-01-03 00:59:55 +03:00
|
|
|
llvm_source_dir, stage3_dir, build_libcxx, osx_cross_compile,
|
2017-01-19 04:20:55 +03:00
|
|
|
build_type, assertions, python_path, gcc_dir, libcxx_include_dir)
|
2013-07-10 23:35:57 +04:00
|
|
|
|
2017-01-03 06:23:08 +03:00
|
|
|
package_name = "clang"
|
|
|
|
if build_clang_tidy:
|
|
|
|
prune_final_dir_for_clang_tidy(os.path.join(final_stage_dir, "clang"))
|
|
|
|
package_name = "clang-tidy"
|
|
|
|
|
2016-02-07 01:21:43 +03:00
|
|
|
if is_darwin() or is_windows():
|
2017-01-03 06:23:08 +03:00
|
|
|
build_tar_package("tar", package_name + ".tar.bz2", final_stage_dir, "clang")
|
2015-07-11 06:11:11 +03:00
|
|
|
else:
|
2017-01-03 06:23:08 +03:00
|
|
|
build_tar_package("tar", package_name + ".tar.xz", final_stage_dir, "clang")
|