def test_read_write_exec_trace(self): input_one = { 'pid': 123, 'ppid': 121, 'function': 'wrapper', # it's a constant in the parse method 'directory': '/path/to/here', 'command': ['cc', '-c', 'this.c'] } input_two = { 'pid': 124, 'ppid': 121, 'function': 'wrapper', # it's a constant in the parse method 'directory': '/path/to/here', 'command': ['cc', '-c', 'that.c'] } # test with a single exec report with tempfile.NamedTemporaryFile() as temp_file: sut.write_exec_trace(temp_file.name, **input_one) result = sut.parse_exec_trace(temp_file.name) self.assertEqual([input_one], list(result)) # test with multiple exec report with tempfile.NamedTemporaryFile() as temp_file: sut.write_exec_trace(temp_file.name, **input_one) sut.write_exec_trace(temp_file.name, **input_two) result = sut.parse_exec_trace(temp_file.name) self.assertEqual([input_one, input_two], list(result))
def libscanbuild_capture( args: argparse.Namespace) -> Tuple[int, Iterable[Compilation]]: """ Implementation of compilation database generation. :param args: the parsed and validated command line arguments :return: the exit status of build process. """ from libscanbuild.intercept import setup_environment, run_build, exec_trace_files, parse_exec_trace, \ compilations from libear import temporary_directory with temporary_directory(prefix='intercept-') as tmp_dir: # run the build command environment = setup_environment(args, tmp_dir) if os.environ.get('PROS_TOOLCHAIN'): environment['PATH'] = os.path.join(os.environ.get('PROS_TOOLCHAIN'), 'bin') + os.pathsep + \ environment['PATH'] if sys.platform == 'darwin': environment['PATH'] = os.path.dirname(os.path.abspath(sys.executable)) + os.pathsep + \ environment['PATH'] exit_code = run_build(args.build, env=environment) # read the intercepted exec calls calls = (parse_exec_trace(file) for file in exec_trace_files(tmp_dir)) current = compilations(calls, args.cc, args.cxx) return exit_code, iter(set(current))
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 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 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)