blob: 0ae62dabf7be04129b8f8639504009a262aa2dac [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2017 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.
"""Adds an analysis build step to invocations of the Clang C/C++ compiler.
Usage: <compiler> [args...]
import argparse
import fnmatch
import itertools
import os
import sys
import wrapper_utils
# Flags used to enable analysis for Clang invocations.
analyzer_enable_flags = [
# Flags used to configure the analyzer's behavior.
analyzer_option_flags = [
# List of checkers to execute.
# The full list of checkers can be found at
# Prepends every element of a list |args| with |token|.
# e.g. ['-analyzer-foo', '-analyzer-bar'] => ['-Xanalyzer', '-analyzer-foo',
# '-Xanalyzer', '-analyzer-bar']
def interleave_args(args, token):
return list(sum(zip([token] * len(args), args), ()))
def main():
parser = argparse.ArgumentParser()
choices=['clang', 'cl'],
help='Specifies the compiler argument convention to use.')
parser.add_argument('args', nargs=argparse.REMAINDER)
parsed_args = parser.parse_args()
prefix = '-Xclang' if parsed_args.mode == 'cl' else '-Xanalyzer'
cmd = parsed_args.args + analyzer_enable_flags + \
interleave_args(analyzer_option_flags, prefix)
returncode, stderr = wrapper_utils.CaptureCommandStderr(
if returncode != 0:
"""WARNING! The Clang static analyzer exited with error code %d.
Please share the error details in if this looks like
a new regression.\n""" % (returncode))
returncode, stderr = wrapper_utils.CaptureCommandStderr(
return returncode
if __name__ == '__main__':