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 wrapper(cplusplus): """ This method implements basic compiler wrapper functionality. """ # initialize wrapper logging logging.basicConfig(format='analyze: %(levelname)s: %(message)s', level=os.getenv('BUILD_ANALYZE_VERBOSE', 'INFO')) # execute with real compiler compiler = os.getenv('BUILD_ANALYZE_CXX', 'c++') if cplusplus \ else os.getenv('BUILD_ANALYZE_CC', 'cc') compilation = [compiler] + sys.argv[1:] logging.info('execute compiler: %s', compilation) result = subprocess.call(compilation) try: # collect the needed parameters from environment, crash when missing consts = { 'clang': os.getenv('BUILD_ANALYZE_CLANG'), 'output_dir': os.getenv('BUILD_ANALYZE_REPORT_DIR'), 'output_format': os.getenv('BUILD_ANALYZE_REPORT_FORMAT'), 'report_failures': os.getenv('BUILD_ANALYZE_REPORT_FAILURES'), 'direct_args': os.getenv('BUILD_ANALYZE_PARAMETERS', '').split(' '), '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 is_source_file(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 compiler exit code return result