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 |
index 3a282ad48d5ae13feabc376a0525ed7f27419289..0ae62dabf7be04129b8f8639504009a262aa2dac 100755 |
--- a/build/toolchain/clang_static_analyzer_wrapper.py |
+++ b/build/toolchain/clang_static_analyzer_wrapper.py |
@@ -18,11 +18,11 @@ import wrapper_utils |
# Flags used to enable analysis for Clang invocations. |
analyzer_enable_flags = [ |
'--analyze', |
- '-fdiagnostics-show-option', |
] |
# Flags used to configure the analyzer's behavior. |
analyzer_option_flags = [ |
+ '-fdiagnostics-show-option', |
'-analyzer-checker=cplusplus', |
'-analyzer-opt-analyze-nested-blocks', |
'-analyzer-eagerly-assume', |
@@ -39,29 +39,27 @@ analyzer_option_flags = [ |
] |
-def main(): |
- args = sys.argv[1:] |
- assert args |
+# 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), ())) |
- # Build the object file and proceed with analysis if it is buildable. |
- returncode, stderr = wrapper_utils.CaptureCommandStderr( |
- wrapper_utils.CommandToRun(args)) |
- sys.stderr.write(stderr) |
- if returncode != 0: |
- return returncode |
- # Now run the analyzer. |
+def main(): |
+ parser = argparse.ArgumentParser() |
+ parser.add_argument('--mode', |
+ choices=['clang', 'cl'], |
+ required=True, |
+ help='Specifies the compiler argument convention to use.') |
+ parser.add_argument('args', nargs=argparse.REMAINDER) |
+ parsed_args = parser.parse_args() |
- # Interleave 'analyzer_option_flags' flags w/'-Xanalyzer' so that Clang |
- # passes them to the analysis tool. |
- # e.g. ['-analyzer-foo', '-analyzer-bar'] => ['-Xanalyzer', '-analyzer-foo', |
- # '-Xanalyzer', '-analyzer-bar'] |
- interleaved_analyzer_flags = list(sum(zip( |
- ['-Xanalyzer'] * len(analyzer_option_flags), |
- analyzer_option_flags), ())) |
+ 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( |
- wrapper_utils.CommandToRun(args + analyzer_enable_flags + |
- interleaved_analyzer_flags)) |
+ wrapper_utils.CommandToRun(cmd)) |
sys.stderr.write(stderr) |
if returncode != 0: |
sys.stderr.write( |
@@ -69,7 +67,11 @@ def main(): |
Please share the error details in crbug.com/695243 if this looks like |
a new regression.\n""" % (returncode)) |
- return 0 |
+ returncode, stderr = wrapper_utils.CaptureCommandStderr( |
+ wrapper_utils.CommandToRun(parsed_args.args)) |
+ sys.stderr.write(stderr) |
+ |
+ return returncode |
if __name__ == '__main__': |
sys.exit(main()) |