def test_skip_preproc(self): """ Compiler preprocessor actions should be marked as skipped. """ preprocessor_actions = StringIO('''[ {"directory": "/tmp", "command": "g++ /tmp/a.cpp -E /tmp/a.cpp", "file": "/tmp/a.cpp" }, {"directory": "/tmp", "command": "g++ /tmp/a.cpp -MT /tmp/a.cpp", "file": "/tmp/a.cpp" }, {"directory": "/tmp", "command": "g++ /tmp/a.cpp -MM /tmp/a.cpp", "file": "/tmp/a.cpp" }, {"directory": "/tmp", "command": "g++ /tmp/a.cpp -MF /tmp/a.cpp", "file": "/tmp/a.cpp" }, {"directory": "/tmp", "command": "g++ /tmp/a.cpp -M /tmp/a.cpp", "file": "/tmp/a.cpp" }] ''') build_actions = \ log_parser.parse_compile_commands_json(preprocessor_actions, ParseLogOptions()) for build_action in build_actions: self.assertTrue(build_action.skip)
def test_omit_preproc(self): """ Compiler preprocessor actions should be omitted. """ preprocessor_actions = StringIO('''[ {"directory": "/tmp", "command": "g++ /tmp/a.cpp -c /tmp/a.cpp", "file": "/tmp/a.cpp" }, {"directory": "/tmp", "command": "g++ /tmp/a.cpp -E /tmp/a.cpp", "file": "/tmp/a.cpp" }, {"directory": "/tmp", "command": "g++ /tmp/a.cpp -MT /tmp/a.cpp", "file": "/tmp/a.cpp" }, {"directory": "/tmp", "command": "g++ /tmp/a.cpp -MM /tmp/a.cpp", "file": "/tmp/a.cpp" }, {"directory": "/tmp", "command": "g++ /tmp/a.cpp -MF /tmp/a.cpp", "file": "/tmp/a.cpp" }, {"directory": "/tmp", "command": "g++ /tmp/a.cpp -M /tmp/a.cpp", "file": "/tmp/a.cpp" }] ''') build_actions = \ log_parser.parse_compile_commands_json(preprocessor_actions, ParseLogOptions()) self.assertEqual(len(build_actions), 1) self.assertTrue('-M' not in build_actions[0].original_command) self.assertTrue('-E' not in build_actions[0].original_command) self.assertTrue('-c' in build_actions[0].original_command)
def __get_comp_actions(self, compile_cmd): """ Generate a compilation command json file and parse it to return the compilation actions. """ comp_cmd_json = self.__get_cmp_json(compile_cmd) return log_parser.parse_compile_commands_json(comp_cmd_json, ParseLogOptions())
def __get_comp_actions(self, compile_cmd): """ Generate a compilation command json file and parse it to return the compilation actions. """ comp_cmd_json = self.__get_cmp_json(compile_cmd) with closing(StringIO(comp_cmd_json)) as text: return log_parser.parse_compile_commands_json( text, ParseLogOptions())
def test_keep_compile_and_dep(self): """ Keep the compile command if -MD is set. Dependency generation is done as a side effect of the compilation. """ preprocessor_actions = StringIO('''[ {"directory": "/tmp", "command": "g++ /tmp/a.cpp -MD /tmp/a.cpp", "file": "/tmp/a.cpp" }] ''') build_actions = \ log_parser.parse_compile_commands_json(preprocessor_actions, ParseLogOptions()) for build_action in build_actions: self.assertFalse(build_action.skip)
def test_keep_compile_and_dep(self): """ Keep the compile command if -MD is set. Dependency generation is done as a side effect of the compilation. """ preprocessor_actions = [{ "directory": "/tmp", "command": "g++ /tmp/a.cpp -MD /tmp/a.cpp", "file": "/tmp/a.cpp" }] build_actions = \ log_parser.parse_compile_commands_json(preprocessor_actions, ParseLogOptions()) self.assertEqual(len(build_actions), 1) self.assertTrue('-MD' in build_actions[0].original_command)
def test_omit_dep_with_e(self): """ Skip the compile command if -MD is set together with -E. """ preprocessor_actions = StringIO('''[ {"directory": "/tmp", "command": "g++ /tmp/a.cpp -MD -E /tmp/a.cpp", "file": "/tmp/a.cpp" }, {"directory": "/tmp", "command": "g++ /tmp/a.cpp -E -MD /tmp/a.cpp", "file": "/tmp/a.cpp" } ] ''') build_actions = \ log_parser.parse_compile_commands_json(preprocessor_actions, ParseLogOptions()) self.assertEqual(len(build_actions), 0)