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

Unified Diff: build/toolchain/clang_static_analyzer_wrapper.py

Issue 2617283002: Add Clang static analyzer to Clang toolchain defs in GN (Closed)
Patch Set: sylvain 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 side-by-side diff with in-line comments
Download patch
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..6f70e9a0c6240c95d3ee79aa3397f1cbf6675dd4
--- /dev/null
+++ b/build/toolchain/clang_static_analyzer_wrapper.py
@@ -0,0 +1,61 @@
+#!/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 shutil
+import sys
+import tempfile
+
+import wrapper_utils
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--clang-cc-path',
Nico 2017/01/11 20:20:05 can't the script hardcode that to script_dir/../..
Kevin M 2017/01/18 23:04:27 Acknowledged.
+ 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.',
+ required=True,
+ metavar='PATH')
+ args, compile_args = parser.parse_known_args()
+
+ # Check that only one of --clang-cc-path or --clang-cxx-path are set.
+ assert ((args.clang_cc_path != None) != (args.clang_cxx_path != None))
+ assert ((args.clang_cc_path != None) or (args.clang_cxx_path != None))
Wez 2017/01/14 00:04:58 Isn't this implicit from the != case? If they wer
Kevin M 2017/01/18 23:04:27 Both of them being set is also a failure case.
Wez 2017/01/21 01:10:15 But if both of them are set (or not-set) then (a !
Kevin M 2017/01/24 01:20:49 Done.
+
+ is_cxx = args.clang_cxx_path != None
+ env = os.environ
+ env['CCC_ANALYZER_FORCE_ANALYZE_DEBUG_CODE'] = '0'
+ env['CCC_ANALYZER_OUTPUT_FORMAT'] = 'text'
+ clang_path = args.clang_cxx_path or args.clang_cc_path
+ if is_cxx:
+ env['CCC_CXX'] = clang_path
+ env['CLANG_CXX'] = clang_path
Wez 2017/01/14 00:04:58 This differs from the previous version, where you
Kevin M 2017/01/18 23:04:28 Yes.
+ else:
+ env['CCC_CC'] = clang_path
+ env['CLANG'] = clang_path
+
+ temp_dir = tempfile.mkdtemp()
Wez 2017/01/14 00:04:58 Do we want to be dumping stuff in temp files, rath
Kevin M 2017/01/18 23:04:25 This is for unsummarized output files. We have som
Wez 2017/01/21 01:10:15 Acknowledged.
+ try:
+ env['CCC_ANALYZER_HTML'] = temp_dir
+ returncode, stderr = wrapper_utils.CaptureCommandStderr(
+ wrapper_utils.CommandToRun([args.analyzer] + compile_args), env)
+ sys.stderr.write(stderr)
Wez 2017/01/14 00:04:58 nit: It seems strange to "capture command stderr",
Kevin M 2017/01/18 23:04:27 I think this is the only way to get output to stde
Wez 2017/01/21 01:10:15 According to the documentation the default behavio
Kevin M 2017/01/24 01:20:49 Done.
+ return returncode
+ finally:
+ shutil.rmtree(temp_dir)
+
+if __name__ == "__main__":
+ sys.exit(main())

Powered by Google App Engine
This is Rietveld 408576698