def test_write_exec_trace_with_response(self): with libear.temporary_directory() as tmp_dir: response_file_one = os.path.join(tmp_dir, 'response1.jom') response_file_two = os.path.join(tmp_dir, 'response2.jom') input_one = Execution(pid=123, cwd='/path/to/here', cmd=[ 'clang-cl', '-c', '@' + response_file_one, '-Idoes_not_exists', '@' + response_file_two ]) output_one = Execution(pid=123, cwd='/path/to/here', cmd=[ 'clang-cl', '-c', '-DSOMETHING_HERE', '-Idoes_not_exists', 'that.cpp' ]) with open(response_file_one, 'w') as response_file_one_handle: response_file_one_handle.write(' -DSOMETHING_HERE\n') with open(response_file_two, 'w') as response_file_two_handle: response_file_two_handle.write(' that.cpp\n') temp_file = os.path.join(tmp_dir, 'single_report.cmd') sut.write_exec_trace(temp_file, input_one) result = sut.parse_exec_trace(temp_file) self.assertEqual(output_one, result)
def test_read_write_exec_trace(self): input_one = Execution(pid=123, cwd='/path/to/here', cmd=['cc', '-c', 'this.c']) with libear.temporary_directory() as tmp_dir: temp_file = os.path.join(tmp_dir, 'single_report.cmd') sut.write_exec_trace(temp_file, input_one) result = sut.parse_exec_trace(temp_file) self.assertEqual(input_one, result)
def from_db_entry(cls, entry): # type: (Type[Compilation], Dict[str, str]) -> Iterable[Compilation] """ Parser method for compilation entry. From compilation database entry it creates the compilation object. :param entry: the compilation database entry :return: stream of CompilationDbEntry objects """ command = shell_split(entry['command']) if 'command' in entry else \ entry['arguments'] execution = Execution(cmd=command, cwd=entry['directory'], pid=0) return cls.iter_from_execution(execution)
def parse_exec_trace(filename): """ Parse execution report file. Given filename points to a file which contains the basic report generated by the interception library or compiler wrapper. :param filename: path to an execution trace file to read from, :return: an Execution object. """ logging.debug(filename) with open(filename, 'r') as handler: entry = json.load(handler) return Execution(pid=entry['pid'], cwd=entry['cwd'], cmd=entry['cmd'])
def from_db(entry): """ Factory method for compilation entry. From compilation database entry it creates the compilation object. :param entry: the compilation database entry :return: a single compilation object """ command = shell_split(entry['command']) if 'command' in entry else \ entry['arguments'] execution = Execution(cmd=command, cwd=entry['directory'], pid=0) entries = list(Compilation.from_call(execution)) assert len(entries) == 1 return entries[0]