Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[analyzer] Fix check for response files #3474

Merged
Merged
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
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/buildlog/log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ def extend_compilation_database_entries(compilation_database):

entry['command'] = ' '.join(cmd)

if '@' in entry['file']:
if entry['file'].startswith('@'):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add the following test case to https://github.com/Ericsson/codechecker/blob/master/analyzer/tests/unit/test_log_parser.py file:

    def test_source_file_contains_at_sign(self):
        """
        Test source file which path contains '@' sign in path.

        Source file path can contain '@' sign which doesn't mean it is a
        response file.
        """
        with tempfile.TemporaryDirectory(suffix='@') as tmp_dir:
            src_file_path = shutil.copy(self.src_file_path, tmp_dir)

            with open(self.compile_command_file_path, "w",
                      encoding="utf-8", errors="ignore") as f:
                f.write(json.dumps([dict(
                    directory=tmp_dir,
                    command=f"g++ {src_file_path}",
                    file=src_file_path
                )]))
            
        build_actions, _ = log_parser.parse_unique_log(load_json_or_empty(
            self.compile_command_file_path), self.__this_dir)

        self.assertEqual(len(build_actions), 1)

        build_action = build_actions[0]
        self.assertEqual(build_action.source, src_file_path)

Just to make sure if it works properly.

for source_file in source_files:
new_entry = dict(entry)
new_entry['file'] = source_file
Expand Down
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 @@ -526,3 +526,29 @@ def test_response_file_contains_multiple_source_files(self):
if b.source == b_file_path][0]
self.assertEqual(len(b_build_action.analyzer_options), 1)
self.assertEqual(b_build_action.analyzer_options[0], '-DVARIABLE=some')

def test_source_file_contains_at_sign(self):
"""
Test source file which path contains '@' sign in path.

Source file path can contain '@' sign which doesn't mean it is a
response file.
"""
with tempfile.TemporaryDirectory(suffix='@') as tmp_dir:
src_file_path = shutil.copy(self.src_file_path, tmp_dir)

with open(self.compile_command_file_path, "w",
encoding="utf-8", errors="ignore") as f:
f.write(json.dumps([dict(
directory=tmp_dir,
command=f"g++ {src_file_path}",
file=src_file_path
)]))

build_actions, _ = log_parser.parse_unique_log(load_json_or_empty(
self.compile_command_file_path), self.__this_dir)

self.assertEqual(len(build_actions), 1)

build_action = build_actions[0]
self.assertEqual(build_action.source, src_file_path)