diff --git a/analyzer/codechecker_analyzer/buildlog/log_parser.py b/analyzer/codechecker_analyzer/buildlog/log_parser.py index 05794d0147..8c87436f99 100644 --- a/analyzer/codechecker_analyzer/buildlog/log_parser.py +++ b/analyzer/codechecker_analyzer/buildlog/log_parser.py @@ -880,8 +880,8 @@ def __get_arch(flag_iterator, details): def __get_target(flag_iterator, details): """ - This function consumes --target or -target flag which is followed by the - compilation target architecture. + This function consumes --target/-target, or --target=/ + -target=, which specify the compilation target architecture. This target might be different from the default compilation target collected from the compiler if cross compilation is done for another target. @@ -892,6 +892,14 @@ def __get_target(flag_iterator, details): details['compilation_target'] = flag_iterator.item return True + for prefix in ['--target=', '-target=']: + if flag_iterator.item.startswith(prefix): + details['compilation_target'] = \ + flag_iterator.item[len(prefix):] + details['analyzer_options'].append(flag_iterator.item) + + return True + return False diff --git a/analyzer/tests/unit/logparser_test_files/target-equals-sign.json b/analyzer/tests/unit/logparser_test_files/target-equals-sign.json new file mode 100644 index 0000000000..81d4d33d3a --- /dev/null +++ b/analyzer/tests/unit/logparser_test_files/target-equals-sign.json @@ -0,0 +1,12 @@ +[ + { + "directory": "/tmp", + "command": "clang++ --target=aarch64-linux-gnu -c /tmp/a.cpp", + "file": "/tmp/a.cpp" + }, + { + "directory": "/tmp", + "command": "clang++ -target aarch64-linux-gnu -c /tmp/a.cpp", + "file": "/tmp/a.cpp" + } +] diff --git a/analyzer/tests/unit/test_log_parser.py b/analyzer/tests/unit/test_log_parser.py index f238561d5e..9ad496c0e2 100644 --- a/analyzer/tests/unit/test_log_parser.py +++ b/analyzer/tests/unit/test_log_parser.py @@ -81,6 +81,32 @@ def test_old_ldlogger(self): self.assertEqual(build_action.source, r'/tmp/a.cpp') self.assertEqual(len(build_action.analyzer_options), 1) + def test_target_equals_sign_form(self): + """ + Regression test for + https://github.com/Ericsson/codechecker/issues/1158 + + The '--target=' (and '-target=') equals-sign form + must be parsed the same way as the space-separated '--target + ' form. Previously, only the space-separated form was + recognized; the equals-sign form was silently dropped, causing + the compiler's own default target to be used instead of the + explicitly requested cross-compilation target. + """ + logfile = os.path.join( + self.__test_files, "target-equals-sign.json") + + build_actions, _ = log_parser.parse_unique_log(load_json(logfile)) + self.assertEqual(len(build_actions), 2) + + assert len(build_actions) == 2 + + equals_sign_action = build_actions[0] + space_separated_action = build_actions[1] + + self.assertEqual(equals_sign_action.target, 'aarch64-linux-gnu') + self.assertEqual(space_separated_action.target, 'aarch64-linux-gnu') + def test_new_ldlogger(self): """ Test log file parsing escape behaviour with after-#631 LD-LOGGER.