Skip to content

Commit

Permalink
[tools] Warning to plist converter
Browse files Browse the repository at this point in the history
Create a new tool which can be used to convert `clang-tidy`
and `clang sanitizer` output messages to `.plist` files.
  • Loading branch information
csordasmarton committed Jan 15, 2020
1 parent a6e27ca commit e05c885
Show file tree
Hide file tree
Showing 18 changed files with 898 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ clean_venv_dev:

clean: clean_package clean_vendor

clean_package: clean_plist_to_html clean_tu_collector
clean_package: clean_plist_to_html clean_tu_collector clean_warning_to_plist
rm -rf $(BUILD_DIR)
find . -name "*.pyc" -delete

Expand All @@ -150,6 +150,9 @@ clean_plist_to_html:
clean_tu_collector:
$(MAKE) -C $(CC_TOOLS)/tu_collector clean

clean_warning_to_plist:
$(MAKE) -C $(CC_TOOLS)/warning-to-plist clean

clean_travis:
# Clean CodeChecker config files stored in the users home directory.
rm -rf ~/.codechecker*
Expand Down
2 changes: 2 additions & 0 deletions tools/warning-to-plist/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
warning_to_plist.egg-info
13 changes: 13 additions & 0 deletions tools/warning-to-plist/.noserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[nosetests]

# increase verbosity level
verbosity=3

# more detailed error messages on failed asserts
detailed-errors=1

# stop running tests on first error
stop=1

# do not capture stdout
#nocapture=1
10 changes: 10 additions & 0 deletions tools/warning-to-plist/.pypirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[distutils]
index-servers =
pypi
testpypi

[pypi]
repository: https://upload.pypi.org/legacy/

[testpypi]
repository: https://test.pypi.org/legacy/
39 changes: 39 additions & 0 deletions tools/warning-to-plist/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
University of Illinois/NCSA Open Source License

Copyright (c) 2015 Ericsson.
All rights reserved.

Developed by:

CodeChecker Team

Ericsson

http://www.ericsson.com

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal with
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimers.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimers in the
documentation and/or other materials provided with the distribution.

* Neither the names of the CodeChecker Team, Ericsson, nor the names of
its contributors may be used to endorse or promote products derived
from this Software without specific prior written permission.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
SOFTWARE.

61 changes: 61 additions & 0 deletions tools/warning-to-plist/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -------------------------------------------------------------------------
# The CodeChecker Infrastructure
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
# -------------------------------------------------------------------------
CURRENT_DIR = $(shell pwd)
ROOT = $(CURRENT_DIR)

BUILD_DIR = $(CURRENT_DIR)/build
WARNING_TO_PLIST_DIR = $(BUILD_DIR)/warning_to_plist

ACTIVATE_DEV_VENV ?= . venv_dev/bin/activate
ACTIVATE_RUNTIME_VENV ?= . venv/bin/activate

VENV_DEV_REQ_FILE ?= requirements_py/dev/requirements.txt

default: all

all: package

venv:
# Create a virtual environment which can be used to run the build package.
virtualenv -p python2 venv && $(ACTIVATE_RUNTIME_VENV)

pip_dev_deps:
pip install -r $(VENV_DEV_REQ_FILE)

venv_dev:
# Create a virtual environment for development.
virtualenv -p python2 venv_dev && \
$(ACTIVATE_DEV_VENV) && pip install -r $(VENV_DEV_REQ_FILE)

clean_venv_dev:
rm -rf venv_dev

package:
# Install package in 'development mode'.
python setup.py develop

build:
python setup.py build --build-purelib $(WARNING_TO_PLIST_DIR)

dist:
# Create a source distribution.
python setup.py sdist

upload_test:
# Upload package to the TestPyPI repository.
$(eval PKG_NAME := $(shell python setup.py --name))
$(eval PKG_VERSION := $(shell python setup.py --version))
twine upload -r testpypi dist/$(PKG_NAME)-$(PKG_VERSION).tar.gz

upload:
# Upload package to the PyPI repository.
$(eval PKG_NAME := $(shell python setup.py --name))
$(eval PKG_VERSION := $(shell python setup.py --version))
twine upload -r pypi dist/$(PKG_NAME)-$(PKG_VERSION).tar.gz

clean:
rm -rf $(BUILD_DIR)
rm -rf warning_to_plist.egg-info
42 changes: 42 additions & 0 deletions tools/warning-to-plist/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# warning-to-plist
`warning-to-plist` is a Python tool which can be used to create a CodeChecker
report directory from the given code analyzer output which can be stored to
a CodeChecker server.

## Install guide
```sh
# Create a Python virtualenv and set it as your environment.
make venv
source $PWD/venv/bin/activate

# Build and install warning-to-plist package.
make package
```

## Usage
```sh
usage: warn-to-plist [-h] -o OUTPUT_DIR -t TYPE [-v] [file]

Creates a CodeChecker report directory from the given code analyzer output
which can be stored to a CodeChecker web server.

positional arguments:
file Code analyzer output result file which will be parsed
and used to generate a CodeChecker report directory.
If this parameter is not given the standard input will
be used.

optional arguments:
-h, --help show this help message and exit
-o OUTPUT_DIR, --output OUTPUT_DIR
This directory will be used to generate CodeChecker
report directory files.
-t TYPE, --type TYPE Specify the format of the code analyzer output.
Currently supported output types are: clang-tidy.
-v, --verbose Set verbosity level. (default: False)
```

## License

The project is licensed under University of Illinois/NCSA Open Source License.
See LICENSE.TXT for details.
3 changes: 3 additions & 0 deletions tools/warning-to-plist/requirements_py/dev/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nose==1.3.7
pycodestyle==2.4.0
pylint==1.9.4
37 changes: 37 additions & 0 deletions tools/warning-to-plist/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import setuptools

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name="warning-to-plist",
version="0.1.0",
author='CodeChecker Team (Ericsson)',
description="Parse and create HTML files from one or more '.plist' "
"result files.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/Ericsson/CodeChecker",
keywords=['warn-to-plist', 'plist-converter', 'plist'],
license='LICENSE.txt',
packages=setuptools.find_packages(),
include_package_data=True,
classifiers=[
"Environment :: Console",
"Intended Audience :: Developers",
"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",
],
entry_points={
'console_scripts': [
'warning-to-plist = warning_to_plist.WarningToPlist:main'
]
},
)
123 changes: 123 additions & 0 deletions tools/warning-to-plist/warning_to_plist/WarningToPlist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env python
# -------------------------------------------------------------------------
# The CodeChecker Infrastructure
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
# -------------------------------------------------------------------------

from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import argparse
import logging
import os
import sys

from .converter.clang_tidy.plist_converter import ClangTidyPlistConverter

LOG = logging.getLogger('WarningToPlist')

msg_formatter = logging.Formatter('[%(levelname)s] - %(message)s')
log_handler = logging.StreamHandler()
log_handler.setFormatter(msg_formatter)
LOG.setLevel(logging.INFO)
LOG.addHandler(log_handler)


supported_converters = {
ClangTidyPlistConverter.TOOL_NAME: ClangTidyPlistConverter}


def output_to_plist(output, parser_type, output_dir):
""" Creates .plist files from the given output to the given output dir. """
plist_converter = supported_converters[parser_type]()
messages = plist_converter.parse_messages(output)

if not messages:
LOG.info("No '%s' results can be found in the given code analyzer "
"output.", parser_type)
sys.exit(0)

converters = {}
for m in messages:
if m.path not in converters:
converters[m.path] = supported_converters[parser_type]()
converters[m.path].add_messages([m])

if not os.path.exists(output_dir):
os.makedirs(output_dir)

for c in converters:
file_name = os.path.basename(c)
out_file_name = '{0}_{1}.plist'.format(file_name, parser_type)
out_file = os.path.join(output_dir, out_file_name)

LOG.info("Creating plist file: '%s'.", out_file)
LOG.debug(converters[c].plist)

converters[c].write_to_file(out_file)


def __add_arguments_to_parser(parser):
""" Add arguments to the the given parser. """
parser.add_argument('input',
type=str,
metavar='file',
nargs='?',
default=argparse.SUPPRESS,
help="Code analyzer output result file which will be "
"parsed and used to generate a CodeChecker "
"report directory. If this parameter is not "
"given the standard input will be used.")

parser.add_argument('-o', '--output',
dest="output_dir",
required=True,
default=argparse.SUPPRESS,
help="This directory will be used to generate "
"CodeChecker report directory files.")

parser.add_argument('-t', '--type',
dest='type',
metavar='TYPE',
required=True,
choices=supported_converters,
default=argparse.SUPPRESS,
help="Specify the format of the code analyzer output. "
"Currently supported output types are: " +
', '.join(supported_converters) + ".")

parser.add_argument('-v', '--verbose',
action='store_true',
dest='verbose',
help="Set verbosity level.")


def main():
""" Warning to plist converter main command line. """
parser = argparse.ArgumentParser(
prog="warn-to-plist",
description="Creates a CodeChecker report directory from the given "
"code analyzer output which can be stored to a "
"CodeChecker web server.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
__add_arguments_to_parser(parser)

args = parser.parse_args()

if 'verbose' in args and args.verbose:
LOG.setLevel(logging.DEBUG)

if 'input' in args and args.input:
with open(args.input) as input_file:
output = input_file.readlines()
else:
output = sys.stdin.readlines()

output_to_plist(output, args.type, args.output_dir)


if __name__ == "__main__":
main()
5 changes: 5 additions & 0 deletions tools/warning-to-plist/warning_to_plist/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -------------------------------------------------------------------------
# The CodeChecker Infrastructure
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
# -------------------------------------------------------------------------
5 changes: 5 additions & 0 deletions tools/warning-to-plist/warning_to_plist/converter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -------------------------------------------------------------------------
# The CodeChecker Infrastructure
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
# -------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -------------------------------------------------------------------------
# The CodeChecker Infrastructure
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
# -------------------------------------------------------------------------
Loading

0 comments on commit e05c885

Please sign in to comment.