From 868183cdb05d60d636c9cc2ab84ac10b6b9e05c4 Mon Sep 17 00:00:00 2001 From: Tom Ritter Date: Thu, 2 Jan 2025 16:12:00 -0500 Subject: [PATCH] Add a mode where CTU files are retained --- analyzer/codechecker_analyzer/analyzer.py | 8 +++++--- analyzer/codechecker_analyzer/cmd/analyze.py | 16 +++++++++++++--- docs/analyzer/user_guide.md | 12 ++++++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/analyzer/codechecker_analyzer/analyzer.py b/analyzer/codechecker_analyzer/analyzer.py index b788461e9f..bc5930f427 100644 --- a/analyzer/codechecker_analyzer/analyzer.py +++ b/analyzer/codechecker_analyzer/analyzer.py @@ -148,6 +148,7 @@ def perform_analysis(args, skip_handlers, filter_handlers, ctu_collect = False ctu_analyze = False + ctu_delete = False ctu_dir = '' if 'ctu_phases' in args: ctu_dir = os.path.join(args.output_path, 'ctu-dir') @@ -157,6 +158,7 @@ def perform_analysis(args, skip_handlers, filter_handlers, return ctu_collect = args.ctu_phases[0] ctu_analyze = args.ctu_phases[1] + ctu_delete = args.ctu_phases[2] if 'stats_enabled' in args and args.stats_enabled: if ClangSA.ANALYZER_NAME not in analyzers: @@ -271,9 +273,9 @@ def perform_analysis(args, skip_handlers, filter_handlers, makefile_creator.create(actions) return - if ctu_collect: + if ctu_delete: shutil.rmtree(ctu_dir, ignore_errors=True) - elif ctu_analyze and not os.path.exists(ctu_dir): + elif not ctu_collect and ctu_analyze and not os.path.exists(ctu_dir): LOG.error("CTU directory: '%s' does not exist.", ctu_dir) return @@ -363,7 +365,7 @@ def perform_analysis(args, skip_handlers, filter_handlers, metadata_tool['timestamps'] = {'begin': start_time, 'end': end_time} - if ctu_collect and ctu_analyze: + if ctu_delete: shutil.rmtree(ctu_dir, ignore_errors=True) manager.shutdown() diff --git a/analyzer/codechecker_analyzer/cmd/analyze.py b/analyzer/codechecker_analyzer/cmd/analyze.py index a2d78c9a01..e2bed4ac78 100644 --- a/analyzer/codechecker_analyzer/cmd/analyze.py +++ b/analyzer/codechecker_analyzer/cmd/analyze.py @@ -537,7 +537,7 @@ def add_arguments_to_parser(parser): ctu_modes = ctu_opts.add_mutually_exclusive_group() ctu_modes.add_argument('--ctu', '--ctu-all', action='store_const', - const=[True, True], + const=[True, True, True], dest='ctu_phases', default=argparse.SUPPRESS, help="Perform Cross Translation Unit (CTU) " @@ -545,10 +545,20 @@ def add_arguments_to_parser(parser): "phases. In this mode, the extra files " "created by 'collect' are cleaned up " "after the analysis.") + ctu_modes.add_argument('--ctu-retain', + action='store_const', + const=[True, True, False], + 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 NOT cleaned up " + "after the analysis.") ctu_modes.add_argument('--ctu-collect', action='store_const', - const=[True, False], + const=[True, False, False], dest='ctu_phases', default=argparse.SUPPRESS, help="Perform the first, 'collect' phase of " @@ -561,7 +571,7 @@ def add_arguments_to_parser(parser): ctu_modes.add_argument('--ctu-analyze', action='store_const', - const=[False, True], + const=[False, True, True], dest='ctu_phases', default=argparse.SUPPRESS, help="Perform the second, 'analyze' phase of " diff --git a/docs/analyzer/user_guide.md b/docs/analyzer/user_guide.md index d9684c8840..127e33a731 100644 --- a/docs/analyzer/user_guide.md +++ b/docs/analyzer/user_guide.md @@ -145,7 +145,7 @@ usage: CodeChecker check [-h] [-o OUTPUT_DIR] [-t {plist}] [-q] [--analyzer-config [ANALYZER_CONFIG [ANALYZER_CONFIG ...]]] [--checker-config [CHECKER_CONFIG [CHECKER_CONFIG ...]]] [--timeout TIMEOUT] - [--ctu | --ctu-collect | --ctu-analyze] + [--ctu | --ctu-retain | --ctu-collect | --ctu-analyze] [--ctu-reanalyze-on-failure] [--ctu-ast-mode {load-from-pch,parse-on-demand}] [-e checker/group/profile] [-d checker/group/profile] @@ -333,6 +333,10 @@ cross translation unit analysis arguments: 'collect' and 'analyze' phases. In this mode, the extra files created by 'collect' are cleaned up after the analysis. + --ctu-retain Perform Cross Translation Unit (CTU) analysis, both + 'collect' and 'analyze' phases. After doing so, the + extra files created by 'collect' are retained after + the analysis and not removed. --ctu-collect Perform the first, 'collect' phase of Cross-TU analysis. This phase generates extra files needed by CTU analysis, and puts them into '/ctu- @@ -993,7 +997,7 @@ usage: CodeChecker analyze [-h] [-j JOBS] [--saargs CLANGSA_ARGS_CFG_FILE] [--tidyargs TIDY_ARGS_CFG_FILE] [--timeout TIMEOUT] - [--ctu | --ctu-collect | --ctu-analyze] + [--ctu | --ctu-retain | --ctu-collect | --ctu-analyze] [--ctu-ast-mode {load-from-pch, parse-on-demand}] [--ctu-reanalyze-on-failure] [-e checker/group/profile] @@ -1650,6 +1654,10 @@ cross translation unit analysis arguments: 'collect' and 'analyze' phases. In this mode, the extra files created by 'collect' are cleaned up after the analysis. + --ctu-retain Perform Cross Translation Unit (CTU) analysis, both + 'collect' and 'analyze' phases. After doing so, the + extra files created by 'collect' are retained after + the analysis and not removed. --ctu-collect Perform the first, 'collect' phase of Cross-TU analysis. This phase generates extra files needed by CTU analysis, and puts them into '/ctu-