Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: build/toolchain/clang_static_analyzer_wrapper.py

Issue 2617283002: Add Clang static analyzer to Clang toolchain defs in GN (Closed)
Patch Set: wez feedback Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 = wrapper_utils.RunCommand(
54 wrapper_utils.CommandToRun([args.analyzer] + compile_args), env)
55 return returncode
56 finally:
57 shutil.rmtree(temp_dir)
58
59 if __name__ == "__main__":
60 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698