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

feat(script): Automatically generate doc_url and severity from ToCs, documentations, and analyser outputs #4225

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
28 changes: 28 additions & 0 deletions scripts/labels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,31 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------
"""
This library ships reusable components and user-facing tools to verify,
generate, and adapt the checker labels in the CodeChecker configuration
structure.
"""
# Load the interpreter injection first.
from . import codechecker

from . import \
checker_labels, \
exception, \
http_, \
output, \
projects, \
transformer, \
util


__all__ = [
"checker_labels",
"codechecker",
"exception",
"http_",
"output",
"projects",
"transformer",
"util",
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@


try:
from .doc_url.generate_tool import __main__ as doc_url_generate
from .doc_url.verify_tool import __main__ as doc_url_verify
from .severity.generate_tool import __main__ as severity_generate
except ModuleNotFoundError as e:
import traceback
traceback.print_exc()
Expand Down Expand Up @@ -41,18 +43,20 @@ def args() -> argparse.ArgumentParser:
dest="subcommand",
required=True)

def add_subparser(command: str, package):
def add_subparser(package):
subparser = subparsers.add_parser(
command,
list(globals().keys())[list(globals().values()).index(package)],
prog=package.__package__,
help=package.short_help,
description=package.description,
epilog=package.epilogue,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
subparser = package.args(subparser)
subparser = package.arg_parser(subparser)
subparser.set_defaults(__main=package.main)

add_subparser("doc_url_verify", doc_url_verify)
add_subparser(doc_url_generate)
add_subparser(doc_url_verify)
add_subparser(severity_generate)

return parser

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _load_json(path: pathlib.Path) -> Dict:
def _save_json(path: pathlib.Path, data: Dict):
try:
with path.open("w") as file:
json.dump(data, file, indent=2)
json.dump(data, file, indent=2, sort_keys=True)
file.write('\n')
except OSError:
import traceback
Expand Down Expand Up @@ -128,7 +128,14 @@ def update_checker_labels(analyser: str,
label_indices = {checker: indices[0] if len(indices) == 1 else None
for checker, indices in label_indices.items()}
for checker, new_label in updates.items():
checker_labels = label_cfg[checker]
try:
checker_labels = label_cfg[checker]
except KeyError:
label_cfg[checker] = []
label_indices[checker] = None

checker_labels = label_cfg[checker]

idx = label_indices[checker]
e = f"{key}:{new_label}"
if idx is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,28 @@ def codechecker_src_root() -> Optional[pathlib.Path]:
"""
try:
this_file = pathlib.Path(__file__).resolve(strict=True)
labels_idx = find_if(this_file.parents,
lambda p: p.stem == "labels")
if not labels_idx:
scripts_idx = find_if(this_file.parents,
lambda p: p.stem == "scripts")
if not scripts_idx:
return None

if this_file.parents[labels_idx + 1].stem == "scripts":
return this_file.parents[labels_idx + 2]

return None
return this_file.parents[scripts_idx + 1]
except Exception:
import traceback
traceback.print_exc()

return None


def default_checker_label_dir() -> Optional[pathlib.Path]:
"""
Returns the directory where the configuration labels for checkers are
stored.
"""
codechecker_root = codechecker_src_root()
return codechecker_root / "config" / "labels" / "analyzers" \
if codechecker_root else None


def inject_codechecker_to_interpreter():
"""
Adds the built CodeChecker package relative to the root of the working
Expand Down
71 changes: 0 additions & 71 deletions scripts/labels/compiler_warnings.py

This file was deleted.

60 changes: 0 additions & 60 deletions scripts/labels/cppcheck.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
configuration.
"""
from . import \
generators, \
output, \
verifiers


__all__ = [
"generators",
"output",
"verifiers",
]
17 changes: 17 additions & 0 deletions scripts/labels/doc_url/generate_tool/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Part of the CodeChecker project, under the Apache License v2.0 with
# LLVM Exceptions. See LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------
"""
This subpackage implements logic that is primarily user-facing, as opposed to
reusable library-like components.
"""
from . import \
tool


__all__ = [
"tool",
]
Loading
Loading