diff --git a/analyzer/codechecker_analyzer/cmd/analyze.py b/analyzer/codechecker_analyzer/cmd/analyze.py index 0429afee8f..b2d9af51ed 100644 --- a/analyzer/codechecker_analyzer/cmd/analyze.py +++ b/analyzer/codechecker_analyzer/cmd/analyze.py @@ -513,9 +513,10 @@ def add_arguments_to_parser(parser): action='store', dest='ctu_ast_mode', choices=['load-from-pch', 'parse-on-demand'], - default='parse-on-demand', + default=argparse.SUPPRESS, help="Choose the way ASTs are loaded during " - "CTU analysis. Mode 'load-from-pch' " + "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 " @@ -525,7 +526,8 @@ def add_arguments_to_parser(parser): "serialized ASTs, while mode " "'parse-on-demand' can incur some " "runtime CPU overhead in the second " - "phase of the analysis.") + "phase of the analysis. (default: " + "parse-on-demand)") if analyzer_types.is_statistics_capable(context): stat_opts = parser.add_argument_group( @@ -815,6 +817,11 @@ def main(args): """ logger.setup_logger(args.verbose if 'verbose' in args else None) + # CTU loading mode is only meaningful if CTU itself is enabled. + if 'ctu_ast_mode' in args and 'ctu_phases' not in args: + LOG.error("Analyzer option 'ctu-ast-mode' requires CTU mode enabled") + sys.exit(1) + try: cmd_config.check_config_file(args) except FileNotFoundError as fnerr: diff --git a/analyzer/codechecker_analyzer/cmd/check.py b/analyzer/codechecker_analyzer/cmd/check.py index b851fbf948..830ffd34ac 100644 --- a/analyzer/codechecker_analyzer/cmd/check.py +++ b/analyzer/codechecker_analyzer/cmd/check.py @@ -14,6 +14,7 @@ import argparse import os import shutil +import sys import tempfile from codechecker_analyzer import analyzer_context @@ -515,9 +516,10 @@ def add_arguments_to_parser(parser): action='store', dest='ctu_ast_mode', choices=['load-from-pch', 'parse-on-demand'], - default='parse-on-demand', + default=argparse.SUPPRESS, help="Choose the way ASTs are loaded during " - "CTU analysis. Mode 'load-from-pch' " + "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 " @@ -527,7 +529,8 @@ def add_arguments_to_parser(parser): "serialized ASTs, while mode " "'parse-on-demand' can incur some " "runtime CPU overhead in the second " - "phase of the analysis.") + "phase of the analysis. (default: " + "parse-on-demand)") if analyzer_types.is_statistics_capable(context): stat_opts = parser.add_argument_group( @@ -729,6 +732,10 @@ def main(args): logger.setup_logger(args.verbose if 'verbose' in args else None) + if 'ctu_ast_mode' in args and 'ctu_phases' not in args: + LOG.error("Analyzer option 'ctu-ast-mode' requires CTU mode enabled") + sys.exit(1) + def __update_if_key_exists(source, target, key): """Append the source Namespace's element with 'key' to target with the same key, but only if it exists.""" diff --git a/analyzer/tests/functional/ctu/test_ctu.py b/analyzer/tests/functional/ctu/test_ctu.py index 0899e1a107..43a17729e0 100644 --- a/analyzer/tests/functional/ctu/test_ctu.py +++ b/analyzer/tests/functional/ctu/test_ctu.py @@ -14,6 +14,7 @@ import shutil import unittest +from subprocess import run from typing import IO from libtest import env @@ -78,6 +79,16 @@ def tearDown(self): shutil.rmtree(self.report_dir, ignore_errors=True) os.chdir(self.__old_pwd) + @skipUnlessCTUCapable + def test_ctu_loading_mode_requires_ctu_mode(self): + """ Test ctu-ast-mode option requires ctu mode enabled. """ + cmd = [self._codechecker_cmd, 'analyze', '-o', self.report_dir, + '--analyzers', 'clangsa', '--ctu-ast-mode=load-from-pch', + self.buildlog] + + self.assertEqual(1, + run(cmd, cwd=self.test_dir, env=self.env).returncode) + @skipUnlessCTUCapable def test_ctu_all_ast_dump_based(self): """ Test full CTU AST-dump based analysis. """ diff --git a/docs/analyzer/user_guide.md b/docs/analyzer/user_guide.md index 215b94729f..0c2e1d62d1 100644 --- a/docs/analyzer/user_guide.md +++ b/docs/analyzer/user_guide.md @@ -302,16 +302,16 @@ cross translation unit analysis arguments: If Cross-TU analysis is enabled and fails for some reason, try to re analyze the same translation unit without Cross-TU enabled. - [--ctu-ast-mode {load-from-pch,parse-on-demand}] --ctu-ast-mode {load-from-pch,parse-on-demand} - Choose the way ASTs are loaded during CTU analysis. - 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) + 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) checker configuration: @@ -1441,16 +1441,16 @@ cross translation unit analysis arguments: analysis, using already available extra files in '/ctu-dir'. (These files will not be cleaned up in this mode.) - --ctu-ast-mode {load-from-pch,parse-on-demand} - Choose the way ASTs are loaded during CTU analysis. - 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) + 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) ``` ### Statistical analysis mode