diff --git a/tools/clang/scripts/build_file.py b/tools/clang/scripts/build_file.py new file mode 100755 index 0000000..85f87231 --- /dev/null +++ b/tools/clang/scripts/build_file.py
@@ -0,0 +1,87 @@ +#!/usr/bin/env python +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import argparse +import json +import os +import re +import shlex +import sys + +script_dir = os.path.dirname(os.path.realpath(__file__)) +tool_dir = os.path.abspath(os.path.join(script_dir, '../pylib')) +sys.path.insert(0, tool_dir) + +from clang import compile_db + +_PROBABLY_CLANG_RE = re.compile(r'clang(?:\+\+)?$') + + +def ParseArgs(): + parser = argparse.ArgumentParser( + description='Utility to build one Chromium file for debugging clang') + parser.add_argument('-p', default='.', help='path to the compile database') + parser.add_argument('--generate-compdb', + help='regenerate the compile database') + parser.add_argument('--prefix', + help='optional prefix to prepend, e.g. --prefix=lldb') + parser.add_argument( + '--compiler', + help='compiler to override the compiler specied in the compile db') + parser.add_argument('--suffix', + help='optional suffix to append, e.g.' + + ' --suffix="-Xclang -ast-dump -fsyntax-only"') + parser.add_argument('target_file', help='file to build') + return parser.parse_args() + + +def BuildIt(record, prefix, compiler, suffix): + """Builds the file in the provided compile DB record. + + Args: + prefix: Optional prefix to prepend to the build command. + compiler: Optional compiler to override the compiler specified the record. + suffix: Optional suffix to append to the build command. + """ + raw_args = shlex.split(record['command']) + # The compile command might have some goop in front of it, e.g. if the build + # is using goma, so shift arguments off the front until raw_args[0] looks like + # a clang invocation. + while raw_args: + if _PROBABLY_CLANG_RE.search(raw_args[0]): + break + raw_args = raw_args[1:] + if not raw_args: + print 'error: command %s does not appear to invoke clang!' % record[ + 'command'] + return 2 + args = [] + if prefix: + args.extend(shlex.split(prefix)) + if compiler: + raw_args[0] = compiler + args.extend(raw_args) + if suffix: + args.extend(shlex.split(suffix)) + print 'Running %s' % ' '.join(args) + os.execv(args[0], args) + + +def main(): + args = ParseArgs() + os.chdir(args.p) + if args.generate_compdb: + compile_db.GenerateWithNinja('.') + db = compile_db.Read('.') + for record in db: + if os.path.normpath(os.path.join(args.p, record[ + 'file'])) == args.target_file: + return BuildIt(record, args.prefix, args.compiler, args.suffix) + print 'error: could not find %s in compile DB!' % args.target_file + return 1 + + +if __name__ == '__main__': + sys.exit(main())
diff --git a/tools/clang/scripts/run_tool.py b/tools/clang/scripts/run_tool.py index c1267da..68f12e98 100755 --- a/tools/clang/scripts/run_tool.py +++ b/tools/clang/scripts/run_tool.py
@@ -40,34 +40,22 @@ import argparse import collections import functools -import json import multiprocessing import os import os.path import subprocess import sys +script_dir = os.path.dirname(os.path.realpath(__file__)) +tool_dir = os.path.abspath(os.path.join(script_dir, '../pylib')) +sys.path.insert(0, tool_dir) + +from clang import compile_db + Edit = collections.namedtuple('Edit', ('edit_type', 'offset', 'length', 'replacement')) -def _GenerateCompileDatabase(path): - """Generates a compile database. - - Note: requires ninja. - - Args: - path: The build directory to generate a compile database for. - """ - # TODO(dcheng): Incorporate Windows-specific compile DB munging from - # https://codereview.chromium.org/718873004 - print 'Generating compile database in %s...' % path - args = ['ninja', '-C', path, '-t', 'compdb', 'cc', 'cxx', 'objc', 'objcxx'] - output = subprocess.check_output(args) - with file(os.path.join(path, 'compile_commands.json'), 'w') as f: - f.write(output) - - def _GetFilesFromGit(paths=None): """Gets the list of files in the git repository. @@ -93,12 +81,8 @@ Args: build_directory: Directory that contains the compile database. """ - compiledb_path = os.path.join(build_directory, 'compile_commands.json') - with open(compiledb_path, 'rb') as compiledb_file: - json_commands = json.load(compiledb_file) - return [os.path.join(entry['directory'], entry['file']) - for entry in json_commands] + for entry in compile_db.Read(build_directory)] def _ExtractEditsFromStdout(build_directory, stdout): @@ -325,7 +309,7 @@ os.environ['PATH']) if args.generate_compdb: - _GenerateCompileDatabase(args.compile_database) + compile_db.GenerateWithNinja(args.compile_database) if args.all: filenames = set(_GetFilesFromCompileDB(args.compile_database))
diff --git a/tools/clang/scripts/update.py b/tools/clang/scripts/update.py index 0e2028e..4211e3077 100755 --- a/tools/clang/scripts/update.py +++ b/tools/clang/scripts/update.py
@@ -26,7 +26,7 @@ # Do NOT CHANGE this if you don't know what you're doing -- see # https://chromium.googlesource.com/chromium/src/+/master/docs/updating_clang.md # Reverting problematic clang rolls is safe, though. -CLANG_REVISION = '263324' +CLANG_REVISION = '264334' use_head_revision = 'LLVM_FORCE_HEAD_REVISION' in os.environ if use_head_revision: @@ -437,13 +437,17 @@ [cxx, '-print-file-name=libstdc++.so.6']).rstrip() os.environ['LD_LIBRARY_PATH'] = os.path.dirname(libstdcpp) - cflags = cxxflags = ldflags = [] + cflags = [] + cxxflags = [] + ldflags = [] base_cmake_args = ['-GNinja', '-DCMAKE_BUILD_TYPE=Release', '-DLLVM_ENABLE_ASSERTIONS=ON', '-DLLVM_ENABLE_THREADS=OFF', '-DLLVM_ENABLE_TIMESTAMPS=OFF', + # Statically link MSVCRT to avoid DLL dependencies. + '-DLLVM_USE_CRT_RELEASE=MT', ] if args.bootstrap: @@ -476,6 +480,10 @@ # https://stackoverflow.com/questions/13050827 cc = cc.replace('\\', '/') cxx = cxx.replace('\\', '/') + # If we're using VS 2015, tell the stage 1 compiler to act like it. + if GetVSVersion().ShortName().startswith('2015'): + cflags += ['-fms-compatibility-version=19'] + cxxflags += ['-fms-compatibility-version=19'] else: cc = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang') cxx = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang++')