def handle_failure(source_analyzer, rh, zip_file, result_base, actions_map): """ If the analysis fails a debug zip is packed together which contains build, analysis information and source files to be able to reproduce the failed analysis. """ other_files = set() action = rh.buildaction try: LOG.debug("Fetching other dependent files from analyzer " "output...") other_files.update( source_analyzer.get_analyzer_mentioned_files(rh.analyzer_stdout)) other_files.update( source_analyzer.get_analyzer_mentioned_files(rh.analyzer_stderr)) except Exception as ex: LOG.debug("Couldn't generate list of other files " "from analyzer output:") LOG.debug(str(ex)) LOG.debug("Collecting debug data") buildactions = [{ 'file': action.source, 'command': action.original_command, 'directory': action.directory }] for of in other_files: mentioned_file = os.path.abspath(os.path.join(action.directory, of)) key = mentioned_file, action.target mentioned_file_action = actions_map.get(key) if mentioned_file_action is not None: buildactions.append({ 'file': mentioned_file_action.source, 'command': mentioned_file_action.original_command, 'directory': mentioned_file_action.directory }) else: LOG.debug("Could not find %s in build actions.", key) tu_collector.zip_tu_files(zip_file, buildactions) # TODO: What about the dependencies of the other_files? tu_collector.add_sources_to_zip( zip_file, map(lambda path: os.path.join(action.directory, path), other_files)) with zipfile.ZipFile(zip_file, 'a') as archive: LOG.debug("[ZIP] Writing analyzer STDOUT to /stdout") archive.writestr("stdout", rh.analyzer_stdout) LOG.debug("[ZIP] Writing analyzer STDERR to /stderr") archive.writestr("stderr", rh.analyzer_stderr) LOG.debug("[ZIP] Writing extra information...") archive.writestr("build-action", action.original_command) archive.writestr("analyzer-command", ' '.join(rh.analyzer_cmd)) archive.writestr("return-code", str(rh.analyzer_returncode)) toolchain = gcc_toolchain.toolchain_in_args( shlex.split(action.original_command)) if toolchain: archive.writestr("gcc-toolchain-path", toolchain) LOG.debug("ZIP file written at '%s'", zip_file) # Remove files that successfully analyzed earlier on. plist_file = result_base + ".plist" if os.path.exists(plist_file): os.remove(plist_file)
def handle_failure(source_analyzer, rh, zip_file, result_base, actions_map): """ If the analysis fails a debug zip is packed together which contains build, analysis information and source files to be able to reproduce the failed analysis. """ other_files = set() action = rh.buildaction try: LOG.debug("Fetching other dependent files from analyzer " "output...") other_files.update( source_analyzer.get_analyzer_mentioned_files(rh.analyzer_stdout)) other_files.update( source_analyzer.get_analyzer_mentioned_files(rh.analyzer_stderr)) except Exception as ex: LOG.debug("Couldn't generate list of other files " "from analyzer output:") LOG.debug(str(ex)) LOG.debug("Collecting debug data") buildactions = [{ 'file': action.source, 'command': action.original_command, 'directory': action.directory }] for of in other_files: mentioned_file = os.path.abspath(os.path.join(action.directory, of)) key = mentioned_file, action.target[action.lang] mentioned_file_action = actions_map.get(key) if mentioned_file_action is not None: buildactions.append({ 'file': mentioned_file_action.source, 'command': mentioned_file_action.original_command, 'directory': mentioned_file_action.directory }) else: LOG.debug("Could not find %s in build actions.", key) from tu_collector import tu_collector tu_collector.zip_tu_files(zip_file, buildactions) # TODO: What about the dependencies of the other_files? tu_collector.add_sources_to_zip( zip_file, [os.path.join(action.directory, path) for path in other_files]) with zipfile.ZipFile(zip_file, 'a') as archive: LOG.debug("[ZIP] Writing analyzer STDOUT to /stdout") archive.writestr("stdout", rh.analyzer_stdout) LOG.debug("[ZIP] Writing analyzer STDERR to /stderr") archive.writestr("stderr", rh.analyzer_stderr) LOG.debug("[ZIP] Writing extra information...") archive.writestr("build-action", action.original_command) archive.writestr("analyzer-command", ' '.join(rh.analyzer_cmd)) archive.writestr("return-code", str(rh.analyzer_returncode)) toolchain = gcc_toolchain.toolchain_in_args( shlex.split(action.original_command)) if toolchain: archive.writestr("gcc-toolchain-path", toolchain) LOG.debug("ZIP file written at '%s'", zip_file) # In case of compiler errors the error message still needs to be collected # from the standard output by this postprocess phase so we can present them # as CodeChecker reports. checks = source_analyzer.config_handler.checks() state = checks.get('clang-diagnostic-error', (CheckerState.default, ''))[0] if state != CheckerState.disabled: rh.postprocess_result() # Remove files that successfully analyzed earlier on. plist_file = result_base + ".plist" if os.path.exists(plist_file): os.remove(plist_file)