forked from Ericsson/codechecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[analyzer] config file option for the parse subcommand
Add support to use a config file by the parse subcommand. The subcommand arguments can be saved and used from the CodeChecker config file. Common config file checking and parsing parts were moved to the codechecker_common module because the analyzer and the server parts use the same code. The config file 'analyze' command related config key was 'analyzer' to keep it in sync with the subcommands it is renamed to 'analyze' in the documentation and examples. The code was made backward compatible to accept both cases and give a warning if both sections are available in the configuration file. The subocommand configuration examples were updated and extended.
- Loading branch information
Gyorgy Orban
committed
Aug 20, 2020
1 parent
5e5214f
commit 929ea81
Showing
10 changed files
with
251 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# ------------------------------------------------------------------------- | ||
# | ||
# Part of the CodeChecker project, under the Apache License v2.0 with | ||
# LLVM Exceptions. See LICENSE for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ------------------------------------------------------------------------- | ||
import os | ||
|
||
from codechecker_common.util import load_json_or_empty | ||
from codechecker_common import logger | ||
|
||
LOG = logger.get_logger('system') | ||
|
||
|
||
def process_config_file(args, subcommand_name): | ||
""" | ||
Handler to get config file options. | ||
""" | ||
if 'config_file' not in args: | ||
return {} | ||
if args.config_file and os.path.exists(args.config_file): | ||
cfg = load_json_or_empty(args.config_file, default={}) | ||
|
||
# The subcommand name is analyze but the | ||
# configuration section name is analyzer. | ||
if subcommand_name == 'analyze': | ||
# The config value can be 'analyze' or 'analyzer' | ||
# for backward compatibility. | ||
analyze_cfg = cfg.get("analyze", []) | ||
analyzer_cfg = cfg.get("analyzer", []) | ||
if analyze_cfg: | ||
if analyzer_cfg: | ||
LOG.warning("There is an 'analyze' and an 'analyzer' " | ||
"config configuration option in the config " | ||
"file. Please use the 'analyze' value to be " | ||
"in sync with the subcommands.\n" | ||
"Using the 'analyze' configuration.") | ||
return analyze_cfg | ||
if analyzer_cfg: | ||
return analyzer_cfg | ||
|
||
return cfg.get(subcommand_name, []) | ||
|
||
|
||
def check_config_file(args): | ||
"""Check if a config file is set in the arguments and if the file exists. | ||
returns - None if not set or the file exists or | ||
FileNotFoundError exception if the set config file is missing. | ||
""" | ||
if 'config_file' not in args: | ||
return | ||
|
||
if 'config_file' in args and args.config_file \ | ||
and not os.path.exists(args.config_file): | ||
raise FileNotFoundError( | ||
f"Configuration file '{args.config_file}' does not exist.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
{ | ||
"analyzer": [ | ||
"--enable", "core.DivideZero", | ||
"--enable", "core.CallAndMessage", | ||
"--disable", "alpha", | ||
"--analyzers", "clangsa", "clang-tidy", | ||
"--clean" | ||
] | ||
} | ||
"analyze": [ | ||
"--enable=core.DivideZero", | ||
"--enable=core.CallAndMessage", | ||
"--analyzer-config", | ||
"clangsa:unroll-loops=true", | ||
"--checker-config", | ||
"clang-tidy:google-readability-function-size.StatementThreshold=100" | ||
"--report-hash", "context-free-v2" | ||
"--verbose=debug", | ||
"--clean" | ||
], | ||
"parse": [ | ||
"--trim-path-prefix", | ||
"/$HOME/workspace" | ||
], | ||
"server": [ | ||
"--workspace=$HOME/workspace", | ||
"--port=9090" | ||
], | ||
"store": [ | ||
"--url", "localhost:9090/Default" | ||
] | ||
} |
Oops, something went wrong.