def run_analyzer(args, output_dir): """ Runs the analyzer against the given compilation database. """ def exclude(filename): """ Return true when any excluded directory prefix the filename. """ return any(re.match(r'^' + directory, filename) for directory in args.excludes) consts = { 'clang': args.clang, 'output_dir': output_dir, 'output_format': args.output_format, 'output_failures': args.output_failures, 'direct_args': analyzer_params(args), 'force_debug': args.force_debug } logging.debug('run analyzer against compilation database') with open(args.cdb, 'r') as handle: generator = (dict(cmd, **consts) for cmd in json.load(handle) if not exclude(cmd['file'])) # when verbose output requested execute sequentially pool = multiprocessing.Pool(1 if args.verbose > 2 else None) for current in pool.imap_unordered(run, generator): logging_analyzer_output(current) pool.close() pool.join()
def analyze_build_wrapper(**kwargs): """ Entry point for `analyze-cc` and `analyze-c++` compiler wrappers. """ # don't run analyzer when compilation fails. if kwargs['result'] or not os.getenv('ANALYZE_BUILD_CLANG'): return # don't run analyzer when the command is not a compilation # (can be preprocessing or a linking only execution of the compiler) compilation = split_command(kwargs['command']) if compilation is None: return # collect the needed parameters from environment, crash when missing env = os.environ.copy() parameters = { 'clang': env['ANALYZE_BUILD_CLANG'], 'output_dir': env['ANALYZE_BUILD_REPORT_DIR'], 'output_format': env['ANALYZE_BUILD_REPORT_FORMAT'], 'output_failures': env.get('ANALYZE_BUILD_REPORT_FAILURES', False), 'direct_args': env.get('ANALYZE_BUILD_PARAMETERS', '').split(' '), 'force_debug': env.get('ANALYZE_BUILD_FORCE_DEBUG', False), 'directory': os.getcwd(), 'command': [kwargs['compiler'], '-c'] + compilation.flags } # call static analyzer against the compilation for source in compilation.files: current = run(dict(parameters, file=source)) # display error message from the static analyzer logging_analyzer_output(current)