OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """Invokes the Clang static analysis command using arguments provided on the |
| 7 command line. |
| 8 """ |
| 9 |
| 10 import argparse |
| 11 import fnmatch |
| 12 import os |
| 13 import shutil |
| 14 import sys |
| 15 import tempfile |
| 16 |
| 17 import wrapper_utils |
| 18 |
| 19 |
| 20 def main(): |
| 21 parser = argparse.ArgumentParser(description=__doc__) |
| 22 parser.add_argument('--clang-cc-path', |
| 23 help='Path to the clang compiler.', |
| 24 metavar='PATH') |
| 25 parser.add_argument('--clang-cxx-path', |
| 26 help='Path to the clang++ compiler', |
| 27 metavar='PATH') |
| 28 parser.add_argument('--analyzer', |
| 29 help='Path to the language-specific Clang analysis tool.', |
| 30 required=True, |
| 31 metavar='PATH') |
| 32 args, compile_args = parser.parse_known_args() |
| 33 |
| 34 # Check that only one of --clang-cc-path or --clang-cxx-path are set. |
| 35 assert ((args.clang_cc_path != None) != (args.clang_cxx_path != None)) |
| 36 |
| 37 is_cxx = args.clang_cxx_path != None |
| 38 env = os.environ |
| 39 env['CCC_ANALYZER_FORCE_ANALYZE_DEBUG_CODE'] = '0' |
| 40 env['CCC_ANALYZER_OUTPUT_FORMAT'] = 'text' |
| 41 clang_path = args.clang_cxx_path or args.clang_cc_path |
| 42 if is_cxx: |
| 43 env['CCC_CXX'] = clang_path |
| 44 env['CLANG_CXX'] = clang_path |
| 45 else: |
| 46 env['CCC_CC'] = clang_path |
| 47 env['CLANG'] = clang_path |
| 48 |
| 49 # TODO(kmarshall): Place the summarized output in a useful directory. |
| 50 temp_dir = tempfile.mkdtemp() |
| 51 try: |
| 52 env['CCC_ANALYZER_HTML'] = temp_dir |
| 53 returncode, stderr = wrapper_utils.CaptureCommandStderr( |
| 54 wrapper_utils.CommandToRun([args.analyzer] + compile_args), env) |
| 55 sys.stderr.write(stderr) |
| 56 return returncode |
| 57 finally: |
| 58 shutil.rmtree(temp_dir) |
| 59 |
| 60 if __name__ == "__main__": |
| 61 sys.exit(main()) |
OLD | NEW |