Exemple #1
0
def add_arguments_to_parser(parser):
    """
    Add the subcommand's arguments to the given argparse.ArgumentParser.
    """

    parser.add_argument('logfile',
                        type=str,
                        help="Path to the JSON compilation command database "
                        "files which were created during the build. "
                        "The analyzers will check only the files "
                        "registered in these build databases.")

    parser.add_argument('-j',
                        '--jobs',
                        type=int,
                        dest="jobs",
                        required=False,
                        default=1,
                        help="Number of threads to use in analysis. More "
                        "threads mean faster analysis at the cost of "
                        "using more memory.")

    skip_mode = parser.add_mutually_exclusive_group()
    skip_mode.add_argument('-i',
                           '--ignore',
                           '--skip',
                           dest="skipfile",
                           required=False,
                           default=argparse.SUPPRESS,
                           help="Path to the Skipfile dictating which project "
                           "files should be omitted from analysis. "
                           "Please consult the User guide on how a "
                           "Skipfile should be laid out.")

    skip_mode.add_argument('--file',
                           nargs='+',
                           dest="files",
                           metavar='FILE',
                           required=False,
                           default=argparse.SUPPRESS,
                           help="Analyze only the given file(s) not the whole "
                           "compilation database. Absolute directory "
                           "paths should start with '/', relative "
                           "directory paths should start with '*' and "
                           "it can contain path glob pattern. "
                           "Example: '/path/to/main.cpp', 'lib/*.cpp', "
                           "*/test*'.")

    parser.add_argument('-o',
                        '--output',
                        dest="output_path",
                        required=True,
                        default=argparse.SUPPRESS,
                        help="Store the analysis output in the given folder.")

    parser.add_argument('--compiler-info-file',
                        dest="compiler_info_file",
                        required=False,
                        default=argparse.SUPPRESS,
                        help="Read the compiler includes and target from the "
                        "specified file rather than invoke the compiler "
                        "executable.")

    parser.add_argument('--keep-gcc-include-fixed',
                        dest="keep_gcc_include_fixed",
                        required=False,
                        action='store_true',
                        default=False,
                        help="There are some implicit include paths which are "
                        "only used by GCC (include-fixed). This flag "
                        "determines whether these should be kept among "
                        "the implicit include paths.")

    parser.add_argument('--keep-gcc-intrin',
                        dest="keep_gcc_intrin",
                        required=False,
                        action='store_true',
                        default=False,
                        help="There are some implicit include paths which "
                        "contain GCC-specific header files (those "
                        "which end with intrin.h). This flag determines "
                        "whether these should be kept among the implicit "
                        "include paths. Use this flag if Clang analysis "
                        "fails with error message related to __builtin "
                        "symbols.")

    parser.add_argument('-t',
                        '--type',
                        '--output-format',
                        dest="output_format",
                        required=False,
                        choices=['plist'],
                        default='plist',
                        help="Specify the format the analysis results should "
                        "use.")

    parser.add_argument('-q',
                        '--quiet',
                        dest="quiet",
                        action='store_true',
                        default=argparse.SUPPRESS,
                        required=False,
                        help="Do not print the output or error of the "
                        "analyzers to the standard output of "
                        "CodeChecker.")

    parser.add_argument('-c',
                        '--clean',
                        dest="clean",
                        required=False,
                        action='store_true',
                        default=argparse.SUPPRESS,
                        help="Delete analysis reports stored in the output "
                        "directory. (By default, CodeChecker would keep "
                        "reports and overwrites only those files that "
                        "were update by the current build command).")

    parser.add_argument('--compile-uniqueing',
                        type=str,
                        dest="compile_uniqueing",
                        default="none",
                        required=False,
                        help="Specify the method the compilation "
                        "actions in the  compilation database are "
                        "uniqued before analysis. "
                        "CTU analysis works properly only if "
                        "there is exactly one "
                        "compilation action per source file. "
                        "none(default in non CTU mode): "
                        "no uniqueing is done. "
                        "strict: no uniqueing is done, "
                        "and an error is given if "
                        "there is more than one compilation "
                        "action for a source file. "
                        "alpha(default in CTU mode): If there is more "
                        "than one compilation action for a source "
                        "file, only the one is kept that belongs to the "
                        "alphabetically first "
                        "compilation target. "
                        "If none of the above given, "
                        "this parameter should "
                        "be a python regular expression."
                        "If there is more than one compilation action "
                        "for a source, "
                        "only the one is kept which matches the "
                        "given python regex. If more than one "
                        "matches an error is given. "
                        "The whole compilation "
                        "action text is searched for match.")

    parser.add_argument('--report-hash',
                        dest="report_hash",
                        default=argparse.SUPPRESS,
                        required=False,
                        choices=['context-free', 'context-free-v2'],
                        help="R|Specify the hash calculation method for "
                        "reports. By default the calculation method for "
                        "Clang Static Analyzer is context sensitive and "
                        "for Clang Tidy it is context insensitive.\n"
                        "You can use the following calculation methods:\n"
                        "- context-free: there was a bug and for Clang "
                        "Tidy not the context free hash was generated "
                        "(kept for backward compatibility).\n"
                        "- context-free-v2: context free hash is used "
                        "for ClangSA and Clang Tidy.\n"
                        "See the 'issue hashes' section of the help "
                        "message of this command below for more "
                        "information.\n"
                        "USE WISELY AND AT YOUR OWN RISK!")

    parser.add_argument('-n',
                        '--name',
                        dest="name",
                        required=False,
                        default=argparse.SUPPRESS,
                        help="Annotate the run analysis with a custom name in "
                        "the created metadata file.")

    analyzer_opts = parser.add_argument_group("analyzer arguments")

    analyzer_opts.add_argument(
        '--analyzers',
        nargs='+',
        dest='analyzers',
        metavar='ANALYZER',
        required=False,
        choices=analyzer_types.supported_analyzers,
        default=argparse.SUPPRESS,
        help="Run analysis only with the analyzers "
        "specified. Currently supported analyzers "
        "are: " + ', '.join(analyzer_types.supported_analyzers) + ".")

    analyzer_opts.add_argument('--capture-analysis-output',
                               dest='capture_analysis_output',
                               action='store_true',
                               default=argparse.SUPPRESS,
                               required=False,
                               help="Store standard output and standard error "
                               "of successful analyzer invocations "
                               "into the '<OUTPUT_DIR>/success' "
                               "directory.")

    analyzer_opts.add_argument('--config',
                               dest='config_file',
                               required=False,
                               help="Allow the configuration from an explicit "
                               "JSON based configuration file. The "
                               "value of the 'analyzer' key in the "
                               "config file will be emplaced as command "
                               "line arguments. The format of "
                               "configuration file is: "
                               "{"
                               "  \"analyzer\": ["
                               "    \"--enable=core.DivideZero\","
                               "    \"--enable=core.CallAndMessage\","
                               "    \"--clean\""
                               "  ]"
                               "}.")

    analyzer_opts.add_argument('--saargs',
                               dest="clangsa_args_cfg_file",
                               required=False,
                               default=argparse.SUPPRESS,
                               help="File containing argument which will be "
                               "forwarded verbatim for the Clang Static "
                               "Analyzer.")

    analyzer_opts.add_argument('--tidyargs',
                               dest="tidy_args_cfg_file",
                               required=False,
                               default=argparse.SUPPRESS,
                               help="File containing argument which will be "
                               "forwarded verbatim for Clang-Tidy.")

    analyzer_opts.add_argument('--tidy-config',
                               dest='tidy_config',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="A file in YAML format containing the "
                               "configuration of clang-tidy checkers. "
                               "The file can be dumped by "
                               "'CodeChecker analyzers --dump-config "
                               "clang-tidy' command.")

    analyzer_opts.add_argument('--analyzer-config',
                               dest='analyzer_config',
                               nargs='*',
                               default=["clang-tidy:HeaderFilterRegex=.*"],
                               help="Analyzer configuration options in the "
                               "following format: analyzer:key=value. "
                               "The collection of the options can be "
                               "printed with "
                               "'CodeChecker analyzers "
                               "--analyzer-config'. To disable the "
                               "default behaviour of this option you can "
                               "use the "
                               "'clang-tidy:take-config-from-directory="
                               "true' option.")

    analyzer_opts.add_argument('--checker-config',
                               dest='checker_config',
                               nargs='*',
                               default=argparse.SUPPRESS,
                               help="Checker configuration options in the "
                               "following format: analyzer:key=value. "
                               "The collection of the options can be "
                               "printed with "
                               "'CodeChecker checkers --checker-config'.")

    analyzer_opts.add_argument('--timeout',
                               type=int,
                               dest='timeout',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="The amount of time (in seconds) that "
                               "each analyzer can spend, individually, "
                               "to analyze the project. If the analysis "
                               "of a particular file takes longer than "
                               "this time, the analyzer is killed and "
                               "the analysis is considered as a failed "
                               "one.")

    context = analyzer_context.get_context()
    clang_has_z3 = analyzer_types.is_z3_capable(context)

    if clang_has_z3:
        analyzer_opts.add_argument('--z3',
                                   dest='enable_z3',
                                   choices=['on', 'off'],
                                   default='off',
                                   help="Enable the z3 solver backend. This "
                                   "allows reasoning over more complex "
                                   "queries, but performance is worse "
                                   "than the default range-based "
                                   "constraint solver.")

    clang_has_z3_refutation = analyzer_types.is_z3_refutation_capable(context)

    if clang_has_z3_refutation:
        analyzer_opts.add_argument(
            '--z3-refutation',
            dest='enable_z3_refutation',
            choices=['on', 'off'],
            default='on' if clang_has_z3_refutation else 'off',
            help="Switch on/off the Z3 SMT Solver "
            "backend to "
            "reduce false positives. The results "
            "of the ranged based constraint "
            "solver in the Clang Static Analyzer "
            "will be cross checked with the Z3 "
            "SMT solver. This should not cause "
            "that much of a slowdown compared to "
            "using the Z3 solver only.")

    if analyzer_types.is_ctu_capable(context):
        ctu_opts = parser.add_argument_group(
            "cross translation unit analysis arguments", """
These arguments are only available if the Clang Static Analyzer supports
Cross-TU analysis. By default, no CTU analysis is run when
'CodeChecker analyze' is called.""")

        ctu_modes = ctu_opts.add_mutually_exclusive_group()
        ctu_modes.add_argument('--ctu',
                               '--ctu-all',
                               action='store_const',
                               const=[True, True],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform Cross Translation Unit (CTU) "
                               "analysis, both 'collect' and 'analyze' "
                               "phases. In this mode, the extra files "
                               "created by 'collect' are cleaned up "
                               "after the analysis.")

        ctu_modes.add_argument('--ctu-collect',
                               action='store_const',
                               const=[True, False],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform the first, 'collect' phase of "
                               "Cross-TU analysis. This phase generates "
                               "extra files needed by CTU analysis, and "
                               "puts them into '<OUTPUT_DIR>/ctu-dir'. "
                               "NOTE: If this argument is present, "
                               "CodeChecker will NOT execute the "
                               "analyzers!")

        ctu_modes.add_argument('--ctu-analyze',
                               action='store_const',
                               const=[False, True],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform the second, 'analyze' phase of "
                               "Cross-TU analysis, using already "
                               "available extra files in "
                               "'<OUTPUT_DIR>/ctu-dir'. (These files "
                               "will not be cleaned up in this mode.)")

        ctu_opts.add_argument('--ctu-reanalyze-on-failure',
                              action='store_true',
                              dest='ctu_reanalyze_on_failure',
                              default=argparse.SUPPRESS,
                              help="If Cross-TU analysis is enabled and fails "
                              "for some reason, try to re analyze the "
                              "same translation unit without "
                              "Cross-TU enabled.")

    if analyzer_types.is_statistics_capable(context):
        stat_opts = parser.add_argument_group(
            "Statistics analysis feature arguments", """
These arguments are only available if the Clang Static Analyzer supports
Statistics-based analysis (e.g. statisticsCollector.ReturnValueCheck,
statisticsCollector.SpecialReturnValue checkers are available).""")

        stat_opts.add_argument('--stats-collect',
                               '--stats-collect',
                               action='store',
                               default=argparse.SUPPRESS,
                               dest='stats_output',
                               help="Perform the first, 'collect' phase of "
                               "Statistical analysis. This phase "
                               "generates extra files needed by "
                               "statistics analysis, and "
                               "puts them into "
                               "'<STATS_OUTPUT>'."
                               " NOTE: If this argument is present, "
                               "CodeChecker will NOT execute the "
                               "analyzers!")

        stat_opts.add_argument('--stats-use',
                               '--stats-use',
                               action='store',
                               default=argparse.SUPPRESS,
                               dest='stats_dir',
                               help="Use the previously generated statistics "
                               "results for the analysis from the given "
                               "'<STATS_DIR>'.")

        stat_opts.add_argument('--stats',
                               action='store_true',
                               default=argparse.SUPPRESS,
                               dest='stats_enabled',
                               help="Perform both phases of "
                               "Statistical analysis. This phase "
                               "generates extra files needed by "
                               "statistics analysis and enables "
                               "the statistical checkers. "
                               "No need to enable them explicitly.")

        stat_opts.add_argument('--stats-min-sample-count',
                               action='store',
                               default="10",
                               type=int,
                               dest='stats_min_sample_count',
                               help="Minimum number of samples (function call"
                               " occurrences) to be collected"
                               " for a statistics to be relevant "
                               "'<MIN-SAMPLE-COUNT>'.")

        stat_opts.add_argument('--stats-relevance-threshold',
                               action='store',
                               default="0.85",
                               type=float,
                               dest='stats_relevance_threshold',
                               help="The minimum ratio of calls of function "
                               "f that must have a certain property "
                               "property to consider it true for that "
                               "function (calculated as calls "
                               "with a property/all calls)."
                               " CodeChecker will warn for"
                               " calls of f do not have that property."
                               "'<RELEVANCE_THRESHOLD>'.")

    checkers_opts = parser.add_argument_group(
        "checker configuration", """
Checkers
------------------------------------------------
The analyzer performs checks that are categorized into families or "checkers".
See 'CodeChecker checkers' for the list of available checkers. You can
fine-tune which checkers to use in the analysis by setting the enabled and
disabled flags starting from the bigger groups and going inwards, e.g.
'-e core -d core.uninitialized -e core.uninitialized.Assign' will enable every
'core' checker, but only 'core.uninitialized.Assign' from the
'core.uninitialized' group. Please consult the manual for details. Disabling
certain checkers - such as the 'core' group - is unsupported by the LLVM/Clang
community, and thus discouraged.

Compiler warnings and errors
------------------------------------------------
Compiler warnings are diagnostic messages that report constructions that are
not inherently erroneous but that are risky or suggest there may have been an
error. Compiler warnings are named 'clang-diagnostic-<warning-option>', e.g.
Clang warning controlled by '-Wliteral-conversion' will be reported with check
name 'clang-diagnostic-literal-conversion'. You can fine-tune which warnings to
use in the analysis by setting the enabled and disabled flags starting from the
bigger groups and going inwards, e.g. '-e Wunused -d Wno-unused-parameter' will
enable every 'unused' warnings except 'unused-parameter'. These flags should
start with a capital 'W' or 'Wno-' prefix followed by the waning name (E.g.:
'-e Wliteral-conversion', '-d Wno-literal-conversion'). By default '-Wall' and
'-Wextra' warnings are enabled. For more information see:
https://clang.llvm.org/docs/DiagnosticsReference.html.
Sometimes GCC is more permissive than Clang, so it is possible that a specific
construction doesn't compile with Clang but compiles with GCC. These
compiler errors are also collected as CodeChecker reports as
'clang-diagnostic-error'.
Note that compiler errors and warnings are captured by CodeChecker only if it
was emitted by clang-tidy.""")

    checkers_opts.add_argument('-e',
                               '--enable',
                               dest="enable",
                               metavar='checker/group/profile',
                               default=argparse.SUPPRESS,
                               action=OrderedCheckersAction,
                               help="Set a checker (or checker group) "
                               "to BE USED in the analysis.")

    checkers_opts.add_argument('-d',
                               '--disable',
                               dest="disable",
                               metavar='checker/group/profile',
                               default=argparse.SUPPRESS,
                               action=OrderedCheckersAction,
                               help="Set a checker (or checker group) "
                               "to BE PROHIBITED from use in the "
                               "analysis.")

    checkers_opts.add_argument('--enable-all',
                               dest="enable_all",
                               action='store_true',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="Force the running analyzers to use "
                               "almost every checker available. The "
                               "checker groups 'alpha.', 'debug.' and "
                               "'osx.' (on Linux) are NOT enabled "
                               "automatically and must be EXPLICITLY "
                               "specified. WARNING! Enabling all "
                               "checkers might result in the analysis "
                               "losing precision and stability, and "
                               "could even result in a total failure of "
                               "the analysis. USE WISELY AND AT YOUR "
                               "OWN RISK!")

    logger.add_verbose_arguments(parser)
    parser.set_defaults(func=main,
                        func_process_config_file=process_config_file)
Exemple #2
0
def add_arguments_to_parser(parser):
    """
    Add the subcommand's arguments to the given argparse.ArgumentParser.
    """

    parser.add_argument('-o',
                        '--output',
                        type=str,
                        dest="output_dir",
                        required=False,
                        default=argparse.SUPPRESS,
                        help="Store the analysis output in the given folder. "
                        "If it is not given then the results go into a "
                        "temporary directory which will be removed after "
                        "the analysis.")

    parser.add_argument('-t',
                        '--type',
                        '--output-format',
                        dest="output_format",
                        required=False,
                        choices=['plist'],
                        default='plist',
                        help="Specify the format the analysis results "
                        "should use.")

    parser.add_argument('-q',
                        '--quiet',
                        dest="quiet",
                        action='store_true',
                        required=False,
                        default=argparse.SUPPRESS,
                        help="If specified, the build tool's and the "
                        "analyzers' output will not be printed to the "
                        "standard output.")

    parser.add_argument('--keep-gcc-include-fixed',
                        dest="keep_gcc_include_fixed",
                        required=False,
                        action='store_true',
                        default=False,
                        help="There are some implicit include paths which are "
                        "only used by GCC (include-fixed). This flag "
                        "determines whether these should be kept among "
                        "the implicit include paths.")

    parser.add_argument('--keep-gcc-intrin',
                        dest="keep_gcc_intrin",
                        required=False,
                        action='store_true',
                        default=False,
                        help="There are some implicit include paths which "
                        "contain GCC-specific header files (those "
                        "which end with intrin.h). This flag determines "
                        "whether these should be kept among the implicit "
                        "include paths. Use this flag if Clang analysis "
                        "fails with error message related to __builtin "
                        "symbols.")

    log_args = parser.add_argument_group(
        "log arguments", """
Specify how the build information database should be obtained. You need to
specify either an already existing log file, or a build command which will be
used to generate a log file on the fly.""")

    log_args = log_args.add_mutually_exclusive_group(required=True)

    log_args.add_argument('-b',
                          '--build',
                          type=str,
                          dest="command",
                          default=argparse.SUPPRESS,
                          help="Execute and record a build command. Build "
                          "commands can be simple calls to 'g++' or "
                          "'clang++' or 'make', but a more complex "
                          "command, or the call of a custom script file "
                          "is also supported.")

    log_args.add_argument('-l',
                          '--logfile',
                          type=str,
                          dest="logfile",
                          default=argparse.SUPPRESS,
                          help="Use an already existing JSON compilation "
                          "command database file specified at this path.")

    analyzer_opts = parser.add_argument_group("analyzer arguments")
    analyzer_opts.add_argument('-j',
                               '--jobs',
                               type=int,
                               dest="jobs",
                               required=False,
                               default=1,
                               help="Number of threads to use in analysis. "
                               "More threads mean faster analysis at "
                               "the cost of using more memory.")

    analyzer_opts.add_argument('-c',
                               '--clean',
                               dest="clean",
                               required=False,
                               action='store_true',
                               default=argparse.SUPPRESS,
                               help="Delete analysis reports stored in the "
                               "output directory. (By default, "
                               "CodeChecker would keep reports and "
                               "overwrites only those files that were "
                               "update by the current build command).")

    parser.add_argument('--compile-uniqueing',
                        type=str,
                        dest="compile_uniqueing",
                        default="none",
                        required=False,
                        help="Specify the method the compilation "
                        "actions in the  compilation database are "
                        "uniqued before analysis. "
                        "CTU analysis works properly only if "
                        "there is exactly one "
                        "compilation action per source file. "
                        "none(default in non CTU mode): "
                        "no uniqueing is done. "
                        "strict: no uniqueing is done, "
                        "and an error is given if "
                        "there is more than one compilation "
                        "action for a source file. "
                        "alpha(default in CTU mode): If there is more "
                        "than one compilation action for a source "
                        "file, only the one is kept that belongs to the "
                        "alphabetically first "
                        "compilation target. "
                        "If none of the above given, "
                        "this parameter should "
                        "be a python regular expression."
                        "If there is more than one compilation action "
                        "for a source, "
                        "only the one is kept which matches the "
                        "given python regex. If more than one "
                        "matches an error is given. "
                        "The whole compilation "
                        "action text is searched for match.")

    analyzer_opts.add_argument('--report-hash',
                               dest="report_hash",
                               default=argparse.SUPPRESS,
                               required=False,
                               choices=['context-free', 'context-free-v2'],
                               help="R|Specify the hash calculation method "
                               "for reports. By default the calculation "
                               "method for Clang Static Analyzer is "
                               "context sensitive and for Clang Tidy it "
                               "is context insensitive.\nYou can use the "
                               "following calculation methods:\n"
                               "- context-free: there was a bug and for "
                               "Clang Tidy not the context free hash "
                               "was generated (kept for backward "
                               "compatibility).\n"
                               "- context-free-v2: context free hash is "
                               "used for ClangSA and Clang Tidy.\n"
                               "See the 'issue hashes' section of the "
                               "help message of this command below for "
                               "more information.\n"
                               "USE WISELY AND AT YOUR OWN RISK!")

    skip_mode = analyzer_opts.add_mutually_exclusive_group()
    skip_mode.add_argument('-i',
                           '--ignore',
                           '--skip',
                           dest="skipfile",
                           required=False,
                           default=argparse.SUPPRESS,
                           help="Path to the Skipfile dictating which project "
                           "files should be omitted from analysis. "
                           "Please consult the User guide on how a "
                           "Skipfile should be laid out.")

    skip_mode.add_argument('--file',
                           nargs='+',
                           dest="files",
                           metavar='FILE',
                           required=False,
                           default=argparse.SUPPRESS,
                           help="Analyze only the given file(s) not the whole "
                           "compilation database. Absolute directory "
                           "paths should start with '/', relative "
                           "directory paths should start with '*' and "
                           "it can contain path glob pattern. "
                           "Example: '/path/to/main.cpp', 'lib/*.cpp', "
                           "*/test*'.")

    analyzer_opts.add_argument(
        '--analyzers',
        nargs='+',
        dest='analyzers',
        metavar='ANALYZER',
        required=False,
        choices=analyzer_types.supported_analyzers,
        default=argparse.SUPPRESS,
        help="Run analysis only with the analyzers "
        "specified. Currently supported analyzers "
        "are: " + ', '.join(analyzer_types.supported_analyzers) + ".")

    analyzer_opts.add_argument('--capture-analysis-output',
                               dest='capture_analysis_output',
                               action='store_true',
                               default=argparse.SUPPRESS,
                               required=False,
                               help="Store standard output and standard error "
                               "of successful analyzer invocations "
                               "into the '<OUTPUT_DIR>/success' "
                               "directory.")

    analyzer_opts.add_argument('--config',
                               dest='config_file',
                               required=False,
                               help="R|Allow the configuration from an "
                               "explicit JSON based configuration file. "
                               "The value of the 'analyzer' key in the "
                               "config file will be emplaced as command "
                               "line arguments. The format of "
                               "configuration file is:\n"
                               "{\n"
                               "  \"analyzer\": [\n"
                               "    \"--enable=core.DivideZero\",\n"
                               "    \"--enable=core.CallAndMessage\",\n"
                               "    \"--report-hash=context-free-v2\",\n"
                               "    \"--verbose=debug\",\n"
                               "    \"--skip=$HOME/project/skip.txt\",\n"
                               "    \"--clean\"\n"
                               "  ]\n"
                               "}.\n"
                               "You can use any environment variable "
                               "inside this file and it will be "
                               "expaneded.")

    # TODO: One day, get rid of these. See Issue #36, #427.
    analyzer_opts.add_argument('--saargs',
                               dest="clangsa_args_cfg_file",
                               required=False,
                               default=argparse.SUPPRESS,
                               help="File containing argument which will be "
                               "forwarded verbatim for the Clang Static "
                               "analyzer.")

    analyzer_opts.add_argument('--tidyargs',
                               dest="tidy_args_cfg_file",
                               required=False,
                               default=argparse.SUPPRESS,
                               help="File containing argument which will be "
                               "forwarded verbatim for the Clang-Tidy "
                               "analyzer.")

    analyzer_opts.add_argument('--tidy-config',
                               dest='tidy_config',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="A file in YAML format containing the "
                               "configuration of clang-tidy checkers. "
                               "The file can be dumped by "
                               "'CodeChecker analyzers --dump-config "
                               "clang-tidy' command.")

    analyzer_opts.add_argument('--analyzer-config',
                               dest='analyzer_config',
                               nargs='*',
                               default=["clang-tidy:HeaderFilterRegex=.*"],
                               help="Analyzer configuration options in the "
                               "following format: analyzer:key=value. "
                               "The collection of the options can be "
                               "printed with "
                               "'CodeChecker analyzers "
                               "--analyzer-config'. To disable the "
                               "default behaviour of this option you can "
                               "use the "
                               "'clang-tidy:take-config-from-directory="
                               "true' option. If the file at --tidyargs "
                               "contains a -config flag then those "
                               "options extend these and override "
                               "\"HeaderFilterRegex\" if any.")

    analyzer_opts.add_argument('--checker-config',
                               dest='checker_config',
                               nargs='*',
                               default=argparse.SUPPRESS,
                               help="Checker configuration options in the "
                               "following format: analyzer:key=value. "
                               "The collection of the options can be "
                               "printed with "
                               "'CodeChecker checkers --checker-config'.")

    analyzer_opts.add_argument('--timeout',
                               type=int,
                               dest='timeout',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="The amount of time (in seconds) that "
                               "each analyzer can spend, individually, "
                               "to analyze the project. If the analysis "
                               "of a particular file takes longer than "
                               "this time, the analyzer is killed and "
                               "the analysis is considered as a failed "
                               "one.")

    context = analyzer_context.get_context()
    clang_has_z3 = analyzer_types.is_z3_capable(context)

    if clang_has_z3:
        analyzer_opts.add_argument('--z3',
                                   dest='enable_z3',
                                   choices=['on', 'off'],
                                   default='off',
                                   help="Enable the z3 solver backend. This "
                                   "allows reasoning over more complex "
                                   "queries, but performance is worse "
                                   "than the default range-based "
                                   "constraint solver.")

    clang_has_z3_refutation = analyzer_types.is_z3_refutation_capable(context)

    if clang_has_z3_refutation:
        analyzer_opts.add_argument(
            '--z3-refutation',
            dest='enable_z3_refutation',
            choices=['on', 'off'],
            default='on' if clang_has_z3_refutation else 'off',
            help="Switch on/off the Z3 SMT Solver "
            "backend to "
            "reduce false positives. The results "
            "of the ranged based constraint "
            "solver in the Clang Static Analyzer "
            "will be cross checked with the Z3 "
            "SMT solver. This should not cause "
            "that much of a slowdown compared to "
            "using the Z3 solver only.")

    if analyzer_types.is_ctu_capable(context):
        ctu_opts = parser.add_argument_group(
            "cross translation unit analysis arguments", """
These arguments are only available if the Clang Static Analyzer supports
Cross-TU analysis. By default, no CTU analysis is run when 'CodeChecker check'
is called.""")

        ctu_modes = ctu_opts.add_mutually_exclusive_group()

        ctu_modes.add_argument('--ctu',
                               '--ctu-all',
                               action='store_const',
                               const=[True, True],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform Cross Translation Unit (CTU) "
                               "analysis, both 'collect' and 'analyze' "
                               "phases. In this mode, the extra files "
                               "created by 'collect' are cleaned up "
                               "after the analysis.")

        ctu_modes.add_argument('--ctu-collect',
                               action='store_const',
                               const=[True, False],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform the first, 'collect' phase of "
                               "Cross-TU analysis. This phase generates "
                               "extra files needed by CTU analysis, and "
                               "puts them into '<OUTPUT_DIR>/ctu-dir'. "
                               "NOTE: If this argument is present, "
                               "CodeChecker will NOT execute the "
                               "analyzers!")

        ctu_modes.add_argument('--ctu-analyze',
                               action='store_const',
                               const=[False, True],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform the second, 'analyze' phase of "
                               "Cross-TU analysis, using already "
                               "available extra files in "
                               "'<OUTPUT_DIR>/ctu-dir'. (These files "
                               "will not be cleaned up in this mode.)")

        ctu_opts.add_argument('--ctu-reanalyze-on-failure',
                              action='store_true',
                              dest='ctu_reanalyze_on_failure',
                              default=argparse.SUPPRESS,
                              help="DEPRECATED. The flag will be removed. "
                              "If Cross-TU analysis is enabled and "
                              "fails for some reason, try to re analyze "
                              "the same translation unit without "
                              "Cross-TU enabled.")

        # Only check for AST loading modes if CTU is available.
        if analyzer_types.is_ctu_on_demand_available(context):
            ctu_opts.add_argument('--ctu-ast-mode',
                                  action='store',
                                  dest='ctu_ast_mode',
                                  choices=['load-from-pch', 'parse-on-demand'],
                                  default=argparse.SUPPRESS,
                                  help="Choose the way ASTs are loaded during "
                                  "CTU analysis. Only available if CTU "
                                  "mode is enabled. Mode 'load-from-pch' "
                                  "generates PCH format serialized ASTs "
                                  "during the 'collect' phase. Mode "
                                  "'parse-on-demand' only generates the "
                                  "invocations needed to parse the ASTs. "
                                  "Mode 'load-from-pch' can use "
                                  "significant disk-space for the "
                                  "serialized ASTs, while mode "
                                  "'parse-on-demand' can incur some "
                                  "runtime CPU overhead in the second "
                                  "phase of the analysis. (default: "
                                  "parse-on-demand)")

    if analyzer_types.is_statistics_capable(context):
        stat_opts = parser.add_argument_group(
            "Statistics analysis feature arguments", """
These arguments are only available if the Clang Static Analyzer supports
Statistics-based analysis (e.g. statisticsCollector.ReturnValueCheck,
statisticsCollector.SpecialReturnValue checkers are available).""")

        stat_opts.add_argument('--stats-collect',
                               '--stats-collect',
                               action='store',
                               default=argparse.SUPPRESS,
                               dest='stats_output',
                               help="Perform the first, 'collect' phase of "
                               "Statistical analysis. This phase "
                               "generates extra files needed by "
                               "statistics analysis, and "
                               "puts them into "
                               "'<STATS_OUTPUT>'."
                               " NOTE: If this argument is present, "
                               "CodeChecker will NOT execute the "
                               "analyzers!")

        stat_opts.add_argument('--stats-use',
                               '--stats-use',
                               action='store',
                               default=argparse.SUPPRESS,
                               dest='stats_dir',
                               help="Use the previously generated statistics "
                               "results for the analysis from the given "
                               "'<STATS_DIR>'.")

        stat_opts.add_argument('--stats',
                               action='store_true',
                               default=argparse.SUPPRESS,
                               dest='stats_enabled',
                               help="Perform both phases of "
                               "Statistical analysis. This phase "
                               "generates extra files needed by "
                               "statistics analysis and enables "
                               "the statistical checkers. "
                               "No need to enable them explicitly.")

        stat_opts.add_argument('--stats-min-sample-count',
                               action='store',
                               default="10",
                               type=int,
                               dest='stats_min_sample_count',
                               help="Minimum number of samples (function call"
                               " occurrences) to be collected"
                               " for a statistics to be relevant.")

        stat_opts.add_argument('--stats-relevance-threshold',
                               action='store',
                               default="0.85",
                               type=float,
                               dest='stats_relevance_threshold',
                               help="The minimum ratio of calls of function "
                               "f that must have a certain property "
                               "property to consider it true for that "
                               "function (calculated as calls "
                               "with a property/all calls)."
                               " CodeChecker will warn for"
                               " calls of f do not have that property.")

    checkers_opts = parser.add_argument_group(
        "checker configuration", """
Checkers
------------------------------------------------
The analyzer performs checks that are categorized into families or "checkers".
See 'CodeChecker checkers' for the list of available checkers. You can
fine-tune which checkers to use in the analysis by setting the enabled and
disabled flags starting from the bigger groups and going inwards, e.g.
'-e core -d core.uninitialized -e core.uninitialized.Assign' will enable every
'core' checker, but only 'core.uninitialized.Assign' from the
'core.uninitialized' group. Please consult the manual for details. Disabling
certain checkers - such as the 'core' group - is unsupported by the LLVM/Clang
community, and thus discouraged.

Compiler warnings and errors
------------------------------------------------
Compiler warnings are diagnostic messages that report constructions that are
not inherently erroneous but that are risky or suggest there may have been an
error. Compiler warnings are named 'clang-diagnostic-<warning-option>', e.g.
Clang warning controlled by '-Wliteral-conversion' will be reported with check
name 'clang-diagnostic-literal-conversion'. You can fine-tune which warnings to
use in the analysis by setting the enabled and disabled flags starting from the
bigger groups and going inwards, e.g. '-e Wunused -d Wno-unused-parameter' will
enable every 'unused' warnings except 'unused-parameter'. These flags should
start with a capital 'W' or 'Wno-' prefix followed by the waning name (E.g.:
'-e Wliteral-conversion', '-d Wno-literal-conversion'). By default '-Wall' and
'-Wextra' warnings are enabled. For more information see:
https://clang.llvm.org/docs/DiagnosticsReference.html.
Sometimes GCC is more permissive than Clang, so it is possible that a specific
construction doesn't compile with Clang but compiles with GCC. These
compiler errors are also collected as CodeChecker reports as
'clang-diagnostic-error'.
Note that compiler errors and warnings are captured by CodeChecker only if it
was emitted by clang-tidy.

Profiles
------------------------------------------------
In CodeCheckers there is a manual grouping of checkers. These groups are called
profiles. The collection of profiles is found in
config/checker_profile_map.json file. The goal of these profile is that you can
enable or disable checkers by these profiles. See the output of "CodeChecker
checkers --profile list" command.

Guidelines
------------------------------------------------
There are several coding guidelines like CppCoreGuideline, SEI-CERT, etc. These
are collections of best programming practices to avoid common programming
errors. Some checkers cover the rules of these guidelines. In CodeChecker there
is a mapping between guidelines and checkers. This way you can list and enable
those checkers which check the fulfillment of certain guideline rules. See the
output of "CodeChecker checkers --guideline" command.""")

    checkers_opts.add_argument('-e',
                               '--enable',
                               dest="enable",
                               metavar='checker/group/profile',
                               default=argparse.SUPPRESS,
                               action=OrderedCheckersAction,
                               help="Set a checker (or checker group), "
                               "profile or guideline "
                               "to BE USED in the analysis. In case of "
                               "ambiguity the priority order is profile, "
                               "guideline, checker name (e.g. security "
                               "means the profile, not the checker "
                               "group). Profiles and guidelines can be "
                               "labeled: 'profile:security' or "
                               "'guideline:sei-cert'.")

    checkers_opts.add_argument('-d',
                               '--disable',
                               dest="disable",
                               metavar='checker/group/profile',
                               default=argparse.SUPPRESS,
                               action=OrderedCheckersAction,
                               help="Set a checker (or checker group), "
                               "profile or guideline "
                               "to BE PROHIBITED from use in the "
                               "analysis. In case of "
                               "ambiguity the priority order is profile, "
                               "guideline, checker name (e.g. security "
                               "means the profile, not the checker "
                               "group). Profiles and guidelines can be "
                               "labeled: 'profile:security' or "
                               "'guideline:sei-cert'.")

    checkers_opts.add_argument('--enable-all',
                               dest="enable_all",
                               action='store_true',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="Force the running analyzers to use "
                               "almost every checker available. The "
                               "checker groups 'alpha.', 'debug.',"
                               "'osx.', 'abseil-', 'android-', "
                               "'darwin-', 'objc-', "
                               "'cppcoreguidelines-', 'fuchsia.', "
                               "'fuchsia-', 'hicpp-', 'llvm-', "
                               "'llvmlibc-', 'google-', 'zircon-', "
                               "'osx.' (on Linux) are NOT enabled "
                               "automatically and must be EXPLICITLY "
                               "specified. WARNING! Enabling all "
                               "checkers might result in the analysis "
                               "losing precision and stability, and "
                               "could even result in a total failure of "
                               "the analysis. USE WISELY AND AT YOUR "
                               "OWN RISK!")

    output_opts = parser.add_argument_group("output arguments")

    output_opts.add_argument('--print-steps',
                             dest="print_steps",
                             action="store_true",
                             required=False,
                             default=argparse.SUPPRESS,
                             help="Print the steps the analyzers took in "
                             "finding the reported defect.")

    output_opts.add_argument('--suppress',
                             type=str,
                             dest="suppress",
                             default=argparse.SUPPRESS,
                             required=False,
                             help="Path of the suppress file to use. Records "
                             "in the suppress file are used to suppress "
                             "the display of certain results when "
                             "parsing the analyses' report. (Reports to "
                             "an analysis result can also be suppressed "
                             "in the source code -- please consult the "
                             "manual on how to do so.) NOTE: The "
                             "suppress file relies on the "
                             "\"bug identifier\" generated by the "
                             "analyzers which is experimental, take "
                             "care when relying on it.")

    parser.add_argument('--review-status',
                        nargs='*',
                        dest="review_status",
                        metavar='REVIEW_STATUS',
                        choices=REVIEW_STATUS_VALUES,
                        default=["confirmed", "unreviewed"],
                        help="Filter results by review statuses. Valid "
                        "values are: {0}".format(
                            ', '.join(REVIEW_STATUS_VALUES)))

    logger.add_verbose_arguments(parser)
    parser.set_defaults(func=main)
Exemple #3
0
def add_arguments_to_parser(parser):
    """
    Add the subcommand's arguments to the given argparse.ArgumentParser.
    """

    parser.add_argument('-o',
                        '--output',
                        type=str,
                        dest="output_dir",
                        required=False,
                        default=argparse.SUPPRESS,
                        help="Store the analysis output in the given folder. "
                        "If it is not given then the results go into a "
                        "temporary directory which will be removed after "
                        "the analysis.")

    parser.add_argument('-t',
                        '--type',
                        '--output-format',
                        dest="output_format",
                        required=False,
                        choices=['plist'],
                        default='plist',
                        help="Specify the format the analysis results "
                        "should use.")

    parser.add_argument('-q',
                        '--quiet',
                        dest="quiet",
                        action='store_true',
                        required=False,
                        default=argparse.SUPPRESS,
                        help="If specified, the build tool's and the "
                        "analyzers' output will not be printed to the "
                        "standard output.")

    parser.add_argument('-f',
                        '--force',
                        dest="force",
                        default=argparse.SUPPRESS,
                        action='store_true',
                        required=False,
                        help="DEPRECATED. Delete analysis results stored in "
                        "the database for the current analysis run's "
                        "name and store only the results reported in the "
                        "'input' files. (By default, CodeChecker would "
                        "keep reports that were coming from files not "
                        "affected by the analysis, and only "
                        "incrementally update defect reports for source "
                        "files that were analysed.)")

    log_args = parser.add_argument_group(
        "log arguments", """
Specify how the build information database should be obtained. You need to
specify either an already existing log file, or a build command which will be
used to generate a log file on the fly.""")

    log_args = log_args.add_mutually_exclusive_group(required=True)

    log_args.add_argument('-b',
                          '--build',
                          type=str,
                          dest="command",
                          default=argparse.SUPPRESS,
                          help="Execute and record a build command. Build "
                          "commands can be simple calls to 'g++' or "
                          "'clang++' or 'make', but a more complex "
                          "command, or the call of a custom script file "
                          "is also supported.")

    log_args.add_argument('-l',
                          '--logfile',
                          type=str,
                          dest="logfile",
                          default=argparse.SUPPRESS,
                          help="Use an already existing JSON compilation "
                          "command database file specified at this path.")

    analyzer_opts = parser.add_argument_group("analyzer arguments")
    analyzer_opts.add_argument('-j',
                               '--jobs',
                               type=int,
                               dest="jobs",
                               required=False,
                               default=1,
                               help="Number of threads to use in analysis. "
                               "More threads mean faster analysis at "
                               "the cost of using more memory.")

    analyzer_opts.add_argument('-c',
                               '--clean',
                               dest="clean",
                               required=False,
                               action='store_true',
                               default=argparse.SUPPRESS,
                               help="Delete analysis reports stored in the "
                               "output directory. (By default, "
                               "CodeChecker would keep reports and "
                               "overwrites only those files that were "
                               "update by the current build command).")

    parser.add_argument('--compile-uniqueing',
                        type=str,
                        dest="compile_uniqueing",
                        default="none",
                        required=False,
                        help="Specify the method the compilation "
                        "actions in the  compilation database are "
                        "uniqued before analysis. "
                        "CTU analysis works properly only if "
                        "there is exactly one "
                        "compilation action per source file. "
                        "none(default in non CTU mode): "
                        "no uniqueing is done. "
                        "strict: no uniqueing is done, "
                        "and an error is given if "
                        "there is more than one compilation "
                        "action for a source file. "
                        "alpha(default in CTU mode): If there is more "
                        "than one compilation action for a source "
                        "file, only the one is kept that belongs to the "
                        "alphabetically first "
                        "compilation target. "
                        "If none of the above given, "
                        "this parameter should "
                        "be a python regular expression."
                        "If there is more than one compilation action "
                        "for a source, "
                        "only the one is kept which matches the "
                        "given python regex. If more than one "
                        "matches an error is given. "
                        "The whole compilation "
                        "action text is searched for match.")

    analyzer_opts.add_argument('--report-hash',
                               dest="report_hash",
                               default=argparse.SUPPRESS,
                               required=False,
                               choices=['context-free'],
                               help="EXPERIMENTAL feature. "
                               "Specify the hash calculation method for "
                               "reports. If this option is not set, the "
                               "default calculation method for Clang "
                               "Static Analyzer will be context "
                               "sensitive and for Clang Tidy it will be "
                               "context insensitive. If this option is "
                               "set to 'context-free' bugs will be "
                               "identified with the CodeChecker "
                               "generated context free hash for every "
                               "analyzers. USE WISELY AND AT YOUR OWN "
                               "RISK!")

    analyzer_opts.add_argument('-i',
                               '--ignore',
                               '--skip',
                               dest="skipfile",
                               required=False,
                               default=argparse.SUPPRESS,
                               help="Path to the Skipfile dictating which "
                               "project files should be omitted from "
                               "analysis. Please consult the User guide "
                               "on how a Skipfile should be laid out.")

    analyzer_opts.add_argument(
        '--analyzers',
        nargs='+',
        dest='analyzers',
        metavar='ANALYZER',
        required=False,
        choices=analyzer_types.supported_analyzers,
        default=argparse.SUPPRESS,
        help="Run analysis only with the analyzers "
        "specified. Currently supported analyzers "
        "are: " + ', '.join(analyzer_types.supported_analyzers) + ".")

    analyzer_opts.add_argument('--add-compiler-defaults',
                               action='store_true',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="DEPRECATED. Always True. Retrieve "
                               " compiler-specific configuration "
                               "from the analyzers themselves, and use "
                               "them with Clang. This is used when the "
                               "compiler on the system is special, e.g. "
                               "when doing cross-compilation.")

    analyzer_opts.add_argument('--capture-analysis-output',
                               dest='capture_analysis_output',
                               action='store_true',
                               default=argparse.SUPPRESS,
                               required=False,
                               help="Store standard output and standard error "
                               "of successful analyzer invocations "
                               "into the '<OUTPUT_DIR>/success' "
                               "directory.")

    # TODO: One day, get rid of these. See Issue #36, #427.
    analyzer_opts.add_argument('--saargs',
                               dest="clangsa_args_cfg_file",
                               required=False,
                               default=argparse.SUPPRESS,
                               help="File containing argument which will be "
                               "forwarded verbatim for the Clang Static "
                               "analyzer.")

    analyzer_opts.add_argument('--tidyargs',
                               dest="tidy_args_cfg_file",
                               required=False,
                               default=argparse.SUPPRESS,
                               help="File containing argument which will be "
                               "forwarded verbatim for the Clang-Tidy "
                               "analyzer.")

    analyzer_opts.add_argument('--tidy-config',
                               dest='tidy_config',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="A file in YAML format containing the "
                               "configuration of clang-tidy checkers. "
                               "The file can be dumped by "
                               "'CodeChecker analyzers --dump-config "
                               "clang-tidy' command.")

    analyzer_opts.add_argument('--timeout',
                               type=int,
                               dest='timeout',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="The amount of time (in seconds) that "
                               "each analyzer can spend, individually, "
                               "to analyze the project. If the analysis "
                               "of a particular file takes longer than "
                               "this time, the analyzer is killed and "
                               "the analysis is considered as a failed "
                               "one.")

    context = analyzer_context.get_context()
    clang_has_z3 = analyzer_types.is_z3_capable(context)

    if clang_has_z3:
        analyzer_opts.add_argument('--z3',
                                   dest='enable_z3',
                                   choices=['on', 'off'],
                                   default='off',
                                   help="Enable the z3 solver backend. This "
                                   "allows reasoning over more complex "
                                   "queries, but performance is worse "
                                   "than the default range-based "
                                   "constraint solver.")

    clang_has_z3_refutation = analyzer_types.is_z3_refutation_capable(context)

    if clang_has_z3_refutation:
        analyzer_opts.add_argument(
            '--z3-refutation',
            dest='enable_z3_refutation',
            choices=['on', 'off'],
            default='on' if clang_has_z3_refutation else 'off',
            help="Switch on/off the Z3 SMT Solver "
            "backend to "
            "reduce false positives. The results "
            "of the ranged based constraint "
            "solver in the Clang Static Analyzer "
            "will be cross checked with the Z3 "
            "SMT solver. This should not cause "
            "that much of a slowdown compared to "
            "using the Z3 solver only.")

    if analyzer_types.is_ctu_capable(context):
        ctu_opts = parser.add_argument_group(
            "cross translation unit analysis arguments", """
These arguments are only available if the Clang Static Analyzer supports
Cross-TU analysis. By default, no CTU analysis is run when 'CodeChecker check'
is called.""")

        ctu_modes = ctu_opts.add_mutually_exclusive_group()

        ctu_modes.add_argument('--ctu',
                               '--ctu-all',
                               action='store_const',
                               const=[True, True],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform Cross Translation Unit (CTU) "
                               "analysis, both 'collect' and 'analyze' "
                               "phases. In this mode, the extra files "
                               "created by 'collect' are cleaned up "
                               "after the analysis.")

        ctu_modes.add_argument('--ctu-collect',
                               action='store_const',
                               const=[True, False],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform the first, 'collect' phase of "
                               "Cross-TU analysis. This phase generates "
                               "extra files needed by CTU analysis, and "
                               "puts them into '<OUTPUT_DIR>/ctu-dir'. "
                               "NOTE: If this argument is present, "
                               "CodeChecker will NOT execute the "
                               "analyzers!")

        ctu_modes.add_argument('--ctu-analyze',
                               action='store_const',
                               const=[False, True],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform the second, 'analyze' phase of "
                               "Cross-TU analysis, using already "
                               "available extra files in "
                               "'<OUTPUT_DIR>/ctu-dir'. (These files "
                               "will not be cleaned up in this mode.)")

    if analyzer_types.is_statistics_capable(context):
        stat_opts = parser.add_argument_group(
            "EXPERIMENTAL statistics analysis feature arguments", """
These arguments are only available if the Clang Static Analyzer supports
Statistics-based analysis (e.g. statisticsCollector.ReturnValueCheck,
statisticsCollector.SpecialReturnValue checkers are available).""")

        stat_opts.add_argument('--stats-collect',
                               '--stats-collect',
                               action='store',
                               default=argparse.SUPPRESS,
                               dest='stats_output',
                               help="EXPERIMENTAL feature. "
                               "Perform the first, 'collect' phase of "
                               "Statistical analysis. This phase "
                               "generates extra files needed by "
                               "statistics analysis, and "
                               "puts them into "
                               "'<STATS_OUTPUT>'."
                               " NOTE: If this argument is present, "
                               "CodeChecker will NOT execute the "
                               "analyzers!")

        stat_opts.add_argument('--stats-use',
                               '--stats-use',
                               action='store',
                               default=argparse.SUPPRESS,
                               dest='stats_dir',
                               help="EXPERIMENTAL feature. "
                               "Use the previously generated statistics "
                               "results for the analysis from the given "
                               "'<STATS_DIR>'.")

        stat_opts.add_argument('--stats',
                               action='store_true',
                               default=argparse.SUPPRESS,
                               dest='stats_enabled',
                               help="EXPERIMENTAL feature. "
                               "Perform both phases of "
                               "Statistical analysis. This phase "
                               "generates extra files needed by "
                               "statistics analysis and enables "
                               "the statistical checkers. "
                               "No need to enable them explicitly.")

        stat_opts.add_argument('--stats-min-sample-count',
                               action='store',
                               default="10",
                               type=int,
                               dest='stats_min_sample_count',
                               help="EXPERIMENTAL feature. "
                               "Minimum number of samples (function call"
                               " occurrences) to be collected"
                               " for a statistics to be relevant.")

        stat_opts.add_argument('--stats-relevance-threshold',
                               action='store',
                               default="0.85",
                               type=float,
                               dest='stats_relevance_threshold',
                               help="EXPERIMENTAL feature. "
                               "The minimum ratio of calls of function "
                               "f that must have a certain property "
                               "property to consider it true for that "
                               "function (calculated as calls "
                               "with a property/all calls)."
                               " CodeChecker will warn for"
                               " calls of f do not have that property.")

    checkers_opts = parser.add_argument_group(
        "checker configuration", """
Checkers
------------------------------------------------
The analyzer performs checks that are categorized into families or "checkers".
See 'CodeChecker checkers' for the list of available checkers. You can
fine-tune which checkers to use in the analysis by setting the enabled and
disabled flags starting from the bigger groups and going inwards, e.g.
'-e core -d core.uninitialized -e core.uninitialized.Assign' will enable every
'core' checker, but only 'core.uninitialized.Assign' from the
'core.uninitialized' group. Please consult the manual for details. Disabling
certain checkers - such as the 'core' group - is unsupported by the LLVM/Clang
community, and thus discouraged.

Compiler warnings
------------------------------------------------
Compiler warnings are diagnostic messages that report constructions that are
not inherently erroneous but that are risky or suggest there may have been an
error. Compiler warnings are named 'clang-diagnostic-<warning-option>', e.g.
Clang warning controlled by '-Wliteral-conversion' will be reported with check
name 'clang-diagnostic-literal-conversion'. You can fine-tune which warnings to
use in the analysis by setting the enabled and disabled flags starting from the
bigger groups and going inwards, e.g. '-e Wunused -d Wno-unused-parameter' will
enable every 'unused' warnings except 'unused-parameter'. These flags should
start with a capital 'W' or 'Wno-' prefix followed by the waning name (E.g.:
'-e Wliteral-conversion', '-d Wno-literal-conversion'). By default '-Wall' and
'-Wextra' warnings are enabled. For more information see:
https://clang.llvm.org/docs/DiagnosticsReference.html.""")

    checkers_opts.add_argument('-e',
                               '--enable',
                               dest="enable",
                               metavar='checker/group/profile',
                               default=argparse.SUPPRESS,
                               action=arg.OrderedCheckersAction,
                               help="Set a checker (or checker group) "
                               "to BE USED in the analysis.")

    checkers_opts.add_argument('-d',
                               '--disable',
                               dest="disable",
                               metavar='checker/group/profile',
                               default=argparse.SUPPRESS,
                               action=arg.OrderedCheckersAction,
                               help="Set a checker (or checker group) "
                               "to BE PROHIBITED from use in the "
                               "analysis.")

    checkers_opts.add_argument('--enable-all',
                               dest="enable_all",
                               action='store_true',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="Force the running analyzers to use "
                               "almost every checker available. The "
                               "checker groups 'alpha.', 'debug.' and "
                               "'osx.' (on Linux) are NOT enabled "
                               "automatically and must be EXPLICITLY "
                               "specified. WARNING! Enabling all "
                               "checkers might result in the analysis "
                               "losing precision and stability, and "
                               "could even result in a total failure of "
                               "the analysis. USE WISELY AND AT YOUR "
                               "OWN RISK!")

    output_opts = parser.add_argument_group("output arguments")

    output_opts.add_argument('--print-steps',
                             dest="print_steps",
                             action="store_true",
                             required=False,
                             default=argparse.SUPPRESS,
                             help="Print the steps the analyzers took in "
                             "finding the reported defect.")

    logger.add_verbose_arguments(parser)
    parser.set_defaults(func=main)
Exemple #4
0
def add_arguments_to_parser(parser):
    """
    Add the subcommand's arguments to the given argparse.ArgumentParser.
    """

    parser.add_argument('logfile',
                        type=str,
                        nargs='+',
                        help="Path to the JSON compilation command database "
                             "files which were created during the build. "
                             "The analyzers will check only the files "
                             "registered in these build databases.")

    parser.add_argument('-j', '--jobs',
                        type=int,
                        dest="jobs",
                        required=False,
                        default=1,
                        help="Number of threads to use in analysis. More "
                             "threads mean faster analysis at the cost of "
                             "using more memory.")

    parser.add_argument('-i', '--ignore', '--skip',
                        dest="skipfile",
                        required=False,
                        default=argparse.SUPPRESS,
                        help="Path to the Skipfile dictating which project "
                             "files should be omitted from analysis. Please "
                             "consult the User guide on how a Skipfile "
                             "should be laid out.")

    parser.add_argument('-o', '--output',
                        dest="output_path",
                        required=True,
                        default=argparse.SUPPRESS,
                        help="Store the analysis output in the given folder.")

    parser.add_argument('--compiler-info-file',
                        dest="compiler_info_file",
                        required=False,
                        default=argparse.SUPPRESS,
                        help="Read the compiler includes and target from the "
                             "specified file rather than invoke the compiler "
                             "executable.")

    parser.add_argument('-t', '--type', '--output-format',
                        dest="output_format",
                        required=False,
                        choices=['plist'],
                        default='plist',
                        help="Specify the format the analysis results should "
                             "use.")

    parser.add_argument('-q', '--quiet',
                        dest="quiet",
                        action='store_true',
                        default=argparse.SUPPRESS,
                        required=False,
                        help="Do not print the output or error of the "
                             "analyzers to the standard output of "
                             "CodeChecker.")

    parser.add_argument('-c', '--clean',
                        dest="clean",
                        required=False,
                        action='store_true',
                        default=argparse.SUPPRESS,
                        help="Delete analysis reports stored in the output "
                             "directory. (By default, CodeChecker would keep "
                             "reports and overwrites only those files that "
                             "were update by the current build command).")

    parser.add_argument('--compile-uniqueing',
                        type=str,
                        dest="compile_uniqueing",
                        default="none",
                        required=False,
                        help="Specify the method the compilation "
                             "actions in the  compilation database are "
                             "uniqued before analysis. "
                             "CTU analysis works properly only if "
                             "there is exactly one "
                             "compilation action per source file. "
                             "none(default in non CTU mode): "
                             "no uniqueing is done. "
                             "strict: no uniqueing is done, "
                             "and an error is given if "
                             "there is more than one compilation "
                             "action for a source file. "
                             "alpha(default in CTU mode): If there is more "
                             "than one compilation action for a source "
                             "file, only the one is kept that belongs to the "
                             "alphabetically first "
                             "compilation target. "
                             "If none of the above given, "
                             "this parameter should "
                             "be a python regular expression."
                             "If there is more than one compilation action "
                             "for a source, "
                             "only the one is kept which matches the "
                             "given python regex. If more than one "
                             "matches an error is given. "
                             "The whole compilation "
                             "action text is searched for match.")

    parser.add_argument('--report-hash',
                        dest="report_hash",
                        default=argparse.SUPPRESS,
                        required=False,
                        choices=['context-free'],
                        help="EXPERIMENTAL feature. "
                             "Specify the hash calculation method for "
                             "reports. If this option is not set, the default "
                             "calculation method for Clang Static Analyzer "
                             "will be context sensitive and for Clang Tidy it "
                             "will be context insensitive. If this option is "
                             "set to 'context-free' bugs will be identified "
                             "with the CodeChecker generated context free "
                             "hash for every analyzers. USE WISELY AND AT "
                             "YOUR OWN RISK!")

    parser.add_argument('-n', '--name',
                        dest="name",
                        required=False,
                        default=argparse.SUPPRESS,
                        help="Annotate the run analysis with a custom name in "
                             "the created metadata file.")

    analyzer_opts = parser.add_argument_group("analyzer arguments")

    analyzer_opts.add_argument('--analyzers',
                               nargs='+',
                               dest='analyzers',
                               metavar='ANALYZER',
                               required=False,
                               choices=analyzer_types.supported_analyzers,
                               default=argparse.SUPPRESS,
                               help="Run analysis only with the analyzers "
                                    "specified. Currently supported analyzers "
                                    "are: " +
                                    ', '.join(analyzer_types.
                                              supported_analyzers) + ".")

    analyzer_opts.add_argument('--add-compiler-defaults',
                               action='store_true',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="DEPRECATED. Always True. Retrieve "
                                    "compiler-specific configuration "
                                    "from the compilers themselves, and use "
                                    "them with Clang. This is used when the "
                                    "compiler on the system is special, e.g. "
                                    "when doing cross-compilation.")

    analyzer_opts.add_argument('--capture-analysis-output',
                               dest='capture_analysis_output',
                               action='store_true',
                               default=argparse.SUPPRESS,
                               required=False,
                               help="Store standard output and standard error "
                                    "of successful analyzer invocations "
                                    "into the '<OUTPUT_DIR>/success' "
                                    "directory.")

    analyzer_opts.add_argument('--saargs',
                               dest="clangsa_args_cfg_file",
                               required=False,
                               default=argparse.SUPPRESS,
                               help="File containing argument which will be "
                                    "forwarded verbatim for the Clang Static "
                                    "Analyzer.")

    analyzer_opts.add_argument('--tidyargs',
                               dest="tidy_args_cfg_file",
                               required=False,
                               default=argparse.SUPPRESS,
                               help="File containing argument which will be "
                                    "forwarded verbatim for Clang-Tidy.")

    analyzer_opts.add_argument('--tidy-config',
                               dest='tidy_config',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="A file in YAML format containing the "
                                    "configuration of clang-tidy checkers. "
                                    "The file can be dumped by "
                                    "'CodeChecker analyzers --dump-config "
                                    "clang-tidy' command.")

    analyzer_opts.add_argument('--timeout',
                               type=int,
                               dest='timeout',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="The amount of time (in seconds) that "
                                    "each analyzer can spend, individually, "
                                    "to analyze the project. If the analysis "
                                    "of a particular file takes longer than "
                                    "this time, the analyzer is killed and "
                                    "the analysis is considered as a failed "
                                    "one.")

    context = analyzer_context.get_context()
    if analyzer_types.is_ctu_capable(context):
        ctu_opts = parser.add_argument_group(
            "cross translation unit analysis arguments",
            """
These arguments are only available if the Clang Static Analyzer supports
Cross-TU analysis. By default, no CTU analysis is run when
'CodeChecker analyze' is called.""")

        ctu_modes = ctu_opts.add_mutually_exclusive_group()
        ctu_modes.add_argument('--ctu', '--ctu-all',
                               action='store_const',
                               const=[True, True],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform Cross Translation Unit (CTU) "
                                    "analysis, both 'collect' and 'analyze' "
                                    "phases. In this mode, the extra files "
                                    "created by 'collect' are cleaned up "
                                    "after the analysis.")

        ctu_modes.add_argument('--ctu-collect',
                               action='store_const',
                               const=[True, False],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform the first, 'collect' phase of "
                                    "Cross-TU analysis. This phase generates "
                                    "extra files needed by CTU analysis, and "
                                    "puts them into '<OUTPUT_DIR>/ctu-dir'. "
                                    "NOTE: If this argument is present, "
                                    "CodeChecker will NOT execute the "
                                    "analyzers!")

        ctu_modes.add_argument('--ctu-analyze',
                               action='store_const',
                               const=[False, True],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform the second, 'analyze' phase of "
                                    "Cross-TU analysis, using already "
                                    "available extra files in "
                                    "'<OUTPUT_DIR>/ctu-dir'. (These files "
                                    "will not be cleaned up in this mode.)")

        ctu_opts.add_argument('--ctu-reanalyze-on-failure',
                              action='store_true',
                              dest='ctu_reanalyze_on_failure',
                              default=argparse.SUPPRESS,
                              help="If Cross-TU analysis is enabled and fails "
                                   "for some reason, try to re analyze the "
                                   "same translation unit without "
                                   "Cross-TU enabled.")

    if analyzer_types.is_statistics_capable(context):
        stat_opts = parser.add_argument_group(
            "EXPERIMENTAL statistics analysis feature arguments",
            """
These arguments are only available if the Clang Static Analyzer supports
Statistics-based analysis (e.g. statisticsCollector.ReturnValueCheck,
statisticsCollector.SpecialReturnValue checkers are available).""")

        stat_opts.add_argument('--stats-collect', '--stats-collect',
                               action='store',
                               default=argparse.SUPPRESS,
                               dest='stats_output',
                               help="EXPERIMENTAL feature. "
                                    "Perform the first, 'collect' phase of "
                                    "Statistical analysis. This phase "
                                    "generates extra files needed by "
                                    "statistics analysis, and "
                                    "puts them into "
                                    "'<STATS_OUTPUT>'."
                                    " NOTE: If this argument is present, "
                                    "CodeChecker will NOT execute the "
                                    "analyzers!")

        stat_opts.add_argument('--stats-use', '--stats-use',
                               action='store',
                               default=argparse.SUPPRESS,
                               dest='stats_dir',
                               help="EXPERIMENTAL feature. "
                                    "Use the previously generated statistics "
                                    "results for the analysis from the given "
                                    "'<STATS_DIR>'.")

        stat_opts.add_argument('--stats',
                               action='store_true',
                               default=argparse.SUPPRESS,
                               dest='stats_enabled',
                               help="EXPERIMENTAL feature. "
                                    "Perform both phases of "
                                    "Statistical analysis. This phase "
                                    "generates extra files needed by "
                                    "statistics analysis and enables "
                                    "the statistical checkers. "
                                    "No need to enable them explicitly.")

        stat_opts.add_argument('--stats-min-sample-count',
                               action='store',
                               default="10",
                               type=int,
                               dest='stats_min_sample_count',
                               help="EXPERIMENTAL feature. "
                                    "Minimum number of samples (function call"
                                    " occurrences) to be collected"
                                    " for a statistics to be relevant "
                                    "'<MIN-SAMPLE-COUNT>'.")

        stat_opts.add_argument('--stats-relevance-threshold',
                               action='store',
                               default="0.85",
                               type=float,
                               dest='stats_relevance_threshold',
                               help="EXPERIMENTAL feature. "
                                    "The minimum ratio of calls of function "
                                    "f that must have a certain property "
                                    "property to consider it true for that "
                                    "function (calculated as calls "
                                    "with a property/all calls)."
                                    " CodeChecker will warn for"
                                    " calls of f do not have that property."
                                    "'<RELEVANCE_THRESHOLD>'.")

    checkers_opts = parser.add_argument_group(
        "checker configuration",
        """
Checkers
------------------------------------------------
The analyzer performs checks that are categorized into families or "checkers".
See 'CodeChecker checkers' for the list of available checkers. You can
fine-tune which checkers to use in the analysis by setting the enabled and
disabled flags starting from the bigger groups and going inwards, e.g.
'-e core -d core.uninitialized -e core.uninitialized.Assign' will enable every
'core' checker, but only 'core.uninitialized.Assign' from the
'core.uninitialized' group. Please consult the manual for details. Disabling
certain checkers - such as the 'core' group - is unsupported by the LLVM/Clang
community, and thus discouraged.

Compiler warnings
------------------------------------------------
Compiler warnings are diagnostic messages that report constructions that are
not inherently erroneous but that are risky or suggest there may have been an
error. Compiler warnings are named 'clang-diagnostic-<warning-option>', e.g.
Clang warning controlled by '-Wliteral-conversion' will be reported with check
name 'clang-diagnostic-literal-conversion'. You can fine-tune which warnings to
use in the analysis by setting the enabled and disabled flags starting from the
bigger groups and going inwards, e.g. '-e Wunused -d Wno-unused-parameter' will
enable every 'unused' warnings except 'unused-parameter'. These flags should
start with a capital 'W' or 'Wno-' prefix followed by the waning name (E.g.:
'-e Wliteral-conversion', '-d Wno-literal-conversion'). By default '-Wall' and
'-Wextra' warnings are enabled. For more information see:
https://clang.llvm.org/docs/DiagnosticsReference.html.""")

    checkers_opts.add_argument('-e', '--enable',
                               dest="enable",
                               metavar='checker/group/profile',
                               default=argparse.SUPPRESS,
                               action=OrderedCheckersAction,
                               help="Set a checker (or checker group) "
                                    "to BE USED in the analysis.")

    checkers_opts.add_argument('-d', '--disable',
                               dest="disable",
                               metavar='checker/group/profile',
                               default=argparse.SUPPRESS,
                               action=OrderedCheckersAction,
                               help="Set a checker (or checker group) "
                                    "to BE PROHIBITED from use in the "
                                    "analysis.")

    checkers_opts.add_argument('--enable-all',
                               dest="enable_all",
                               action='store_true',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="Force the running analyzers to use "
                                    "almost every checker available. The "
                                    "checker groups 'alpha.', 'debug.' and "
                                    "'osx.' (on Linux) are NOT enabled "
                                    "automatically and must be EXPLICITLY "
                                    "specified. WARNING! Enabling all "
                                    "checkers might result in the analysis "
                                    "losing precision and stability, and "
                                    "could even result in a total failure of "
                                    "the analysis. USE WISELY AND AT YOUR "
                                    "OWN RISK!")

    logger.add_verbose_arguments(parser)
    parser.set_defaults(func=main)
Exemple #5
0
def add_arguments_to_parser(parser):
    """
    Add the subcommand's arguments to the given argparse.ArgumentParser.
    """

    parser.add_argument('logfile',
                        type=str,
                        nargs='+',
                        help="Path to the JSON compilation command database "
                        "files which were created during the build. "
                        "The analyzers will check only the files "
                        "registered in these build databases.")

    parser.add_argument('-j',
                        '--jobs',
                        type=int,
                        dest="jobs",
                        required=False,
                        default=1,
                        help="Number of threads to use in analysis. More "
                        "threads mean faster analysis at the cost of "
                        "using more memory.")

    parser.add_argument('-i',
                        '--ignore',
                        '--skip',
                        dest="skipfile",
                        required=False,
                        default=argparse.SUPPRESS,
                        help="Path to the Skipfile dictating which project "
                        "files should be omitted from analysis. Please "
                        "consult the User guide on how a Skipfile "
                        "should be laid out.")

    parser.add_argument('-o',
                        '--output',
                        dest="output_path",
                        required=True,
                        default=argparse.SUPPRESS,
                        help="Store the analysis output in the given folder.")

    parser.add_argument('-t',
                        '--type',
                        '--output-format',
                        dest="output_format",
                        required=False,
                        choices=['plist'],
                        default='plist',
                        help="Specify the format the analysis results should "
                        "use.")

    parser.add_argument('-q',
                        '--quiet',
                        dest="quiet",
                        action='store_true',
                        default=argparse.SUPPRESS,
                        required=False,
                        help="Do not print the output or error of the "
                        "analyzers to the standard output of "
                        "CodeChecker.")

    parser.add_argument('-c',
                        '--clean',
                        dest="clean",
                        required=False,
                        action='store_true',
                        default=argparse.SUPPRESS,
                        help="Delete analysis reports stored in the output "
                        "directory. (By default, CodeChecker would keep "
                        "reports and overwrites only those files that "
                        "were update by the current build command).")

    parser.add_argument('--report-hash',
                        dest="report_hash",
                        default=argparse.SUPPRESS,
                        required=False,
                        choices=['context-free'],
                        help="EXPERIMENTAL feature. "
                        "Specify the hash calculation method for "
                        "reports. If this option is not set, the default "
                        "calculation method for Clang Static Analyzer "
                        "will be context sensitive and for Clang Tidy it "
                        "will be context insensitive. If this option is "
                        "set to 'context-free' bugs will be identified "
                        "with the CodeChecker generated context free "
                        "hash for every analyzers. USE WISELY AND AT "
                        "YOUR OWN RISK!")

    parser.add_argument('-n',
                        '--name',
                        dest="name",
                        required=False,
                        default=argparse.SUPPRESS,
                        help="Annotate the run analysis with a custom name in "
                        "the created metadata file.")

    analyzer_opts = parser.add_argument_group("analyzer arguments")

    analyzer_opts.add_argument(
        '--analyzers',
        nargs='+',
        dest='analyzers',
        metavar='ANALYZER',
        required=False,
        choices=analyzer_types.supported_analyzers,
        default=argparse.SUPPRESS,
        help="Run analysis only with the analyzers "
        "specified. Currently supported analyzers "
        "are: " + ', '.join(analyzer_types.supported_analyzers) + ".")

    analyzer_opts.add_argument('--add-compiler-defaults',
                               action='store_true',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="DEPRECATED. Always True. Retrieve "
                               "compiler-specific configuration "
                               "from the compilers themselves, and use "
                               "them with Clang. This is used when the "
                               "compiler on the system is special, e.g. "
                               "when doing cross-compilation.")

    analyzer_opts.add_argument('--capture-analysis-output',
                               dest='capture_analysis_output',
                               action='store_true',
                               default=argparse.SUPPRESS,
                               required=False,
                               help="Store standard output and standard error "
                               "of successful analyzer invocations "
                               "into the '<OUTPUT_DIR>/success' "
                               "directory.")

    analyzer_opts.add_argument('--saargs',
                               dest="clangsa_args_cfg_file",
                               required=False,
                               default=argparse.SUPPRESS,
                               help="File containing argument which will be "
                               "forwarded verbatim for the Clang Static "
                               "Analyzer.")

    analyzer_opts.add_argument('--tidyargs',
                               dest="tidy_args_cfg_file",
                               required=False,
                               default=argparse.SUPPRESS,
                               help="File containing argument which will be "
                               "forwarded verbatim for Clang-Tidy.")

    analyzer_opts.add_argument('--tidy-config',
                               dest='tidy_config',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="A file in YAML format containing the "
                               "configuration of clang-tidy checkers. "
                               "The file can be dumped by "
                               "'CodeChecker analyzers --dump-config "
                               "clang-tidy' command.")

    analyzer_opts.add_argument('--timeout',
                               type=int,
                               dest='timeout',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="The amount of time (in seconds) that "
                               "each analyzer can spend, individually, "
                               "to analyze the project. If the analysis "
                               "of a particular file takes longer than "
                               "this time, the analyzer is killed and "
                               "the analysis is considered as a failed "
                               "one.")

    context = analyzer_context.get_context()
    if analyzer_types.is_ctu_capable(context):
        ctu_opts = parser.add_argument_group(
            "cross translation unit analysis arguments", """
These arguments are only available if the Clang Static Analyzer supports
Cross-TU analysis. By default, no CTU analysis is run when
'CodeChecker analyze' is called.""")

        ctu_modes = ctu_opts.add_mutually_exclusive_group()
        ctu_modes.add_argument('--ctu',
                               '--ctu-all',
                               action='store_const',
                               const=[True, True],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform Cross Translation Unit (CTU) "
                               "analysis, both 'collect' and 'analyze' "
                               "phases. In this mode, the extra files "
                               "created by 'collect' are cleaned up "
                               "after the analysis.")

        ctu_modes.add_argument('--ctu-collect',
                               action='store_const',
                               const=[True, False],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform the first, 'collect' phase of "
                               "Cross-TU analysis. This phase generates "
                               "extra files needed by CTU analysis, and "
                               "puts them into '<OUTPUT_DIR>/ctu-dir'. "
                               "NOTE: If this argument is present, "
                               "CodeChecker will NOT execute the "
                               "analyzers!")

        ctu_modes.add_argument('--ctu-analyze',
                               action='store_const',
                               const=[False, True],
                               dest='ctu_phases',
                               default=argparse.SUPPRESS,
                               help="Perform the second, 'analyze' phase of "
                               "Cross-TU analysis, using already "
                               "available extra files in "
                               "'<OUTPUT_DIR>/ctu-dir'. (These files "
                               "will not be cleaned up in this mode.)")

        ctu_opts.add_argument('--ctu-reanalyze-on-failure',
                              action='store_true',
                              dest='ctu_reanalyze_on_failure',
                              default=argparse.SUPPRESS,
                              help="If Cross-TU analysis is enabled and fails "
                              "for some reason, try to re analyze the "
                              "same translation unit without "
                              "Cross-TU enabled.")

    if analyzer_types.is_statistics_capable(context):
        stat_opts = parser.add_argument_group(
            "EXPERIMENTAL statistics analysis feature arguments", """
These arguments are only available if the Clang Static Analyzer supports
Statistics-based analysis (e.g. statisticsCollector.ReturnValueCheck,
statisticsCollector.SpecialReturnValue checkers are available).""")

        stat_opts.add_argument('--stats-collect',
                               '--stats-collect',
                               action='store',
                               default=argparse.SUPPRESS,
                               dest='stats_output',
                               help="EXPERIMENTAL feature. "
                               "Perform the first, 'collect' phase of "
                               "Statistical analysis. This phase "
                               "generates extra files needed by "
                               "statistics analysis, and "
                               "puts them into "
                               "'<STATS_OUTPUT>'."
                               " NOTE: If this argument is present, "
                               "CodeChecker will NOT execute the "
                               "analyzers!")

        stat_opts.add_argument('--stats-use',
                               '--stats-use',
                               action='store',
                               default=argparse.SUPPRESS,
                               dest='stats_dir',
                               help="EXPERIMENTAL feature. "
                               "Use the previously generated statistics "
                               "results for the analysis from the given "
                               "'<STATS_DIR>'.")

        stat_opts.add_argument('--stats',
                               action='store_true',
                               default=argparse.SUPPRESS,
                               dest='stats_enabled',
                               help="EXPERIMENTAL feature. "
                               "Perform both phases of "
                               "Statistical analysis. This phase "
                               "generates extra files needed by "
                               "statistics analysis and enables "
                               "the statistical checkers. "
                               "No need to enable them explicitly.")

        stat_opts.add_argument('--stats-min-sample-count',
                               action='store',
                               default="10",
                               type=int,
                               dest='stats_min_sample_count',
                               help="EXPERIMENTAL feature. "
                               "Minimum number of samples (function call"
                               " occurrences) to be collected"
                               " for a statistics to be relevant "
                               "'<MIN-SAMPLE-COUNT>'.")

        stat_opts.add_argument('--stats-relevance-threshold',
                               action='store',
                               default="0.85",
                               type=float,
                               dest='stats_relevance_threshold',
                               help="EXPERIMENTAL feature. "
                               "The minimum ratio of calls of function "
                               "f that must have a certain property "
                               "property to consider it true for that "
                               "function (calculated as calls "
                               "with a property/all calls)."
                               " CodeChecker will warn for"
                               " calls of f do not have that property."
                               "'<RELEVANCE_THRESHOLD>'.")

    checkers_opts = parser.add_argument_group(
        "checker configuration", """
Checkers
------------------------------------------------
The analyzer performs checks that are categorized into families or "checkers".
See 'CodeChecker checkers' for the list of available checkers. You can
fine-tune which checkers to use in the analysis by setting the enabled and
disabled flags starting from the bigger groups and going inwards, e.g.
'-e core -d core.uninitialized -e core.uninitialized.Assign' will enable every
'core' checker, but only 'core.uninitialized.Assign' from the
'core.uninitialized' group. Please consult the manual for details. Disabling
certain checkers - such as the 'core' group - is unsupported by the LLVM/Clang
community, and thus discouraged.

Compiler warnings
------------------------------------------------
Compiler warnings are diagnostic messages that report constructions that are
not inherently erroneous but that are risky or suggest there may have been an
error. Compiler warnings are named 'clang-diagnostic-<warning-option>', e.g.
Clang warning controlled by '-Wliteral-conversion' will be reported with check
name 'clang-diagnostic-literal-conversion'. You can fine-tune which warnings to
use in the analysis by setting the enabled and disabled flags starting from the
bigger groups and going inwards, e.g. '-e Wunused -d Wno-unused-parameter' will
enable every 'unused' warnings except 'unused-parameter'. These flags should
start with a capital 'W' or 'Wno-' prefix followed by the waning name (E.g.:
'-e Wliteral-conversion', '-d Wno-literal-conversion'). By default '-Wall' and
'-Wextra' warnings are enabled. For more information see:
https://clang.llvm.org/docs/DiagnosticsReference.html.""")

    checkers_opts.add_argument('-e',
                               '--enable',
                               dest="enable",
                               metavar='checker/group/profile',
                               default=argparse.SUPPRESS,
                               action=OrderedCheckersAction,
                               help="Set a checker (or checker group) "
                               "to BE USED in the analysis.")

    checkers_opts.add_argument('-d',
                               '--disable',
                               dest="disable",
                               metavar='checker/group/profile',
                               default=argparse.SUPPRESS,
                               action=OrderedCheckersAction,
                               help="Set a checker (or checker group) "
                               "to BE PROHIBITED from use in the "
                               "analysis.")

    checkers_opts.add_argument('--enable-all',
                               dest="enable_all",
                               action='store_true',
                               required=False,
                               default=argparse.SUPPRESS,
                               help="Force the running analyzers to use "
                               "almost every checker available. The "
                               "checker groups 'alpha.', 'debug.' and "
                               "'osx.' (on Linux) are NOT enabled "
                               "automatically and must be EXPLICITLY "
                               "specified. WARNING! Enabling all "
                               "checkers might result in the analysis "
                               "losing precision and stability, and "
                               "could even result in a total failure of "
                               "the analysis. USE WISELY AND AT YOUR "
                               "OWN RISK!")

    logger.add_verbose_arguments(parser)
    parser.set_defaults(func=main)