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 yaml dumper #3331

Merged
merged 1 commit into from
May 25, 2021
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
17 changes: 16 additions & 1 deletion analyzer/codechecker_analyzer/analyzers/clangsa/ctu_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tempfile
from pathlib import Path
from sys import maxsize
from yaml import Dumper

from codechecker_common.logger import get_logger

Expand All @@ -29,6 +30,18 @@
LOG = get_logger('analyzer')


class LLVMComatibleYamlDumper(Dumper):
def check_simple_key(self):
""" Mark every keys as simple keys.

PyYAML limits simple keys to '128' characters and this value can't be
changed (https://github.com/yaml/pyyaml/issues/157). To be compatible
with the YAML parser of LLVM we override this function and mark every
keys as simple keys.
"""
return True


def merge_clang_extdef_mappings(ctu_dir, ctu_func_map_file,
ctu_temp_fnmap_folder):
""" Merge individual function maps into a global one."""
Expand Down Expand Up @@ -87,7 +100,9 @@ def generate_invocation_list(triple_arch, action, source, config, env):
# Line width is set to max int size because of compatibility with the YAML
# parser of LLVM. We try to ensure that no lines break in the textual
# representation of the list items.
invocation_line = yaml.dump({str(source_path): cmd}, width=maxsize)
invocation_line = yaml.dump(
{str(source_path): cmd},
width=maxsize, Dumper=LLVMComatibleYamlDumper)

LOG.debug_analyzer("Appending invocation list item '%s'", invocation_line)

Expand Down
15 changes: 13 additions & 2 deletions analyzer/tests/functional/ctu/test_ctu.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ def test_ctu_ondemand_yaml_format(self):
""" Test the generated YAML used in CTU on-demand mode.
The YAML file should not contain newlines in individual entries in the
generated textual format. """
# Copy test files to a directory which file path will be longer than
# 128 chars to test the yaml parser.
test_dir = os.path.join(
self.test_workspace, os.path.join(*[
''.join('0' for _ in range(43)) for _ in range(0, 3)]))

shutil.copytree(self.test_dir, test_dir)

complex_buildlog = os.path.join(test_dir, 'complex_buildlog.json')
shutil.copy(self.complex_buildlog, complex_buildlog)
env.adjust_buildlog('complex_buildlog.json', test_dir, test_dir)

cmd = [self._codechecker_cmd, 'analyze',
'-o', self.report_dir,
Expand All @@ -275,8 +286,8 @@ def test_ctu_ondemand_yaml_format(self):
# intact only if a single ctu-phase is
# specified
'--ctu-ast-mode', 'parse-on-demand',
self.complex_buildlog]
_, _, result = call_command(cmd, cwd=self.test_dir, env=self.env)
complex_buildlog]
_, _, result = call_command(cmd, cwd=test_dir, env=self.env)
self.assertEqual(result, 0, "Analyzing failed.")

ctu_dir = os.path.join(self.report_dir, 'ctu-dir')
Expand Down