Skip to content

Commit

Permalink
[refactor] Simplify report-converter package structure
Browse files Browse the repository at this point in the history
- Use `codechecker_report_converter` as the module name to avoid conflicts.
- Move converters to the root module directory.
- Use `cli.py` as the command line script name.
- Use absolute imports in the main cli script.
- Use `output_parser.Parser` instread of `output_parser.OutputParser`.
  • Loading branch information
csordasmarton committed Jan 16, 2020
1 parent 72c6807 commit b5dacdf
Show file tree
Hide file tree
Showing 32 changed files with 80 additions and 107 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ build_report_converter:

package_report_converter: build_report_converter package_dir_structure
# Copy tu_collector files.
cp -rp $(CC_TOOLS)/report-converter/build/report_converter/report_converter $(CC_BUILD_LIB_DIR) && \
chmod u+x $(CC_BUILD_LIB_DIR)/report_converter/ReportConverter.py && \
cp -rp $(CC_TOOLS)/report-converter/build/report_converter/codechecker_report_converter $(CC_BUILD_LIB_DIR) && \
chmod u+x $(CC_BUILD_LIB_DIR)/codechecker_report_converter/cli.py && \
cd $(CC_BUILD_DIR) && \
ln -sf ../lib/python2.7/report_converter/ReportConverter.py bin/report-converter
ln -sf ../lib/python2.7/codechecker_report_converter/cli.py bin/report-converter

package: package_dir_structure set_git_commit_template package_plist_to_html package_tu_collector package_report_converter
BUILD_DIR=$(BUILD_DIR) BUILD_LOGGER_64_BIT_ONLY=$(BUILD_LOGGER_64_BIT_ONLY) $(MAKE) -C $(CC_ANALYZER) package_analyzer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import os
import re

from ..output_parser import Message, Event, OutputParser
from ..output_parser import Message, Event, BaseParser

LOG = logging.getLogger('ReportConverter')


class ClangTidyOutputParser(OutputParser):
class ClangTidyParser(BaseParser):
""" Parser for clang-tidy console output. """

def __init__(self):
super(ClangTidyOutputParser, self).__init__()
super(ClangTidyParser, self).__init__()

# Regex for parsing a clang-tidy message.
self.message_line_re = re.compile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from __future__ import absolute_import

from ..plist_converter import PlistConverter
from .output_parser import ClangTidyOutputParser
from .output_parser import ClangTidyParser


class ClangTidyPlistConverter(PlistConverter):
Expand All @@ -20,7 +20,7 @@ class ClangTidyPlistConverter(PlistConverter):

def parse_messages(self, output):
""" Parse the given output. """
parser = ClangTidyOutputParser()
parser = ClangTidyParser()
return parser.parse_messages(output)

def _get_checker_category(self, checker):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,16 @@
import shutil
import sys

try:
from .converter.clang_tidy.plist_converter import \
ClangTidyPlistConverter
from .converter.sanitizers.address.plist_converter import \
ASANPlistConverter
from .converter.sanitizers.memory.plist_converter import \
MSANPlistConverter
from .converter.sanitizers.thread.plist_converter import \
TSANPlistConverter
from .converter.sanitizers.ub.plist_converter import \
UBSANPlistConverter
except ValueError:
# Attempted relative import in non-package.
from converter.clang_tidy.plist_converter import \
ClangTidyPlistConverter
from converter.sanitizers.address.plist_converter import \
ASANPlistConverter
from converter.sanitizers.memory.plist_converter import \
MSANPlistConverter
from converter.sanitizers.thread.plist_converter import \
TSANPlistConverter
from converter.sanitizers.ub.plist_converter import \
UBSANPlistConverter
from codechecker_report_converter.clang_tidy.plist_converter import \
ClangTidyPlistConverter
from codechecker_report_converter.sanitizers.address.plist_converter import \
ASANPlistConverter
from codechecker_report_converter.sanitizers.memory.plist_converter import \
MSANPlistConverter
from codechecker_report_converter.sanitizers.thread.plist_converter import \
TSANPlistConverter
from codechecker_report_converter.sanitizers.ub.plist_converter import \
UBSANPlistConverter


LOG = logging.getLogger('ReportConverter')
Expand Down Expand Up @@ -135,7 +122,7 @@ def __add_arguments_to_parser(parser):


def main():
""" Warning to plist converter main command line. """
""" Report converter main command line. """
parser = argparse.ArgumentParser(
prog="report-converter",
description="Creates a CodeChecker report directory from the given "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def __str__(self):


class Message(Event):
""" Represents a message with an optional event and fixit messages. """
""" Represents a message with an optional event, fixit and note messages.
This will be a diagnostic section in the plist which represents a report.
"""

def __init__(self, path, line, column, message, checker, events=None,
notes=None, fixits=None):
Expand All @@ -66,7 +69,7 @@ def __str__(self):
[str(fixit) for fixit in self.fixits])


class OutputParser(object):
class BaseParser(object):
""" Warning message parser. """

__metaclass__ = ABCMeta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import re

from ...output_parser import get_next, Message, Event
from ..output_parser import SANOutputParser
from ..output_parser import SANParser

LOG = logging.getLogger('ReportConverter')


class ASANOutputParser(SANOutputParser):
class ASANParser(SANParser):
""" Parser for Clang AddressSanitizer console outputs. """

def __init__(self):
super(ASANOutputParser, self).__init__()
super(ASANParser, self).__init__()

# Regex for parsing AddressSanitizer output message.
self.address_line_re = re.compile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from __future__ import absolute_import

from ...plist_converter import PlistConverter
from .output_parser import ASANOutputParser
from .output_parser import ASANParser


class ASANPlistConverter(PlistConverter):
Expand All @@ -20,7 +20,7 @@ class ASANPlistConverter(PlistConverter):

def parse_messages(self, output):
""" Parse the given output. """
parser = ASANOutputParser()
parser = ASANParser()
return parser.parse_messages(output)

def _get_checker_category(self, checker):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import re

from ...output_parser import get_next, Message, Event
from ..output_parser import SANOutputParser
from ..output_parser import SANParser

LOG = logging.getLogger('ReportConverter')


class MSANOutputParser(SANOutputParser):
class MSANParser(SANParser):
""" Parser for Clang MemorySanitizer console outputs. """

def __init__(self):
super(MSANOutputParser, self).__init__()
super(MSANParser, self).__init__()

# Regex for parsing MemorySanitizer output message.
self.memory_line_re = re.compile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from __future__ import absolute_import

from ...plist_converter import PlistConverter
from .output_parser import MSANOutputParser
from .output_parser import MSANParser


class MSANPlistConverter(PlistConverter):
Expand All @@ -20,7 +20,7 @@ class MSANPlistConverter(PlistConverter):

def parse_messages(self, output):
""" Parse the given output. """
parser = MSANOutputParser()
parser = MSANParser()
return parser.parse_messages(output)

def _get_checker_category(self, checker):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
import os
import re

from ..output_parser import get_next, OutputParser, Event
from ..output_parser import get_next, BaseParser, Event

LOG = logging.getLogger('ReportConverter')


class SANOutputParser(OutputParser):
class SANParser(BaseParser):
""" Parser for Clang UndefinedBehaviourSanitizer console outputs.
Example output
/a/b/main.cpp:13:10: runtime error: load of value 7...
"""

def __init__(self):
super(SANOutputParser, self).__init__()
super(SANParser, self).__init__()

# Regex for parsing stack trace line.
# It has the following format:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import re

from ...output_parser import get_next, Message, Event
from ..output_parser import SANOutputParser
from ..output_parser import SANParser

LOG = logging.getLogger('ReportConverter')


class TSANOutputParser(SANOutputParser):
class TSANParser(SANParser):
""" Parser for Clang AddressSanitizer console outputs. """

def __init__(self):
super(TSANOutputParser, self).__init__()
super(TSANParser, self).__init__()

# Regex for parsing ThreadSanitizer output message.
self.tsan_line_re = re.compile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from __future__ import absolute_import

from ...plist_converter import PlistConverter
from .output_parser import TSANOutputParser
from .output_parser import TSANParser


class TSANPlistConverter(PlistConverter):
Expand All @@ -20,7 +20,7 @@ class TSANPlistConverter(PlistConverter):

def parse_messages(self, output):
""" Parse the given output. """
parser = TSANOutputParser()
parser = TSANParser()
return parser.parse_messages(output)

def _get_checker_category(self, checker):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
import re

from ...output_parser import get_next, Message, Event
from ..output_parser import SANOutputParser
from ..output_parser import SANParser

LOG = logging.getLogger('ReportConverter')


class UBSANOutputParser(SANOutputParser):
class UBSANParser(SANParser):
""" Parser for Clang UndefinedBehaviourSanitizer console outputs.
Example output
/a/b/main.cpp:13:10: runtime error: load of value 7...
"""

def __init__(self):
super(UBSANOutputParser, self).__init__()
super(UBSANParser, self).__init__()

# Regex for parsing UndefinedBehaviorSanitizer output message.
self.ub_line_re = re.compile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from __future__ import absolute_import

from ...plist_converter import PlistConverter
from .output_parser import UBSANOutputParser
from .output_parser import UBSANParser


class UBSANPlistConverter(PlistConverter):
Expand All @@ -20,7 +20,7 @@ class UBSANPlistConverter(PlistConverter):

def parse_messages(self, output):
""" Parse the given output. """
parser = UBSANOutputParser()
parser = UBSANParser()
return parser.parse_messages(output)

def _get_checker_category(self, checker):
Expand Down

This file was deleted.

6 changes: 2 additions & 4 deletions tools/report-converter/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
"License :: OSI Approved :: University of Illinois/NCSA Open Source License",
"Operating System :: MacOS",
"Operating System :: POSIX",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 2.7"
],
entry_points={
'console_scripts': [
'report-converter = report_converter.ReportConverter:main'
'report-converter = codechecker_report_converter.cli:main'
]
},
)
4 changes: 2 additions & 2 deletions tools/report-converter/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test: pycodestyle pylint test_unit test_functional

test_in_env: pycodestyle_in_env pylint_in_env test_unit_in_env

PYCODESTYLE_TEST_CMD = pycodestyle report_converter tests
PYCODESTYLE_TEST_CMD = pycodestyle codechecker_report_converter tests

pycodestyle:
$(PYCODESTYLE_TEST_CMD)
Expand All @@ -18,7 +18,7 @@ pycodestyle_in_env: venv_dev
$(ACTIVATE_DEV_VENV) && $(PYCODESTYLE_TEST_CMD)

PYLINT_TEST_CMD = PYLINTRC=$(ROOT)/.pylintrc \
pylint ./report_converter ./tests/**
pylint ./codechecker_report_converter ./tests/**

pylint:
$(PYLINT_TEST_CMD)
Expand Down
18 changes: 4 additions & 14 deletions tools/report-converter/tests/functional/cmdline/test_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,12 @@
import unittest


def run_cmd(cmd, env=None):
print(cmd)
proc = subprocess.Popen(cmd,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

out, err = proc.communicate()
print(out)
return proc.returncode, out, err


class TestCmdline(unittest.TestCase):
""" Simple tests to check report-converter command line. """

def test_help(self):
""" Get help for report-converter tool. """
cmd_help = ['report-converter', '--help']
self.assertEqual(0, run_cmd(cmd_help)[0])
ret = subprocess.call(['report-converter', '--help'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.assertEqual(0, ret)
10 changes: 5 additions & 5 deletions tools/report-converter/tests/unit/test_asan_output_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
except ImportError:
from io import BytesIO as StringIO

from report_converter.converter.output_parser import Event, Message
from report_converter.converter.sanitizers.address.output_parser import \
ASANOutputParser
from report_converter.converter.sanitizers.address.plist_converter import \
from codechecker_report_converter.output_parser import Event, Message
from codechecker_report_converter.sanitizers.address.output_parser import \
ASANParser
from codechecker_report_converter.sanitizers.address.plist_converter import \
ASANPlistConverter

OLD_PWD = None
Expand Down Expand Up @@ -104,7 +104,7 @@ class ASANOutputParserTestCase(unittest.TestCase):

def setUp(self):
"""Setup the OutputParser."""
self.parser = ASANOutputParser()
self.parser = ASANParser()

def test_asan(self):
""" Test the generated Messages of msan.out. """
Expand Down
Loading

0 comments on commit b5dacdf

Please sign in to comment.