Lines Matching +full:build +full:- +full:args
1 # -*- coding: utf-8 -*-
6 """ This module implements the 'scan-build' command API.
8 To run the static analyzer against a build is done in multiple steps:
10 -- Intercept: capture the compilation command during the build,
11 -- Analyze: run the analyzer against the captured commands,
12 -- Report: create a cover report from the analyzer outputs. """
32 COMPILER_WRAPPER_CC = 'analyze-cc'
33 COMPILER_WRAPPER_CXX = 'analyze-c++'
38 """ Entry point for 'analyze-build' and 'scan-build'. """
41 args = parser.parse_args()
42 validate(parser, args, from_build_command)
45 initialize_logging(args.verbose)
46 logging.debug('Parsed arguments: %s', args)
48 with report_directory(args.output, args.keep_empty) as target_dir:
51 run_analyzer(args, target_dir)
52 number_of_bugs = document(args, target_dir, True)
53 return number_of_bugs if args.status_bugs else 0
54 elif args.intercept_first:
55 # run build command and capture compiler executions
56 exit_code = capture(args, bin_dir)
58 if need_analyzer(args.build):
59 run_analyzer(args, target_dir)
61 number_of_bugs = document(args, target_dir, True)
63 if os.path.exists(args.cdb):
64 os.unlink(args.cdb)
66 return number_of_bugs if args.status_bugs else exit_code
70 # run the build command with compiler wrappers which
72 environment = setup_environment(args, target_dir, bin_dir)
73 logging.debug('run build in environment: %s', environment)
74 exit_code = subprocess.call(args.build, env=environment)
75 logging.debug('build finished with exit code: %d', exit_code)
77 number_of_bugs = document(args, target_dir, False)
79 return number_of_bugs if args.status_bugs else exit_code
82 def need_analyzer(args): argument
83 """ Check the intent of the build command.
88 To run `scan-build` against the configure step might be neccessary,
89 when compiler wrappers are used. That's the moment when build setup
90 check the compiler and capture the location for the build process. """
92 return len(args) and not re.search('configure|autogen', args[0])
95 def run_analyzer(args, output_dir): argument
101 for directory in args.excludes)
104 'clang': args.clang,
106 'output_format': args.output_format,
107 'output_failures': args.output_failures,
108 'direct_args': analyzer_params(args),
109 'force_debug': args.force_debug
113 with open(args.cdb, 'r') as handle:
117 pool = multiprocessing.Pool(1 if args.verbose > 2 else None)
127 def setup_environment(args, destination, bin_dir): argument
128 """ Set up environment for build command to interpose compiler wrapper. """
134 'ANALYZE_BUILD_CC': args.cc,
135 'ANALYZE_BUILD_CXX': args.cxx,
136 'ANALYZE_BUILD_CLANG': args.clang if need_analyzer(args.build) else '',
137 'ANALYZE_BUILD_VERBOSE': 'DEBUG' if args.verbose > 2 else 'WARNING',
139 'ANALYZE_BUILD_REPORT_FORMAT': args.output_format,
140 'ANALYZE_BUILD_REPORT_FAILURES': 'yes' if args.output_failures else '',
141 'ANALYZE_BUILD_PARAMETERS': ' '.join(analyzer_params(args)),
142 'ANALYZE_BUILD_FORCE_DEBUG': 'yes' if args.force_debug else ''
148 """ Entry point for `analyze-cc` and `analyze-c++` compiler wrappers. """
178 'command': [sys.argv[0], '-c'] + compilation.flags
194 def analyzer_params(args): argument
208 if args.store_model:
209 result.append('-analyzer-store={0}'.format(args.store_model))
210 if args.constraints_model:
211 result.append('-analyzer-constraints={0}'.format(
212 args.constraints_model))
213 if args.internal_stats:
214 result.append('-analyzer-stats')
215 if args.analyze_headers:
216 result.append('-analyzer-opt-analyze-headers')
217 if args.stats:
218 result.append('-analyzer-checker=debug.Stats')
219 if args.maxloop:
220 result.extend(['-analyzer-max-loop', str(args.maxloop)])
221 if args.output_format:
222 result.append('-analyzer-output={0}'.format(args.output_format))
223 if args.analyzer_config:
224 result.append(args.analyzer_config)
225 if args.verbose >= 4:
226 result.append('-analyzer-display-progress')
227 if args.plugins:
228 result.extend(prefix_with('-load', args.plugins))
229 if args.enable_checker:
230 checkers = ','.join(args.enable_checker)
231 result.extend(['-analyzer-checker', checkers])
232 if args.disable_checker:
233 checkers = ','.join(args.disable_checker)
234 result.extend(['-analyzer-disable-checker', checkers])
236 result.append('-analyzer-viz-egraph-ubigraph')
238 return prefix_with('-Xclang', result)
268 def validate(parser, args, from_build_command): argument
272 if args.help_checkers_verbose:
273 print_checkers(get_checkers(args.clang, args.plugins))
275 elif args.help_checkers:
276 print_active_checkers(get_checkers(args.clang, args.plugins))
279 if from_build_command and not args.build:
280 parser.error('missing build command')
290 '--verbose', '-v',
296 '--override-compiler',
301 '--intercept-first',
303 help="""Run the build commands only, build a compilation database,
305 Generally speaking it has better coverage on build commands.
306 With '--override-compiler' it use compiler wrapper, but does
307 not run the analyzer till the build is finished. """)
309 '--cdb',
315 '--output', '-o',
322 '--status-bugs',
325 executed build command. Specifying this option causes the exit
329 '--html-title',
334 '--analyze-headers',
341 '--plist', '-plist',
348 '--plist-html', '-plist-html',
350 const='plist-html',
355 # TODO: implement '-view '
359 '--keep-empty',
361 help="""Don't remove the build results directory even if no issues
364 '--no-failure-reports', '-no-failure-reports',
370 '--stats', '-stats',
375 '--internal-stats',
379 '--maxloop', '-maxloop',
386 '--store', '-store',
391 'region' specifies a field- sensitive store model.
394 checker-0.221 and earlier.""")
396 '--constraints', '-constraints',
402 checker-0.160 and earlier.""")
404 '--use-analyzer',
413 '--use-cc',
429 '--use-c++',
433 help="""This is the same as "--use-cc" but for C++ code.""")
435 '--analyzer-config', '-analyzer-config',
438 -analyzer-config flag. Several options are separated with
442 stable-report-filename=true or false (default)
445 report-<filename>-<function/method name>-<id>.html
446 instead of report-XXXXXX.html""")
448 '--exclude',
459 '--force-analyze-debug-code',
467 '--load-plugin', '-load-plugin',
473 '--enable-checker', '-enable-checker',
478 '--disable-checker', '-disable-checker',
483 '--help-checkers',
490 '--help-checkers-verbose',
496 dest='build',