From 747c3369d91f41c1736c9ace4c018de5bd5e31b1 Mon Sep 17 00:00:00 2001 From: bruntib Date: Thu, 19 Aug 2021 14:18:33 +0200 Subject: [PATCH] [cmd] Support label listing in CodeChecker checkers --- .../analyzers/config_handler.py | 16 - analyzer/codechecker_analyzer/cmd/checkers.py | 681 ++++++++++++------ .../tests/functional/cmdline/test_cmdline.py | 7 +- codechecker_common/checker_labels.py | 9 +- docs/analyzer/user_guide.md | 67 +- 5 files changed, 539 insertions(+), 241 deletions(-) diff --git a/analyzer/codechecker_analyzer/analyzers/config_handler.py b/analyzer/codechecker_analyzer/analyzers/config_handler.py index 4218b159a7..8c9f90f99c 100644 --- a/analyzer/codechecker_analyzer/analyzers/config_handler.py +++ b/analyzer/codechecker_analyzer/analyzers/config_handler.py @@ -12,11 +12,9 @@ from abc import ABCMeta from enum import Enum -from operator import itemgetter import collections import platform import subprocess -import sys from codechecker_common.logger import get_logger @@ -157,20 +155,6 @@ def initialize_checkers(self, checker_labels = analyzer_context.checker_labels - if 'profile:list' in map(itemgetter(0), cmdline_enable): - LOG.error("'list' is a reserved profile keyword. ") - LOG.error("Please choose another profile name in " - "%s/config/descriptions.json and rebuild.", - analyzer_context.data_files_dir_path) - sys.exit(1) - - if 'guideline:list' in map(itemgetter(0), cmdline_enable): - LOG.error("'list' is a reserved guideline keyword. ") - LOG.error("Please choose another guideline name in " - "%s/config/descriptions.json and rebuild.", - analyzer_context.data_files_dir_path) - sys.exit(1) - # Add all checkers marked as default. This means the analyzer should # manage whether it is enabled or disabled. for checker_name, description in checkers: diff --git a/analyzer/codechecker_analyzer/cmd/checkers.py b/analyzer/codechecker_analyzer/cmd/checkers.py index ac6079c8a1..e1629ce9de 100644 --- a/analyzer/codechecker_analyzer/cmd/checkers.py +++ b/analyzer/codechecker_analyzer/cmd/checkers.py @@ -11,17 +11,21 @@ import argparse +import json import os import subprocess import sys from collections import defaultdict +from typing import Dict, Iterable, Tuple from codechecker_analyzer import analyzer_context from codechecker_analyzer.analyzers import analyzer_types from codechecker_analyzer.analyzers.clangsa.analyzer import ClangSA +from codechecker_analyzer.analyzers.clangtidy.analyzer import ClangTidy from codechecker_common import arg, logger from codechecker_common.output import USER_FORMATS, twodim +from codechecker_common.checker_labels import CheckerLabels from codechecker_analyzer import env from codechecker_analyzer.analyzers.config_handler import CheckerState @@ -95,6 +99,33 @@ def get_argparser_ctor_args(): 'epilog': """ The list of checkers that are enabled or disabled by default can be edited by editing "profile:default" labels in the directory '{}'. + +Example scenario: List checkers by labels +----------------------------------------- +List checkers in "sensitive" profile: + CodeChecker checkers --label profile:sensitive + CodeChecker checkers --profile sensitive + +List checkers in "HIGH" severity: + CodeChecker checkers --label severity:HIGH + CodeChecker checkers --severity HIGH + +List checkers covering str34-c SEI-CERT rule: + CodeChecker checkers --label sei-cert:str-34-c + CodeChecker checkers --guideline sei-cert:str34-c + +List checkers covering all SEI-CERT rules: + CodeChecker checkers --label guideline:sei-cert + CodeChecker checkers --guideline sei-cert + +List available profiles, guidelines and severities: + CodeChecker checkers --profile + CodeChecker checkers --guideline + CodeChecker checkers --severity + +List labels and their available values: + CodeChecker checkers --label + CodeChecker checkers --label severity """.format(os.path.join(labels_dir_path)), # Help is shown when the "parent" CodeChecker command lists the @@ -133,33 +164,50 @@ def add_arguments_to_parser(parser): action='store_true', required=False, help="Show details about the checker, such as " - "description, if available.") + "status, checker name, analyzer name, severity, " + "guidelines and description. Status shows if the " + "checker is enabled besides the given labels. " + "If the labels don't trigger a checker then the " + "status is determined by the analyzer tool.") parser.add_argument('--label', - nargs='+', + nargs='?', required=False, default=argparse.SUPPRESS, - help="") + help="Filter checkers that are attached the given " + "label. The format of a label is " + "