Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions analyzer/codechecker_analyzer/buildlog/log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=<value>/
-target=<value>, 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.
Expand All @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the first branch where -target is separated from its parameter, the flag is not added to analyzer_options. What is the motivation of adding it here? Either both or none of the branches should have this logic. I vote for not adding it to analyzer_options, because this was the original behavior.


return True

return False


Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
]
26 changes: 26 additions & 0 deletions analyzer/tests/unit/test_log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=<value>' (and '-target=<value>') equals-sign form
must be parsed the same way as the space-separated '--target
<value>' 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.
Expand Down
Loading