Bug 1570564 - Convert build-clang.py to python 3. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D40152
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
#!/usr/bin/python2.7
|
#!/usr/bin/python3
|
||||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
# 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
|
# 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/.
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
# Only necessary for flake8 to be happy...
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
@@ -18,7 +21,7 @@ import sys
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from distutils.dir_util import copy_tree
|
from distutils.dir_util import copy_tree
|
||||||
|
|
||||||
from mozfile import which
|
from shutil import which
|
||||||
|
|
||||||
URL_REPO = "https://github.com/llvm/llvm-project"
|
URL_REPO = "https://github.com/llvm/llvm-project"
|
||||||
|
|
||||||
@@ -34,7 +37,7 @@ def symlink(source, link_name):
|
|||||||
|
|
||||||
|
|
||||||
def check_run(args):
|
def check_run(args):
|
||||||
print >> sys.stderr, ' '.join(args)
|
print(' '.join(args), file=sys.stderr)
|
||||||
if args[0] == 'cmake':
|
if args[0] == 'cmake':
|
||||||
# CMake `message(STATUS)` messages, as appearing in failed source code
|
# CMake `message(STATUS)` messages, as appearing in failed source code
|
||||||
# compiles, appear on stdout, so we only capture that.
|
# compiles, appear on stdout, so we only capture that.
|
||||||
@@ -42,7 +45,7 @@ def check_run(args):
|
|||||||
lines = []
|
lines = []
|
||||||
for line in p.stdout:
|
for line in p.stdout:
|
||||||
lines.append(line)
|
lines.append(line)
|
||||||
sys.stdout.write(line)
|
sys.stdout.write(line.decode())
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
r = p.wait()
|
r = p.wait()
|
||||||
if r != 0:
|
if r != 0:
|
||||||
@@ -60,8 +63,8 @@ def check_run(args):
|
|||||||
|
|
||||||
def dump_file(log):
|
def dump_file(log):
|
||||||
with open(log, 'rb') as f:
|
with open(log, 'rb') as f:
|
||||||
print >> sys.stderr, "\nContents of", log, "follow\n"
|
print("\nContents of", log, "follow\n", file=sys.stderr)
|
||||||
print >> sys.stderr, f.read()
|
print(f.read(), file=sys.stderr)
|
||||||
if output_match:
|
if output_match:
|
||||||
dump_file(output_match.group(1))
|
dump_file(output_match.group(1))
|
||||||
if error_match:
|
if error_match:
|
||||||
@@ -73,10 +76,10 @@ def check_run(args):
|
|||||||
|
|
||||||
def run_in(path, args):
|
def run_in(path, args):
|
||||||
d = os.getcwd()
|
d = os.getcwd()
|
||||||
print >> sys.stderr, 'cd "%s"' % path
|
print('cd "%s"' % path, file=sys.stderr)
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
check_run(args)
|
check_run(args)
|
||||||
print >> sys.stderr, 'cd "%s"' % d
|
print('cd "%s"' % d, file=sys.stderr)
|
||||||
os.chdir(d)
|
os.chdir(d)
|
||||||
|
|
||||||
|
|
||||||
@@ -174,7 +177,7 @@ def install_libgcc(gcc_dir, clang_dir, is_final_stage):
|
|||||||
out = subprocess.check_output([os.path.join(gcc_bin_dir, "gcc"),
|
out = subprocess.check_output([os.path.join(gcc_bin_dir, "gcc"),
|
||||||
'-print-libgcc-file-name'])
|
'-print-libgcc-file-name'])
|
||||||
|
|
||||||
libgcc_dir = os.path.dirname(out.rstrip())
|
libgcc_dir = os.path.dirname(out.decode().rstrip())
|
||||||
clang_lib_dir = os.path.join(clang_dir, "lib", "gcc",
|
clang_lib_dir = os.path.join(clang_dir, "lib", "gcc",
|
||||||
"x86_64-unknown-linux-gnu",
|
"x86_64-unknown-linux-gnu",
|
||||||
os.path.basename(libgcc_dir))
|
os.path.basename(libgcc_dir))
|
||||||
@@ -352,7 +355,7 @@ def build_one_stage(cc, cxx, asm, ld, ar, ranlib, libtool,
|
|||||||
|
|
||||||
android_link_flags = "-fuse-ld=lld"
|
android_link_flags = "-fuse-ld=lld"
|
||||||
|
|
||||||
for target, cfg in android_targets.iteritems():
|
for target, cfg in android_targets.items():
|
||||||
sysroot_dir = cfg["ndk_sysroot"]
|
sysroot_dir = cfg["ndk_sysroot"]
|
||||||
android_gcc_dir = cfg["ndk_toolchain"]
|
android_gcc_dir = cfg["ndk_toolchain"]
|
||||||
android_include_dirs = cfg["ndk_includes"]
|
android_include_dirs = cfg["ndk_includes"]
|
||||||
@@ -669,7 +672,7 @@ if __name__ == "__main__":
|
|||||||
if "android_targets" in config:
|
if "android_targets" in config:
|
||||||
android_targets = config["android_targets"]
|
android_targets = config["android_targets"]
|
||||||
for attr in ("ndk_toolchain", "ndk_sysroot", "ndk_includes", "api_level"):
|
for attr in ("ndk_toolchain", "ndk_sysroot", "ndk_includes", "api_level"):
|
||||||
for target, cfg in android_targets.iteritems():
|
for target, cfg in android_targets.items():
|
||||||
if attr not in cfg:
|
if attr not in cfg:
|
||||||
raise ValueError("must specify '%s' as a key for android target: %s" %
|
raise ValueError("must specify '%s' as a key for android target: %s" %
|
||||||
(attr, target))
|
(attr, target))
|
||||||
@@ -678,7 +681,7 @@ if __name__ == "__main__":
|
|||||||
extra_targets = config["extra_targets"]
|
extra_targets = config["extra_targets"]
|
||||||
if not isinstance(extra_targets, list):
|
if not isinstance(extra_targets, list):
|
||||||
raise ValueError("extra_targets must be a list")
|
raise ValueError("extra_targets must be a list")
|
||||||
if not all(isinstance(t, (str, unicode)) for t in extra_targets):
|
if not all(isinstance(t, str) for t in extra_targets):
|
||||||
raise ValueError("members of extra_targets should be strings")
|
raise ValueError("members of extra_targets should be strings")
|
||||||
if is_linux() and gcc_dir is None:
|
if is_linux() and gcc_dir is None:
|
||||||
raise ValueError("Config file needs to set gcc_dir")
|
raise ValueError("Config file needs to set gcc_dir")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python2.7
|
#!/usr/bin/python3
|
||||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
# 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
|
# 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/.
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
@@ -34,9 +34,8 @@ def copy_dir_contents(src, dest):
|
|||||||
|
|
||||||
|
|
||||||
def write_cmake(module_path):
|
def write_cmake(module_path):
|
||||||
names = map(lambda f: ' ' + os.path.basename(f),
|
names = [' ' + os.path.basename(f) for f in glob.glob("%s/*.cpp" % module_path)]
|
||||||
glob.glob("%s/*.cpp" % module_path))
|
with open(os.path.join(module_path, 'CMakeLists.txt'), 'w') as f:
|
||||||
with open(os.path.join(module_path, 'CMakeLists.txt'), 'wb') as f:
|
|
||||||
f.write("""set(LLVM_LINK_COMPONENTS support)
|
f.write("""set(LLVM_LINK_COMPONENTS support)
|
||||||
|
|
||||||
add_definitions( -DCLANG_TIDY )
|
add_definitions( -DCLANG_TIDY )
|
||||||
@@ -76,13 +75,13 @@ def add_item_to_cmake_section(cmake_path, section, library):
|
|||||||
libs.append(library)
|
libs.append(library)
|
||||||
libs = sorted(libs, key=lambda s: s.lower())
|
libs = sorted(libs, key=lambda s: s.lower())
|
||||||
|
|
||||||
with open(cmake_path, 'wb') as f:
|
with open(cmake_path, 'w') as f:
|
||||||
seen_target_libs = False
|
seen_target_libs = False
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.find(section) > -1:
|
if line.find(section) > -1:
|
||||||
seen_target_libs = True
|
seen_target_libs = True
|
||||||
f.write(line)
|
f.write(line)
|
||||||
f.writelines(map(lambda p: ' ' + p + '\n', libs))
|
f.writelines([' ' + p + '\n' for p in libs])
|
||||||
continue
|
continue
|
||||||
elif seen_target_libs:
|
elif seen_target_libs:
|
||||||
if line.find(')') > -1:
|
if line.find(')') > -1:
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ cd $HOME_DIR/src
|
|||||||
set +x
|
set +x
|
||||||
|
|
||||||
cd build/build-clang
|
cd build/build-clang
|
||||||
# |mach python| sets up a virtualenv for us!
|
python3 ./build-clang.py -c clang-4.0-linux64.json
|
||||||
../../mach python ./build-clang.py -c clang-4.0-linux64.json
|
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ cd $HOME_DIR/src
|
|||||||
set +x
|
set +x
|
||||||
|
|
||||||
cd build/build-clang
|
cd build/build-clang
|
||||||
# |mach python| sets up a virtualenv for us!
|
python3 ./build-clang.py -c clang-7-linux64.json
|
||||||
../../mach python ./build-clang.py -c clang-7-linux64.json
|
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ cd $HOME_DIR/src
|
|||||||
set +x
|
set +x
|
||||||
|
|
||||||
cd build/build-clang
|
cd build/build-clang
|
||||||
# |mach python| sets up a virtualenv for us!
|
python3 ./build-clang.py -c clang-8-android.json
|
||||||
../../mach python ./build-clang.py -c clang-8-android.json
|
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ export PATH="$WORKSPACE/build/src/binutils/bin:$PATH"
|
|||||||
set +x
|
set +x
|
||||||
|
|
||||||
cd build/build-clang
|
cd build/build-clang
|
||||||
# |mach python| sets up a virtualenv for us!
|
python3 ./build-clang.py -c clang-8-linux64-aarch64-cross.json
|
||||||
../../mach python ./build-clang.py -c clang-8-linux64-aarch64-cross.json
|
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ export PATH=$PATH:$CROSS_CCTOOLS_PATH/bin
|
|||||||
set +x
|
set +x
|
||||||
|
|
||||||
cd build/build-clang
|
cd build/build-clang
|
||||||
# |mach python| sets up a virtualenv for us!
|
python3 ./build-clang.py -c clang-8-macosx64.json --skip-tar
|
||||||
../../mach python ./build-clang.py -c clang-8-macosx64.json --skip-tar
|
|
||||||
|
|
||||||
# We now have a native macosx64 toolchain.
|
# We now have a native macosx64 toolchain.
|
||||||
# What we want is a native linux64 toolchain which can target macosx64 and use the sanitizer dylibs.
|
# What we want is a native linux64 toolchain which can target macosx64 and use the sanitizer dylibs.
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ cd $HOME_DIR/src
|
|||||||
set +x
|
set +x
|
||||||
|
|
||||||
cd build/build-clang
|
cd build/build-clang
|
||||||
# |mach python| sets up a virtualenv for us!
|
python3 ./build-clang.py -c clang-8-linux64.json
|
||||||
../../mach python ./build-clang.py -c clang-8-linux64.json
|
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
|||||||
@@ -288,8 +288,7 @@ prepare
|
|||||||
set +x
|
set +x
|
||||||
|
|
||||||
cd build/build-clang
|
cd build/build-clang
|
||||||
# |mach python| sets up a virtualenv for us!
|
python3 ./build-clang.py -c clang-8-mingw.json --skip-tar
|
||||||
../../mach python ./build-clang.py -c clang-8-mingw.json --skip-tar
|
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ export PATH=$PATH:$CROSS_CCTOOLS_PATH/bin
|
|||||||
set +x
|
set +x
|
||||||
|
|
||||||
cd build/build-clang
|
cd build/build-clang
|
||||||
# |mach python| sets up a virtualenv for us!
|
python3 ./build-clang.py -c clang-8-macosx64.json
|
||||||
../../mach python ./build-clang.py -c clang-8-macosx64.json
|
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ cd $HOME_DIR/src
|
|||||||
set +x
|
set +x
|
||||||
|
|
||||||
cd build/build-clang
|
cd build/build-clang
|
||||||
# |mach python| sets up a virtualenv for us!
|
python3 ./build-clang.py -c clang-tidy-linux64.json
|
||||||
../../mach python ./build-clang.py -c clang-tidy-linux64.json
|
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ export PATH=$PATH:$CROSS_CCTOOLS_PATH/bin
|
|||||||
set +x
|
set +x
|
||||||
|
|
||||||
cd build/build-clang
|
cd build/build-clang
|
||||||
# |mach python| sets up a virtualenv for us!
|
python3 ./build-clang.py -c clang-tidy-macosx64.json
|
||||||
../../mach python ./build-clang.py -c clang-tidy-macosx64.json
|
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
|||||||
@@ -39,20 +39,12 @@ export PATH="$(pwd)/cmd:${PATH}"
|
|||||||
export PATH="$(cd cmake && pwd)/bin:${PATH}"
|
export PATH="$(cd cmake && pwd)/bin:${PATH}"
|
||||||
export PATH="$(cd ninja && pwd)/bin:${PATH}"
|
export PATH="$(cd ninja && pwd)/bin:${PATH}"
|
||||||
|
|
||||||
# We use |mach python| to set up a virtualenv automatically for us. We create
|
|
||||||
# a dummy mozconfig, because the default machinery for config.guess-choosing
|
|
||||||
# of the objdir doesn't work very well.
|
|
||||||
MOZCONFIG="$(pwd)/mozconfig"
|
|
||||||
cat > ${MOZCONFIG} <<EOF
|
|
||||||
mk_add_options MOZ_OBJDIR=$(pwd)/objdir
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# gets a bit too verbose here
|
# gets a bit too verbose here
|
||||||
set +x
|
set +x
|
||||||
|
|
||||||
BUILD_CLANG_DIR=build/src/build/build-clang
|
BUILD_CLANG_DIR=build/src/build/build-clang
|
||||||
cd ${BUILD_CLANG_DIR}
|
cd ${BUILD_CLANG_DIR}
|
||||||
MOZCONFIG=${MOZCONFIG} ../../mach python ./build-clang.py -c ./${1}
|
python3 ./build-clang.py -c ./${1}
|
||||||
cd -
|
cd -
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user