summaryrefslogtreecommitdiff
path: root/chromium/tools/clang
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/tools/clang')
-rwxr-xr-xchromium/tools/clang/pylib/clang/compile_db.py14
-rwxr-xr-xchromium/tools/clang/pylib/clang/plugin_testing.py14
-rwxr-xr-xchromium/tools/clang/scripts/build_clang_tools_extra.py91
-rwxr-xr-xchromium/tools/clang/scripts/clang_tidy_tool.py199
-rwxr-xr-xchromium/tools/clang/scripts/package.py19
-rwxr-xr-xchromium/tools/clang/scripts/process_crashreports.py117
-rwxr-xr-xchromium/tools/clang/scripts/update.py122
-rw-r--r--chromium/tools/clang/traffic_annotation_extractor/traffic_annotation_extractor.cpp6
8 files changed, 420 insertions, 162 deletions
diff --git a/chromium/tools/clang/pylib/clang/compile_db.py b/chromium/tools/clang/pylib/clang/compile_db.py
index 5c769d886fd..3e8e12b393a 100755
--- a/chromium/tools/clang/pylib/clang/compile_db.py
+++ b/chromium/tools/clang/pylib/clang/compile_db.py
@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+from __future__ import print_function
+
import json
import os
import re
@@ -32,9 +34,9 @@ def _ProcessCommand(command):
command = ' '.join(
[match_dict['clang'], '--driver-mode=cl', match_dict['args']])
elif _debugging:
- print 'Compile command didn\'t match expected regex!'
- print 'Command:', command
- print 'Regex:', _CMD_LINE_RE.pattern
+ print('Compile command didn\'t match expected regex!')
+ print('Command:', command)
+ print('Regex:', _CMD_LINE_RE.pattern)
return command
@@ -56,7 +58,7 @@ def _ProcessEntry(entry):
entry['command'][match.end(1):]])
except IOError:
if _debugging:
- print 'Couldn\'t read response file for %s' % entry['file']
+ print('Couldn\'t read response file for %s' % entry['file'])
return entry
@@ -77,7 +79,7 @@ def ProcessCompileDatabaseIfNeeded(compile_db):
return compile_db
if _debugging:
- print 'Read in %d entries from the compile db' % len(compile_db)
+ print('Read in %d entries from the compile db' % len(compile_db))
compile_db = [_ProcessEntry(e) for e in compile_db]
original_length = len(compile_db)
@@ -86,7 +88,7 @@ def ProcessCompileDatabaseIfNeeded(compile_db):
compile_db = [e for e in compile_db if '_nacl.cc.pdb' not in e['command']
and '_nacl_win64.cc.pdb' not in e['command']]
if _debugging:
- print 'Filtered out %d entries...' % (original_length - len(compile_db))
+ print('Filtered out %d entries...' % (original_length - len(compile_db)))
# TODO(dcheng): Also filter out multiple commands for the same file. Not sure
# how that happens, but apparently it's an issue on Windows.
diff --git a/chromium/tools/clang/pylib/clang/plugin_testing.py b/chromium/tools/clang/pylib/clang/plugin_testing.py
index ca8559b5a97..ba8bb13b0af 100755
--- a/chromium/tools/clang/pylib/clang/plugin_testing.py
+++ b/chromium/tools/clang/pylib/clang/plugin_testing.py
@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+from __future__ import print_function
+
import glob
import os
import subprocess
@@ -43,7 +45,7 @@ class ClangPluginTest(object):
Returns: the number of failing tests.
"""
- print 'Using clang %s...' % self._clang_path
+ print('Using clang %s...' % self._clang_path)
os.chdir(self._test_base)
@@ -68,16 +70,16 @@ class ClangPluginTest(object):
failure_message = self.RunOneTest(test_name, cmd)
if failure_message:
- print 'failed: %s' % failure_message
+ print('failed: %s' % failure_message)
failing.append(test_name)
else:
- print 'passed!'
+ print('passed!')
passing.append(test_name)
- print 'Ran %d tests: %d succeeded, %d failed' % (
- len(passing) + len(failing), len(passing), len(failing))
+ print('Ran %d tests: %d succeeded, %d failed' % (
+ len(passing) + len(failing), len(passing), len(failing)))
for test in failing:
- print ' %s' % test
+ print(' %s' % test)
return len(failing)
def RunOneTest(self, test_name, cmd):
diff --git a/chromium/tools/clang/scripts/build_clang_tools_extra.py b/chromium/tools/clang/scripts/build_clang_tools_extra.py
new file mode 100755
index 00000000000..12db0ad3ba0
--- /dev/null
+++ b/chromium/tools/clang/scripts/build_clang_tools_extra.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+# Copyright 2019 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.
+
+"""A script for fetching LLVM monorepo and building clang-tools-extra binaries.
+
+Example: build clangd and clangd-indexer
+
+ tools/clang/scripts/build_clang_tools_extra.py --fetch out/Release clangd \
+ clangd-indexer
+"""
+
+import argparse
+import errno
+import os
+import subprocess
+import sys
+
+
+def GetCheckoutDir(out_dir):
+ """Returns absolute path to the checked-out llvm repo."""
+ return os.path.join(out_dir, 'tools', 'clang', 'third_party', 'llvm')
+
+
+def GetBuildDir(out_dir):
+ return os.path.join(GetCheckoutDir(out_dir), 'build')
+
+
+def CreateDirIfNotExists(dir):
+ if not os.path.exists(dir):
+ os.makedirs(dir)
+
+
+def FetchLLVM(checkout_dir):
+ """Clone llvm repo into |out_dir| or update if it already exists."""
+ CreateDirIfNotExists(os.path.dirname(checkout_dir))
+
+ try:
+ # First, try to clone the repo.
+ args = [
+ 'git',
+ 'clone',
+ 'https://github.com/llvm/llvm-project.git',
+ checkout_dir,
+ ]
+ subprocess.check_call(args, shell=sys.platform == 'win32')
+ except subprocess.CalledProcessError:
+ # Otherwise, try to update it.
+ print('-- Attempting to update existing repo')
+ args = ['git', 'pull', '--rebase', 'origin', 'master']
+ subprocess.check_call(args, cwd=checkout_dir)
+
+
+def BuildTargets(build_dir, targets):
+ """Build targets from llvm repo at |build_dir|."""
+ CreateDirIfNotExists(build_dir)
+
+ # From that dir, run cmake
+ cmake_args = [
+ 'cmake',
+ '-GNinja',
+ '-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra',
+ '-DCMAKE_BUILD_TYPE=Release',
+ '-DLLVM_ENABLE_ASSERTIONS=On',
+ '../llvm',
+ ]
+ subprocess.check_call(cmake_args, cwd=build_dir)
+
+ ninja_commands = ['ninja'] + targets
+ subprocess.check_call(ninja_commands, cwd=build_dir)
+
+
+def main():
+ parser = argparse.ArgumentParser(description='Build clang_tools_extra.')
+ parser.add_argument(
+ '--fetch', action='store_true', help='fetch LLVM source')
+ parser.add_argument('OUT_DIR', help='where we put the LLVM source repository')
+ parser.add_argument('TARGETS', nargs='+', help='targets being built')
+ args = parser.parse_args()
+
+ if args.fetch:
+ print 'Fetching LLVM source'
+ FetchLLVM(GetCheckoutDir(args.OUT_DIR))
+
+ print 'Building targets: %s' % ', '.join(args.TARGETS)
+ BuildTargets(GetBuildDir(args.OUT_DIR), args.TARGETS)
+
+
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/chromium/tools/clang/scripts/clang_tidy_tool.py b/chromium/tools/clang/scripts/clang_tidy_tool.py
index b12e77ba6dc..7bc16e2b1c4 100755
--- a/chromium/tools/clang/scripts/clang_tidy_tool.py
+++ b/chromium/tools/clang/scripts/clang_tidy_tool.py
@@ -13,6 +13,14 @@ enables the clang static analyzer checks.
--checks='-*,clang-analyzer-*,-clang-analyzer-alpha*' \\
--header-filter='.*' \\
out/Release chrome
+
+The same, but checks the changes only.
+
+ git diff -U5 | tools/clang/scripts/clang_tidy_tool.py \\
+ --diff \\
+ --checks='-*,clang-analyzer-*,-clang-analyzer-alpha*' \\
+ --header-filter='.*' \\
+ out/Release chrome
"""
import argparse
@@ -20,95 +28,59 @@ import os
import subprocess
import sys
+import build_clang_tools_extra
-def GetCheckoutDir(out_dir):
- """Returns absolute path to the checked-out llvm repo."""
- return os.path.join(out_dir, 'tools', 'clang', 'third_party', 'llvm')
-
-
-def GetBuildDir(out_dir):
- return os.path.join(GetCheckoutDir(out_dir), 'build')
-
-
-def FetchClang(out_dir):
- """Clone llvm repo into |out_dir| or update if it already exists."""
- checkout_dir = GetCheckoutDir(out_dir)
-
- try:
- # Create parent directories of the checkout directory
- os.makedirs(os.path.dirname(checkout_dir))
- except OSError:
- pass
-
- try:
- # First, try to clone the repo.
- args = [
- 'git',
- 'clone',
- 'https://github.com/llvm/llvm-project.git',
- checkout_dir,
- ]
- subprocess.check_call(args, shell=sys.platform == 'win32')
- except subprocess.CalledProcessError:
- # Otherwise, try to update it.
- print('-- Attempting to update existing repo')
- args = ['git', 'pull', '--rebase', 'origin', 'master']
- subprocess.check_call(args, cwd=checkout_dir)
-
-
-def BuildClang(out_dir):
- """Build clang from llvm repo at |GetCheckoutDir(out_dir)|."""
- # Make <checkout>/build directory
- build_dir = GetBuildDir(out_dir)
- try:
- os.mkdir(build_dir)
- except OSError as e:
- # Ignore errno 17 'File Exists'
- if e.errno != 17:
- raise e
-
- # From that dir, run cmake
- cmake_args = [
- 'cmake',
- '-GNinja',
- '-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra',
- '-DCMAKE_BUILD_TYPE=Release',
- '../llvm',
- ]
- subprocess.check_call(cmake_args, cwd=build_dir)
- ninja_args = [
- 'ninja',
- 'clang-tidy',
- 'clang-apply-replacements',
- ]
- subprocess.check_call(ninja_args, cwd=build_dir)
+def GetBinaryPath(build_dir, binary):
+ if sys.platform == 'win32':
+ binary += '.exe'
+ return os.path.join(build_dir, 'bin', binary)
def BuildNinjaTarget(out_dir, ninja_target):
- args = ['ninja', '-C', out_dir, ninja_target]
- subprocess.check_call(args)
+ args = ['autoninja', '-C', out_dir, ninja_target]
+ subprocess.check_call(args, shell=sys.platform == 'win32')
def GenerateCompDb(out_dir):
gen_compdb_script = os.path.join(
os.path.dirname(__file__), 'generate_compdb.py')
- comp_db_file = os.path.join(out_dir, 'compile_commands.json')
- args = [gen_compdb_script, '-p', out_dir, '-o', comp_db_file]
+ comp_db_file_path = os.path.join(out_dir, 'compile_commands.json')
+ args = [
+ sys.executable,
+ gen_compdb_script,
+ '-p',
+ out_dir,
+ '-o',
+ comp_db_file_path,
+ ]
subprocess.check_call(args)
+ # The resulting CompDb file includes /showIncludes which causes clang-tidy to
+ # output a lot of unnecessary text to the console.
+ with open(comp_db_file_path, 'r') as comp_db_file:
+ comp_db_data = comp_db_file.read();
+
+ # The trailing space on /showIncludes helps keep single-spaced flags.
+ comp_db_data = comp_db_data.replace('/showIncludes ', '')
-def RunClangTidy(checks, header_filter, auto_fix, out_dir, ninja_target):
- """Invoke the |clang-tidy| binary."""
+ with open(comp_db_file_path, 'w') as comp_db_file:
+ comp_db_file.write(comp_db_data)
+
+
+def RunClangTidy(checks, header_filter, auto_fix, clang_src_dir,
+ clang_build_dir, out_dir, ninja_target):
+ """Invoke the |run-clang-tidy.py| script."""
run_clang_tidy_script = os.path.join(
- GetCheckoutDir(out_dir), 'clang-tools-extra', 'clang-tidy', 'tool',
+ clang_src_dir, 'clang-tools-extra', 'clang-tidy', 'tool',
'run-clang-tidy.py')
- clang_tidy_binary = os.path.join(GetBuildDir(out_dir), 'bin', 'clang-tidy')
- clang_apply_rep_binary = os.path.join(
- GetBuildDir(out_dir), 'bin', 'clang-apply-replacements')
+ clang_tidy_binary = GetBinaryPath(clang_build_dir, 'clang-tidy')
+ clang_apply_rep_binary = GetBinaryPath(clang_build_dir,
+ 'clang-apply-replacements')
args = [
+ sys.executable,
run_clang_tidy_script,
'-quiet',
'-p',
@@ -132,6 +104,37 @@ def RunClangTidy(checks, header_filter, auto_fix, out_dir, ninja_target):
subprocess.check_call(args)
+def RunClangTidyDiff(checks, header_filter, auto_fix, clang_src_dir,
+ clang_build_dir, out_dir):
+ """Invoke the |clang-tidy-diff.py| script over the diff from stdin."""
+ clang_tidy_diff_script = os.path.join(
+ clang_src_dir, 'clang-tools-extra', 'clang-tidy', 'tool',
+ 'clang-tidy-diff.py')
+
+ clang_tidy_binary = GetBinaryPath(clang_build_dir, 'clang-tidy')
+
+ args = [
+ clang_tidy_diff_script,
+ '-quiet',
+ '-p1',
+ '-path',
+ out_dir,
+ '-clang-tidy-binary',
+ clang_tidy_binary,
+ ]
+
+ if checks:
+ args.append('-checks={}'.format(checks))
+
+ if header_filter:
+ args.append('-header-filter={}'.format(header_filter))
+
+ if auto_fix:
+ args.append('-fix')
+
+ subprocess.check_call(args)
+
+
def main():
script_name = sys.argv[0]
@@ -143,6 +146,15 @@ def main():
'--build',
action='store_true',
help='build clang sources to get clang-tidy')
+ parser.add_argument(
+ '--diff',
+ action='store_true',
+ default=False,
+ help ='read diff from the stdin and check it')
+ parser.add_argument('--clang-src-dir', type=str,
+ help='override llvm and clang checkout location')
+ parser.add_argument('--clang-build-dir', type=str,
+ help='override clang build dir location')
parser.add_argument('--checks', help='passed to clang-tidy')
parser.add_argument('--header-filter', help='passed to clang-tidy')
parser.add_argument(
@@ -155,20 +167,49 @@ def main():
steps = []
+ # If the user hasn't provided a clang checkout and build dir, checkout and
+ # build clang-tidy where update.py would.
+ if not args.clang_src_dir:
+ args.clang_src_dir = build_clang_tools_extra.GetCheckoutDir(args.OUT_DIR)
+ if not args.clang_build_dir:
+ args.clang_build_dir = build_clang_tools_extra.GetBuildDir(args.OUT_DIR)
+ elif (args.clang_build_dir and not
+ os.path.isfile(GetBinaryPath(args.clang_build_dir, 'clang-tidy'))):
+ sys.exit('clang-tidy binary doesn\'t exist at ' +
+ GetBinaryPath(args.clang_build_dir, 'clang-tidy'))
+
+
if args.fetch:
- steps.append(('Fetching clang sources', lambda: FetchClang(args.OUT_DIR)))
+ steps.append(('Fetching LLVM sources', lambda:
+ build_clang_tools_extra.FetchLLVM(args.clang_src_dir)))
if args.build:
- steps.append(('Building clang', lambda: BuildClang(args.OUT_DIR)))
+ steps.append(('Building clang-tidy',
+ lambda: build_clang_tools_extra.BuildTargets(
+ args.clang_build_dir,
+ ['clang-tidy', 'clang-apply-replacements'])))
steps += [
('Building ninja target: %s' % args.NINJA_TARGET,
- lambda: BuildNinjaTarget(args.OUT_DIR, args.NINJA_TARGET)),
- ('Generating compilation DB', lambda: GenerateCompDb(args.OUT_DIR)),
- ('Running clang-tidy',
- lambda: RunClangTidy(args.checks, args.header_filter, args.auto_fix, args
- .OUT_DIR, args.NINJA_TARGET)),
- ]
+ lambda: BuildNinjaTarget(args.OUT_DIR, args.NINJA_TARGET)),
+ ('Generating compilation DB', lambda: GenerateCompDb(args.OUT_DIR))
+ ]
+ if args.diff:
+ steps += [
+ ('Running clang-tidy on diff',
+ lambda: RunClangTidyDiff(args.checks, args.header_filter,
+ args.auto_fix, args.clang_src_dir,
+ args.clang_build_dir, args.OUT_DIR,
+ args.NINJA_TARGET)),
+ ]
+ else:
+ steps += [
+ ('Running clang-tidy',
+ lambda: RunClangTidy(args.checks, args.header_filter,
+ args.auto_fix, args.clang_src_dir,
+ args.clang_build_dir, args.OUT_DIR,
+ args.NINJA_TARGET)),
+ ]
# Run the steps in sequence.
for i, (msg, step_func) in enumerate(steps):
diff --git a/chromium/tools/clang/scripts/package.py b/chromium/tools/clang/scripts/package.py
index 169fe10b2a6..8310d7caa3b 100755
--- a/chromium/tools/clang/scripts/package.py
+++ b/chromium/tools/clang/scripts/package.py
@@ -217,7 +217,7 @@ def main():
if sys.platform.startswith('linux'):
opt_flags += ['--lto-lld']
build_cmd = [sys.executable, os.path.join(THIS_DIR, 'update.py'),
- '--bootstrap', '--force-local-build',
+ '--bootstrap', '--disable-asserts', '--force-local-build',
'--run-tests'] + opt_flags
TeeCmd(build_cmd, log)
@@ -466,18 +466,6 @@ def main():
filter=PrintTarProgress)
MaybeUpload(args, objdumpdir, platform)
- # Zip up llvm-cfi-verify for CFI coverage.
- cfiverifydir = 'llvmcfiverify-' + stamp
- shutil.rmtree(cfiverifydir, ignore_errors=True)
- os.makedirs(os.path.join(cfiverifydir, 'bin'))
- shutil.copy(os.path.join(LLVM_RELEASE_DIR, 'bin', 'llvm-cfi-verify' +
- exe_ext),
- os.path.join(cfiverifydir, 'bin'))
- with tarfile.open(cfiverifydir + '.tgz', 'w:gz') as tar:
- tar.add(os.path.join(cfiverifydir, 'bin'), arcname='bin',
- filter=PrintTarProgress)
- MaybeUpload(args, cfiverifydir, platform)
-
# On Mac, lld isn't part of the main zip. Upload it in a separate zip.
if sys.platform == 'darwin':
llddir = 'lld-' + stamp
@@ -494,8 +482,9 @@ def main():
filter=PrintTarProgress)
MaybeUpload(args, llddir, platform)
- # dsymutil isn't part of the main zip either, and it gets periodically deployed to CIPD
- # (manually, not as part of clang rolls) for use in the Mac build toolchain.
+ # dsymutil isn't part of the main zip either, and it gets periodically
+ # deployed to CIPD (manually, not as part of clang rolls) for use in the
+ # Mac build toolchain.
dsymdir = 'dsymutil-' + stamp
shutil.rmtree(dsymdir, ignore_errors=True)
os.makedirs(os.path.join(dsymdir, 'bin'))
diff --git a/chromium/tools/clang/scripts/process_crashreports.py b/chromium/tools/clang/scripts/process_crashreports.py
new file mode 100755
index 00000000000..f623fc08efb
--- /dev/null
+++ b/chromium/tools/clang/scripts/process_crashreports.py
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+# Copyright 2019 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.
+
+"""Looks for crash reports in tools/clang/crashreports and uploads them to GCS.
+"""
+
+import argparse
+import datetime
+import getpass
+import glob
+import os
+import shutil
+import subprocess
+import sys
+import tarfile
+import tempfile
+
+
+GCS_BUCKET = 'chrome-clang-crash-reports'
+THIS_DIR = os.path.dirname(__file__)
+CRASHREPORTS_DIR = os.path.join(THIS_DIR, '..', 'crashreports')
+GSUTIL = os.path.join(
+ THIS_DIR, '..', '..', '..', 'third_party', 'depot_tools', 'gsutil.py')
+
+
+def ProcessCrashreport(base, source):
+ """Zip up all files belonging to a crash base name and upload them to GCS."""
+ sys.stdout.write('processing %s... ' % base)
+ sys.stdout.flush()
+
+ # Note that this will include the .sh and other files:
+ files = glob.glob(os.path.join(CRASHREPORTS_DIR, base + '.*'))
+
+ # Path design.
+ # - For each crash, it should be easy to see which platform it was on,
+ # and which configuration it happened for.
+ # - Crash prefixes should be regular so that a second bot could download
+ # crash reports and auto-triage them.
+ # - Ideally the assert reason would be easily visible too, but clang doesn't
+ # write that to disk.
+ # Prepend with '/v1' so that we can move to other schemes in the future if
+ # needed.
+ # /v1/yyyy-mm-dd/botname-basename.tgz
+ now = datetime.datetime.now()
+ dest = 'gs://%s/v1/%04d/%02d/%02d/%s-%s.tgz' % (
+ GCS_BUCKET, now.year, now.month, now.day, source, base)
+
+ # zipfile.ZipFile() defaults to Z_DEFAULT_COMPRESSION (6) and that can't
+ # be overridden until Python 3.7. tarfile always uses compression level 9,
+ # so use tarfile.
+ tmp_name = None
+ try:
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.tgz') as tmp:
+ tmp_name = tmp.name
+ sys.stdout.write('compressing... ')
+ sys.stdout.flush()
+ with tarfile.open(mode='w:gz', fileobj=tmp) as tgz:
+ for f in files:
+ tgz.add(f, os.path.basename(f))
+ sys.stdout.write('uploading... ')
+ sys.stdout.flush()
+ subprocess.check_call([sys.executable, GSUTIL, '-q', 'cp', tmp_name, dest])
+ print 'done'
+ print ' %s' % dest
+ finally:
+ if tmp_name:
+ os.remove(tmp_name)
+
+
+def DeleteCrashFiles():
+ for root, dirs, files in os.walk(CRASHREPORTS_DIR, topdown=True):
+ for d in dirs:
+ print 'removing dir', d
+ shutil.rmtree(os.path.join(root, d))
+ for f in files:
+ if f != '.gitignore':
+ print 'removing', f
+ os.remove(os.path.join(root, f))
+ del dirs[:] # Abort os.walk() after one level.
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--delete', dest='delete', action='store_true',
+ help='Delete all crashreports after processing them '
+ '(default)')
+ parser.add_argument('--no-delete', dest='delete', action='store_false',
+ help='Do not delete crashreports after processing them')
+ parser.set_defaults(delete=True)
+ parser.add_argument('--source', default='user-' + getpass.getuser(),
+ help='Source of the crash -- usually a bot name. '
+ 'Leave empty to use your username.')
+ args = parser.parse_args()
+ # When clang notices that it crashes, it tries to write a .sh file containing
+ # the command used to invoke clang, a source file containing the whole
+ # input source code with an extension matching the input file (.c, .cpp, ...),
+ # and potentially other temp files and directories.
+ # If generating the unified input source file fails, the .sh file won't
+ # be written. (see Driver::generateCompilationDiagnostics()).
+ # As a heuristic, find all .sh files in the crashreports directory, then
+ # zip each up along with all other files that have the same basename with
+ # different extensions.
+ for reproducer in glob.glob(os.path.join(CRASHREPORTS_DIR, '*.sh')):
+ base = os.path.splitext(os.path.basename(reproducer))[0]
+ ProcessCrashreport(base, args.source)
+
+ if args.delete:
+ DeleteCrashFiles()
+
+
+if __name__ == '__main__':
+ try:
+ main()
+ except Exception as e:
+ print 'got exception:', e
diff --git a/chromium/tools/clang/scripts/update.py b/chromium/tools/clang/scripts/update.py
index 2ced82971d8..c284aff1e3b 100755
--- a/chromium/tools/clang/scripts/update.py
+++ b/chromium/tools/clang/scripts/update.py
@@ -7,6 +7,8 @@
It is also used by package.py to build the prebuilt clang binaries."""
+from __future__ import print_function
+
import argparse
import distutils.spawn
import glob
@@ -20,14 +22,20 @@ import sys
import tarfile
import tempfile
import time
-import urllib2
+
+try:
+ import urllib2 as urllib
+except ImportError: # For Py3 compatibility
+ import urllib.request as urllib
+ import urllib.error as urllib
+
import zipfile
# 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 = '354873'
+CLANG_REVISION = '357692'
use_head_revision = bool(os.environ.get('LLVM_FORCE_HEAD_REVISION', '0')
in ('1', 'YES'))
@@ -82,6 +90,8 @@ LLVM_REPO_URL='https://llvm.org/svn/llvm-project'
if 'LLVM_REPO_URL' in os.environ:
LLVM_REPO_URL = os.environ['LLVM_REPO_URL']
+BUG_REPORT_URL = ('https://crbug.com and run tools/clang/scripts/upload_crash.py'
+ ' (only works inside Google) which will upload a report')
def DownloadUrl(url, output_file):
@@ -95,7 +105,7 @@ def DownloadUrl(url, output_file):
try:
sys.stdout.write('Downloading %s ' % url)
sys.stdout.flush()
- response = urllib2.urlopen(url)
+ response = urllib.urlopen(url)
total_size = int(response.info().getheader('Content-Length').strip())
bytes_done = 0
dots_printed = 0
@@ -110,17 +120,17 @@ def DownloadUrl(url, output_file):
sys.stdout.flush()
dots_printed = num_dots
if bytes_done != total_size:
- raise urllib2.URLError("only got %d of %d bytes" %
- (bytes_done, total_size))
- print ' Done.'
+ raise urllib.URLError("only got %d of %d bytes" %
+ (bytes_done, total_size))
+ print(' Done.')
return
- except urllib2.URLError as e:
+ except urllib.URLError as e:
sys.stdout.write('\n')
- print e
- if num_retries == 0 or isinstance(e, urllib2.HTTPError) and e.code == 404:
+ print(e)
+ if num_retries == 0 or isinstance(e, urllib.HTTPError) and e.code == 404:
raise e
num_retries -= 1
- print 'Retrying in %d s ...' % retry_wait_s
+ print('Retrying in %d s ...' % retry_wait_s)
time.sleep(retry_wait_s)
retry_wait_s *= 2
@@ -218,10 +228,10 @@ def RunCommand(command, msvc_arch=None, env=None, fail_hard=True):
# do the single-string transformation there.
if sys.platform != 'win32':
command = ' '.join([pipes.quote(c) for c in command])
- print 'Running', command
+ print('Running', command)
if subprocess.call(command, env=env, shell=True) == 0:
return True
- print 'Failed.'
+ print('Failed.')
if fail_hard:
sys.exit(1)
return False
@@ -229,7 +239,7 @@ def RunCommand(command, msvc_arch=None, env=None, fail_hard=True):
def CopyFile(src, dst):
"""Copy a file from src to dst."""
- print "Copying %s to %s" % (src, dst)
+ print("Copying %s to %s" % (src, dst))
shutil.copy(src, dst)
@@ -243,17 +253,17 @@ def CopyDirectoryContents(src, dst):
def Checkout(name, url, dir):
"""Checkout the SVN module at url into dir. Use name for the log message."""
- print "Checking out %s r%s into '%s'" % (name, CLANG_REVISION, dir)
+ print("Checking out %s r%s into '%s'" % (name, CLANG_REVISION, dir))
command = ['svn', 'checkout', '--force', url + '@' + CLANG_REVISION, dir]
if RunCommand(command, fail_hard=False):
return
if os.path.isdir(dir):
- print "Removing %s." % (dir)
+ print("Removing %s." % dir)
RmTree(dir)
- print "Retrying."
+ print("Retrying.")
RunCommand(command)
@@ -350,7 +360,7 @@ def AddGnuWinToPath():
GNUWIN_VERSION = '9'
GNUWIN_STAMP = os.path.join(gnuwin_dir, 'stamp')
if ReadStampFile(GNUWIN_STAMP) == GNUWIN_VERSION:
- print 'GNU Win tools already up to date.'
+ print('GNU Win tools already up to date.')
else:
zip_name = 'gnuwin-%s.zip' % GNUWIN_VERSION
DownloadAndUnpack(CDS_URL + '/tools/' + zip_name, LLVM_BUILD_TOOLS_DIR)
@@ -439,8 +449,8 @@ def VeryifyVersionOfBuiltClangMatchesVERSION():
version_out = subprocess.check_output([clang, '--version'])
version_out = re.match(r'clang version ([0-9.]+)', version_out).group(1)
if version_out != VERSION:
- print ('unexpected clang version %s (not %s), update VERSION in update.py'
- % (version_out, VERSION))
+ print('unexpected clang version %s (not %s), update VERSION in update.py'
+ % (version_out, VERSION))
sys.exit(1)
@@ -461,10 +471,10 @@ def DownloadAndUnpackClangPackage(platform, runtimes_only=False):
if runtimes_only:
path_prefix = 'lib/clang/' + VERSION + '/lib/'
DownloadAndUnpack(cds_full_url, LLVM_BUILD_DIR, path_prefix)
- except urllib2.URLError:
- print 'Failed to download prebuilt clang %s' % cds_file
- print 'Use --force-local-build if you want to build locally.'
- print 'Exiting.'
+ except urllib.URLError:
+ print('Failed to download prebuilt clang %s' % cds_file)
+ print('Use --force-local-build if you want to build locally.')
+ print('Exiting.')
sys.exit(1)
@@ -500,24 +510,24 @@ def UpdateClang(args):
return 0
if args.with_android and not os.path.exists(ANDROID_NDK_DIR):
- print 'Android NDK not found at ' + ANDROID_NDK_DIR
- print 'The Android NDK is needed to build a Clang whose -fsanitize=address'
- print 'works on Android. See '
- print 'https://www.chromium.org/developers/how-tos/android-build-instructions'
- print 'for how to install the NDK, or pass --without-android.'
+ print('Android NDK not found at ' + ANDROID_NDK_DIR)
+ print('The Android NDK is needed to build a Clang whose -fsanitize=address')
+ print('works on Android. See ')
+ print('https://www.chromium.org/developers/how-tos/android-build-instructions')
+ print('for how to install the NDK, or pass --without-android.')
return 1
if args.with_fuchsia and not os.path.exists(FUCHSIA_SDK_DIR):
- print 'Fuchsia SDK not found at ' + FUCHSIA_SDK_DIR
- print 'The Fuchsia SDK is needed to build libclang_rt for Fuchsia.'
- print 'Install the Fuchsia SDK by adding fuchsia to the '
- print 'target_os section in your .gclient and running hooks, '
- print 'or pass --without-fuchsia.'
- print 'https://chromium.googlesource.com/chromium/src/+/master/docs/fuchsia_build_instructions.md'
- print 'for general Fuchsia build instructions.'
+ print('Fuchsia SDK not found at ' + FUCHSIA_SDK_DIR)
+ print('The Fuchsia SDK is needed to build libclang_rt for Fuchsia.')
+ print('Install the Fuchsia SDK by adding fuchsia to the ')
+ print('target_os section in your .gclient and running hooks, ')
+ print('or pass --without-fuchsia.')
+ print('https://chromium.googlesource.com/chromium/src/+/master/docs/fuchsia_build_instructions.md')
+ print('for general Fuchsia build instructions.')
return 1
- print 'Locally building Clang %s...' % PACKAGE_VERSION
+ print('Locally building Clang %s...' % PACKAGE_VERSION)
AddCMakeToPath(args)
AddGnuWinToPath()
@@ -539,7 +549,8 @@ def UpdateClang(args):
targets = 'AArch64;ARM;Mips;PowerPC;SystemZ;WebAssembly;X86'
base_cmake_args = ['-GNinja',
'-DCMAKE_BUILD_TYPE=Release',
- '-DLLVM_ENABLE_ASSERTIONS=ON',
+ '-DLLVM_ENABLE_ASSERTIONS=%s' %
+ ('OFF' if args.disable_asserts else 'ON'),
'-DLLVM_ENABLE_PIC=OFF',
'-DLLVM_ENABLE_TERMINFO=OFF',
'-DLLVM_TARGETS_TO_BUILD=' + targets,
@@ -550,6 +561,7 @@ def UpdateClang(args):
'-DCLANG_ENABLE_ARCMT=OFF',
# TODO(crbug.com/929645): Use newer toolchain to host.
'-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON',
+ '-DBUG_REPORT_URL=' + BUG_REPORT_URL,
]
if sys.platform != 'win32':
@@ -557,7 +569,7 @@ def UpdateClang(args):
base_cmake_args.append('-DLLVM_ENABLE_LIBXML2=FORCE_ON')
if args.bootstrap:
- print 'Building bootstrap compiler'
+ print('Building bootstrap compiler')
EnsureDirExists(LLVM_BOOTSTRAP_DIR)
os.chdir(LLVM_BOOTSTRAP_DIR)
bootstrap_args = base_cmake_args + [
@@ -565,6 +577,8 @@ def UpdateClang(args):
'-DCMAKE_INSTALL_PREFIX=' + LLVM_BOOTSTRAP_INSTALL_DIR,
'-DCMAKE_C_FLAGS=' + ' '.join(cflags),
'-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
+ # Ignore args.disable_asserts for the bootstrap compiler.
+ '-DLLVM_ENABLE_ASSERTIONS=ON',
]
if cc is not None: bootstrap_args.append('-DCMAKE_C_COMPILER=' + cc)
if cxx is not None: bootstrap_args.append('-DCMAKE_CXX_COMPILER=' + cxx)
@@ -588,7 +602,7 @@ def UpdateClang(args):
cc = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang')
cxx = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang++')
- print 'Building final compiler'
+ print('Building final compiler')
# LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is
# needed, on OS X it requires libc++. clang only automatically links to libc++
@@ -631,8 +645,8 @@ def UpdateClang(args):
# Build lld and code coverage tools. This is done separately from the rest of
# the build because these tools require threading support.
- tools_with_threading = [ 'lld', 'llvm-cov', 'llvm-profdata' ]
- print 'Building the following tools with threading support: %s' % (
+ tools_with_threading = [ 'dsymutil', 'lld', 'llvm-cov', 'llvm-profdata' ]
+ print('Building the following tools with threading support: %s' %
str(tools_with_threading))
if os.path.exists(THREADS_ENABLED_BUILD_DIR):
@@ -825,10 +839,8 @@ def UpdateClang(args):
os.mkdir(os.path.join(build_dir))
os.chdir(build_dir)
target_triple = target_arch
- abi_libs = 'c++abi'
if target_arch == 'arm':
target_triple = 'armv7'
- abi_libs += ';unwind'
target_triple += '-linux-android' + api_level
cflags = ['--target=%s' % target_triple,
'--sysroot=%s/sysroot' % toolchain_dir,
@@ -841,8 +853,7 @@ def UpdateClang(args):
'-DCMAKE_C_FLAGS=' + ' '.join(cflags),
'-DCMAKE_CXX_FLAGS=' + ' '.join(cflags),
'-DCMAKE_ASM_FLAGS=' + ' '.join(cflags),
- '-DSANITIZER_CXX_ABI=none',
- '-DSANITIZER_CXX_ABI_LIBRARY=' + abi_libs,
+ '-DSANITIZER_CXX_ABI=libcxxabi',
'-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-u__cxa_demangle',
'-DANDROID=1']
RmCmakeCache('.')
@@ -926,7 +937,7 @@ def UpdateClang(args):
RunCommand(['ninja', 'check-all'], msvc_arch='x64')
WriteStampFile(PACKAGE_VERSION)
- print 'Clang update was successful.'
+ print('Clang update was successful.')
return 0
@@ -943,6 +954,8 @@ def main():
parser = argparse.ArgumentParser(description='Build Clang.')
parser.add_argument('--bootstrap', action='store_true',
help='first build clang with CC, then with itself.')
+ parser.add_argument('--disable-asserts', action='store_true',
+ help='build with asserts disabled')
parser.add_argument('--force-local-build', action='store_true',
help="don't try to download prebuild binaries")
parser.add_argument('--gcc-toolchain', help='set the version for which gcc '
@@ -983,10 +996,10 @@ def main():
args = parser.parse_args()
if args.lto_lld and not args.bootstrap:
- print '--lto-lld requires --bootstrap'
+ print('--lto-lld requires --bootstrap')
return 1
if args.lto_lld and not sys.platform.startswith('linux'):
- print '--lto-lld is only effective on Linux. Ignoring the option.'
+ print('--lto-lld is only effective on Linux. Ignoring the option.')
args.lto_lld = False
# Get svn if we're going to use it to check the revision or do a local build.
@@ -995,23 +1008,24 @@ def main():
AddSvnToPathOnWin()
if args.verify_version and args.verify_version != VERSION:
- print 'VERSION is %s but --verify-version argument was %s, exiting.' % (
- VERSION, args.verify_version)
- print 'clang_version in build/toolchain/toolchain.gni is likely outdated.'
+ print('VERSION is %s but --verify-version argument was %s, exiting.' % (
+ VERSION, args.verify_version))
+ print('clang_version in build/toolchain/toolchain.gni is likely outdated.')
return 1
# DEVELOPER_DIR needs to be set when Xcode isn't in a standard location
# and xcode-select wasn't run. This is needed for running clang and ld
# for the build done by this script, but it's also needed for running
- # macOS system svn, so this needs to happen before calling functions using svn.
+ # macOS system svn, so this needs to happen before calling functions using
+ # svn.
SetMacXcodePath()
global CLANG_REVISION, PACKAGE_VERSION
if args.print_revision:
if use_head_revision or args.llvm_force_head_revision:
- print GetSvnRevision(LLVM_DIR)
+ print(GetSvnRevision(LLVM_DIR))
else:
- print PACKAGE_VERSION
+ print(PACKAGE_VERSION)
return 0
if args.print_clang_version:
diff --git a/chromium/tools/clang/traffic_annotation_extractor/traffic_annotation_extractor.cpp b/chromium/tools/clang/traffic_annotation_extractor/traffic_annotation_extractor.cpp
index 5d68093529e..b1e64db3be1 100644
--- a/chromium/tools/clang/traffic_annotation_extractor/traffic_annotation_extractor.cpp
+++ b/chromium/tools/clang/traffic_annotation_extractor/traffic_annotation_extractor.cpp
@@ -32,6 +32,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/ArgumentsAdjusters.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/Tooling.h"
@@ -157,7 +158,7 @@ class NetworkAnnotationTagCallback : public MatchFinder::MatchCallback {
void GetInstanceLocation(const MatchFinder::MatchResult& result,
const clang::Expr* expr,
Location* location) {
- clang::SourceLocation source_location = expr->getLocStart();
+ clang::SourceLocation source_location = expr->getBeginLoc();
if (source_location.isMacroID())
source_location = result.SourceManager->getExpansionLoc(source_location);
location->file_path = result.SourceManager->getFilename(source_location);
@@ -398,6 +399,7 @@ int main(int argc, const char* argv[]) {
clang::tooling::CommonOptionsParser options(argc, argv, ToolCategory);
clang::tooling::ClangTool tool(options.getCompilations(),
options.getSourcePathList());
+ tool.appendArgumentsAdjuster(clang::tooling::getStripPluginsAdjuster());
Collector collector;
llvm::InitializeNativeTarget();
@@ -442,4 +444,4 @@ int main(int argc, const char* argv[]) {
}
return 0;
-} \ No newline at end of file
+}