Chromium Code Reviews| Index: build/toolchain/clang_static_analyzer_wrapper.py |
| diff --git a/build/toolchain/clang_static_analyzer_wrapper.py b/build/toolchain/clang_static_analyzer_wrapper.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..c5fa6544203af9c2203cc8307ec9707fc00d7616 |
| --- /dev/null |
| +++ b/build/toolchain/clang_static_analyzer_wrapper.py |
| @@ -0,0 +1,72 @@ |
| +#!/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. |
| + |
| +"""Invokes the Clang static analysis command using arguments provided on the |
| +command line. |
| +""" |
| + |
| +import argparse |
| +import fnmatch |
| +import os |
| +import sys |
| + |
| +import wrapper_utils |
| + |
| +def run_command(command, args, env=os.environ): |
| + returncode, stderr = wrapper_utils.CaptureCommandStderr( |
| + wrapper_utils.CommandToRun([command] + args), env) |
| + sys.stderr.write(stderr) |
| + return returncode |
| + |
| +def main(): |
| + parser = argparse.ArgumentParser(description=__doc__) |
| + parser.add_argument('--clang-cc-path', |
| + help='Path to the clang compiler.', |
| + metavar='PATH') |
| + parser.add_argument('--clang-cxx-path', |
| + help='Path to the clang++ compiler', |
| + metavar='PATH') |
| + parser.add_argument('--analyzer', |
| + help='Path to the language-specific Clang analysis tool.', |
| + metavar='PATH') |
| + args, compile_args = parser.parse_known_args() |
| + |
| + is_cxx = False |
| + if args.clang_cxx_path != None: |
|
Wez
2017/01/10 02:41:48
Should we assert that clang_cc_path is None if so?
Kevin M
2017/01/10 19:12:27
Did something different - moved the one-of validat
|
| + is_cxx = True |
| + |
| + command = None |
| + env = os.environ |
| + env['CCC_ANALYZER_FORCE_ANALYZE_DEBUG_CODE'] = '0' |
| + clang_path = None |
| + |
| + if args.clang_cc_path != None: |
| + env['CCC_CC'] = args.clang_cc_path |
| + env['CLANG'] = args.clang_cc_path |
| + clang_path = args.clang_cc_path |
| + if args.clang_cxx_path != None: |
| + env['CCC_CXX'] = args.clang_cxx_path |
| + env['CLANG'] = args.clang_cxx_path |
| + clang_path = args.clang_cc_path |
|
Wez
2017/01/10 02:41:48
typo cc -> cxx
Kevin M
2017/01/10 19:12:27
Done.
|
| + |
| + # Only one of CCC_CC or CCC_CXX must be set. |
| + assert (env.has_key('CCC_CC') or env.has_key('CCC_CXX')) |
| + assert (env.has_key('CCC_CC') != env.has_key('CCC_CXX')) |
| + |
| + returncode = run_command(args.analyzer, compile_args, env) |
| + if returncode == 0: |
| + return 0 |
| + else: |
| + sys.stderr.write('WARNING: static analysis failed with return code %d.' % |
| + returncode) |
| + |
| + if is_cxx: |
| + command = [args.clang_cxx_path] + compile_args |
|
Wez
2017/01/10 02:41:48
You don't seem to use |command|?
Kevin M
2017/01/10 19:12:27
Done.
|
| + return run_command(args.clang_cxx_path, compile_args) |
|
Wez
2017/01/10 02:41:48
Why not have a single run_command that uses clang_
Kevin M
2017/01/10 19:12:27
Need a fallback for the time being - there were a
Wez
2017/01/14 00:04:58
My comment was based on the fact that you were set
|
| + else: |
| + return run_command(args.clang_cc_path, compile_args) |
| + |
| +if __name__ == "__main__": |
| + sys.exit(main()) |