def analyze_build_wrapper(cplusplus): """ Entry point for `analyze-cc` and `analyze-c++` compiler wrappers. """ # initialize wrapper logging logging.basicConfig(format='analyze: %(levelname)s: %(message)s', level=os.getenv('ANALYZE_BUILD_VERBOSE', 'INFO')) # execute with real compiler compiler = os.getenv('ANALYZE_BUILD_CXX', 'c++') if cplusplus \ else os.getenv('ANALYZE_BUILD_CC', 'cc') compilation = [compiler] + sys.argv[1:] logging.info('execute compiler: %s', compilation) result = subprocess.call(compilation) # exit when it fails, ... if result or not os.getenv('ANALYZE_BUILD_CLANG'): return result # ... and run the analyzer if all went well. try: # collect the needed parameters from environment, crash when missing consts = { 'clang': os.getenv('ANALYZE_BUILD_CLANG'), 'output_dir': os.getenv('ANALYZE_BUILD_REPORT_DIR'), 'output_format': os.getenv('ANALYZE_BUILD_REPORT_FORMAT'), 'output_failures': os.getenv('ANALYZE_BUILD_REPORT_FAILURES'), 'direct_args': os.getenv('ANALYZE_BUILD_PARAMETERS', '').split(' '), 'force_analyze_debug_code': os.getenv('ANALYZE_BUILD_FORCE_ANALYZE_DEBUG_CODE'), 'directory': os.getcwd(), } # get relevant parameters from command line arguments args = classify_parameters(sys.argv) filenames = args.pop('files', []) for filename in (name for name in filenames if classify_source(name)): parameters = dict(args, file=filename, **consts) logging.debug('analyzer parameters %s', parameters) current = action_check(parameters) # display error message from the static analyzer if current is not None: for line in current['error_output']: logging.info(line.rstrip()) except Exception: logging.exception("run analyzer inside compiler wrapper failed.") return 0
def language_check(opts, continuation=create_commands): """ Find out the language from command line parameters or file name extension. The decision also influenced by the compiler invocation. """ accepteds = {"c", "c++", "objective-c", "objective-c++", "c-cpp-output", "c++-cpp-output", "objective-c-cpp-output"} key = "language" language = opts[key] if key in opts else classify_source(opts["file"], opts["c++"]) if language is None: logging.debug("skip analysis, language not known") return None elif language not in accepteds: logging.debug("skip analysis, language not supported") return None else: logging.debug("analysis, language: %s", language) opts.update({key: language}) return continuation(opts)
def language_check(opts, continuation=create_commands): """ Find out the language from command line parameters or file name extension. The decision also influenced by the compiler invocation. """ accepteds = { 'c', 'c++', 'objective-c', 'objective-c++', 'c-cpp-output', 'c++-cpp-output', 'objective-c-cpp-output' } key = 'language' language = opts[key] if key in opts else \ classify_source(opts['file'], opts['c++']) if language is None: logging.debug('skip analysis, language not known') return None elif language not in accepteds: logging.debug('skip analysis, language not supported') return None else: logging.debug('analysis, language: %s', language) opts.update({key: language}) return continuation(opts)