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
|
||||
# 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/.
|
||||
|
||||
# Only necessary for flake8 to be happy...
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import shutil
|
||||
@@ -18,7 +21,7 @@ import sys
|
||||
from contextlib import contextmanager
|
||||
from distutils.dir_util import copy_tree
|
||||
|
||||
from mozfile import which
|
||||
from shutil import which
|
||||
|
||||
URL_REPO = "https://github.com/llvm/llvm-project"
|
||||
|
||||
@@ -34,7 +37,7 @@ def symlink(source, link_name):
|
||||
|
||||
|
||||
def check_run(args):
|
||||
print >> sys.stderr, ' '.join(args)
|
||||
print(' '.join(args), file=sys.stderr)
|
||||
if args[0] == 'cmake':
|
||||
# CMake `message(STATUS)` messages, as appearing in failed source code
|
||||
# compiles, appear on stdout, so we only capture that.
|
||||
@@ -42,7 +45,7 @@ def check_run(args):
|
||||
lines = []
|
||||
for line in p.stdout:
|
||||
lines.append(line)
|
||||
sys.stdout.write(line)
|
||||
sys.stdout.write(line.decode())
|
||||
sys.stdout.flush()
|
||||
r = p.wait()
|
||||
if r != 0:
|
||||
@@ -60,8 +63,8 @@ def check_run(args):
|
||||
|
||||
def dump_file(log):
|
||||
with open(log, 'rb') as f:
|
||||
print >> sys.stderr, "\nContents of", log, "follow\n"
|
||||
print >> sys.stderr, f.read()
|
||||
print("\nContents of", log, "follow\n", file=sys.stderr)
|
||||
print(f.read(), file=sys.stderr)
|
||||
if output_match:
|
||||
dump_file(output_match.group(1))
|
||||
if error_match:
|
||||
@@ -73,10 +76,10 @@ def check_run(args):
|
||||
|
||||
def run_in(path, args):
|
||||
d = os.getcwd()
|
||||
print >> sys.stderr, 'cd "%s"' % path
|
||||
print('cd "%s"' % path, file=sys.stderr)
|
||||
os.chdir(path)
|
||||
check_run(args)
|
||||
print >> sys.stderr, 'cd "%s"' % d
|
||||
print('cd "%s"' % d, file=sys.stderr)
|
||||
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"),
|
||||
'-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",
|
||||
"x86_64-unknown-linux-gnu",
|
||||
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"
|
||||
|
||||
for target, cfg in android_targets.iteritems():
|
||||
for target, cfg in android_targets.items():
|
||||
sysroot_dir = cfg["ndk_sysroot"]
|
||||
android_gcc_dir = cfg["ndk_toolchain"]
|
||||
android_include_dirs = cfg["ndk_includes"]
|
||||
@@ -669,7 +672,7 @@ if __name__ == "__main__":
|
||||
if "android_targets" in config:
|
||||
android_targets = config["android_targets"]
|
||||
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:
|
||||
raise ValueError("must specify '%s' as a key for android target: %s" %
|
||||
(attr, target))
|
||||
@@ -678,7 +681,7 @@ if __name__ == "__main__":
|
||||
extra_targets = config["extra_targets"]
|
||||
if not isinstance(extra_targets, 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")
|
||||
if is_linux() and gcc_dir is None:
|
||||
raise ValueError("Config file needs to set gcc_dir")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
|
||||
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
|
||||
# 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/.
|
||||
@@ -34,9 +34,8 @@ def copy_dir_contents(src, dest):
|
||||
|
||||
|
||||
def write_cmake(module_path):
|
||||
names = map(lambda f: ' ' + os.path.basename(f),
|
||||
glob.glob("%s/*.cpp" % module_path))
|
||||
with open(os.path.join(module_path, 'CMakeLists.txt'), 'wb') as f:
|
||||
names = [' ' + os.path.basename(f) for f in glob.glob("%s/*.cpp" % module_path)]
|
||||
with open(os.path.join(module_path, 'CMakeLists.txt'), 'w') as f:
|
||||
f.write("""set(LLVM_LINK_COMPONENTS support)
|
||||
|
||||
add_definitions( -DCLANG_TIDY )
|
||||
@@ -76,13 +75,13 @@ def add_item_to_cmake_section(cmake_path, section, library):
|
||||
libs.append(library)
|
||||
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
|
||||
for line in lines:
|
||||
if line.find(section) > -1:
|
||||
seen_target_libs = True
|
||||
f.write(line)
|
||||
f.writelines(map(lambda p: ' ' + p + '\n', libs))
|
||||
f.writelines([' ' + p + '\n' for p in libs])
|
||||
continue
|
||||
elif seen_target_libs:
|
||||
if line.find(')') > -1:
|
||||
|
||||
@@ -14,8 +14,7 @@ cd $HOME_DIR/src
|
||||
set +x
|
||||
|
||||
cd build/build-clang
|
||||
# |mach python| sets up a virtualenv for us!
|
||||
../../mach python ./build-clang.py -c clang-4.0-linux64.json
|
||||
python3 ./build-clang.py -c clang-4.0-linux64.json
|
||||
|
||||
set -x
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ cd $HOME_DIR/src
|
||||
set +x
|
||||
|
||||
cd build/build-clang
|
||||
# |mach python| sets up a virtualenv for us!
|
||||
../../mach python ./build-clang.py -c clang-7-linux64.json
|
||||
python3 ./build-clang.py -c clang-7-linux64.json
|
||||
|
||||
set -x
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@ cd $HOME_DIR/src
|
||||
set +x
|
||||
|
||||
cd build/build-clang
|
||||
# |mach python| sets up a virtualenv for us!
|
||||
../../mach python ./build-clang.py -c clang-8-android.json
|
||||
python3 ./build-clang.py -c clang-8-android.json
|
||||
|
||||
set -x
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ export PATH="$WORKSPACE/build/src/binutils/bin:$PATH"
|
||||
set +x
|
||||
|
||||
cd build/build-clang
|
||||
# |mach python| sets up a virtualenv for us!
|
||||
../../mach python ./build-clang.py -c clang-8-linux64-aarch64-cross.json
|
||||
python3 ./build-clang.py -c clang-8-linux64-aarch64-cross.json
|
||||
|
||||
set -x
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@ export PATH=$PATH:$CROSS_CCTOOLS_PATH/bin
|
||||
set +x
|
||||
|
||||
cd build/build-clang
|
||||
# |mach python| sets up a virtualenv for us!
|
||||
../../mach python ./build-clang.py -c clang-8-macosx64.json --skip-tar
|
||||
python3 ./build-clang.py -c clang-8-macosx64.json --skip-tar
|
||||
|
||||
# We now have a native macosx64 toolchain.
|
||||
# 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
|
||||
|
||||
cd build/build-clang
|
||||
# |mach python| sets up a virtualenv for us!
|
||||
../../mach python ./build-clang.py -c clang-8-linux64.json
|
||||
python3 ./build-clang.py -c clang-8-linux64.json
|
||||
|
||||
set -x
|
||||
|
||||
|
||||
@@ -288,8 +288,7 @@ prepare
|
||||
set +x
|
||||
|
||||
cd build/build-clang
|
||||
# |mach python| sets up a virtualenv for us!
|
||||
../../mach python ./build-clang.py -c clang-8-mingw.json --skip-tar
|
||||
python3 ./build-clang.py -c clang-8-mingw.json --skip-tar
|
||||
|
||||
set -x
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@ export PATH=$PATH:$CROSS_CCTOOLS_PATH/bin
|
||||
set +x
|
||||
|
||||
cd build/build-clang
|
||||
# |mach python| sets up a virtualenv for us!
|
||||
../../mach python ./build-clang.py -c clang-8-macosx64.json
|
||||
python3 ./build-clang.py -c clang-8-macosx64.json
|
||||
|
||||
set -x
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ cd $HOME_DIR/src
|
||||
set +x
|
||||
|
||||
cd build/build-clang
|
||||
# |mach python| sets up a virtualenv for us!
|
||||
../../mach python ./build-clang.py -c clang-tidy-linux64.json
|
||||
python3 ./build-clang.py -c clang-tidy-linux64.json
|
||||
|
||||
set -x
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@ export PATH=$PATH:$CROSS_CCTOOLS_PATH/bin
|
||||
set +x
|
||||
|
||||
cd build/build-clang
|
||||
# |mach python| sets up a virtualenv for us!
|
||||
../../mach python ./build-clang.py -c clang-tidy-macosx64.json
|
||||
python3 ./build-clang.py -c clang-tidy-macosx64.json
|
||||
|
||||
set -x
|
||||
|
||||
|
||||
@@ -39,20 +39,12 @@ export PATH="$(pwd)/cmd:${PATH}"
|
||||
export PATH="$(cd cmake && 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
|
||||
set +x
|
||||
|
||||
BUILD_CLANG_DIR=build/src/build/build-clang
|
||||
cd ${BUILD_CLANG_DIR}
|
||||
MOZCONFIG=${MOZCONFIG} ../../mach python ./build-clang.py -c ./${1}
|
||||
python3 ./build-clang.py -c ./${1}
|
||||
cd -
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user