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

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: gni comment 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 sys
14
15 import wrapper_utils
16
17 def run_command(command, args, env=os.environ):
18 returncode, stderr = wrapper_utils.CaptureCommandStderr(
19 wrapper_utils.CommandToRun([command] + args), env)
20 sys.stderr.write(stderr)
21 return returncode
22
23 def main():
24 parser = argparse.ArgumentParser(description=__doc__)
25 parser.add_argument('--clang-cc-path',
26 help='Path to the clang compiler.',
27 metavar='PATH')
28 parser.add_argument('--clang-cxx-path',
29 help='Path to the clang++ compiler',
30 metavar='PATH')
31 parser.add_argument('--analyzer',
32 help='Path to the language-specific Clang analysis tool.',
33 metavar='PATH')
34 args, compile_args = parser.parse_known_args()
35
36 is_cxx = False
37 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
38 is_cxx = True
39
40 command = None
41 env = os.environ
42 env['CCC_ANALYZER_FORCE_ANALYZE_DEBUG_CODE'] = '0'
43 clang_path = None
44
45 if args.clang_cc_path != None:
46 env['CCC_CC'] = args.clang_cc_path
47 env['CLANG'] = args.clang_cc_path
48 clang_path = args.clang_cc_path
49 if args.clang_cxx_path != None:
50 env['CCC_CXX'] = args.clang_cxx_path
51 env['CLANG'] = args.clang_cxx_path
52 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.
53
54 # Only one of CCC_CC or CCC_CXX must be set.
55 assert (env.has_key('CCC_CC') or env.has_key('CCC_CXX'))
56 assert (env.has_key('CCC_CC') != env.has_key('CCC_CXX'))
57
58 returncode = run_command(args.analyzer, compile_args, env)
59 if returncode == 0:
60 return 0
61 else:
62 sys.stderr.write('WARNING: static analysis failed with return code %d.' %
63 returncode)
64
65 if is_cxx:
66 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.
67 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
68 else:
69 return run_command(args.clang_cc_path, compile_args)
70
71 if __name__ == "__main__":
72 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698