Skip to content

Commit

Permalink
[cmd] Expand environment variables in config file
Browse files Browse the repository at this point in the history
Expand environment variables in the config file given by the
--config option.
  • Loading branch information
csordasmarton committed Jul 30, 2020
1 parent 0a7617b commit c3f6347
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 14 deletions.
6 changes: 5 additions & 1 deletion analyzer/codechecker_analyzer/cmd/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,13 @@ def add_arguments_to_parser(parser):
" \"--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.")

analyzer_opts.add_argument('--saargs',
dest="clangsa_args_cfg_file",
Expand Down
6 changes: 5 additions & 1 deletion analyzer/codechecker_analyzer/cmd/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,13 @@ def add_arguments_to_parser(parser):
" \"--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',
Expand Down
3 changes: 3 additions & 0 deletions bin/CodeChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def signal_handler(signum, frame):
if 'func_process_config_file' in args:
cfg_args = args.func_process_config_file(args)
if cfg_args:
# Expand environment variables in the arguments.
cfg_args = map(lambda cfg: os.path.expandvars(cfg), cfg_args)

sys.argv.extend(cfg_args)
args = parser.parse_args()

Expand Down
13 changes: 11 additions & 2 deletions docs/analyzer/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,12 @@ analyzer arguments:
"--enable=core.CallAndMessage",
"--report-hash=context-free-v2",
"--verbose=debug",
"--skip=$HOME/project/skip.txt",
"--clean"
]
} (default: None)
}.
You can use any environment variable inside this file
and it will be expaneded. (default: None)
--saargs CLANGSA_ARGS_CFG_FILE
File containing argument which will be forwarded
verbatim for the Clang Static analyzer.
Expand Down Expand Up @@ -881,9 +884,12 @@ analyzer arguments:
"--enable=core.CallAndMessage",
"--report-hash=context-free-v2",
"--verbose=debug",
"--skip=$HOME/project/skip.txt",
"--clean"
]
} (default: None)
}.
You can use any environment variable inside this file
and it will be expaneded. (default: None)
--saargs CLANGSA_ARGS_CFG_FILE
File containing argument which will be forwarded
verbatim for the Clang Static Analyzer.
Expand Down Expand Up @@ -978,6 +984,9 @@ formats:
- Use separated values for option and parameter:
`{ "analyzer": [ "--verbose", "debug" ] }`

Note: environment variables inside this config file will be expanded:
`{ "analyzer": [ "--skip=$HOME/project/skip.txt" ] }`

#### Analyzer and checker config options <a name="analyzer-checker-config-option"></a>

CodeChecker's analyzer module currently handles ClangSA and ClangTidy. The main
Expand Down
11 changes: 6 additions & 5 deletions docs/web/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,13 @@ optional arguments:
config file will overwrite the values set in the
command line. The format of configuration file is:
{
"store": [
"--name=run_name",
"--tag=my_tag",
"--url=http://codechecker.my/MyProduct"
"server": [
"--workspace=$HOME/workspace",
"--port=9090"
]
}. (default: None)
}.
You can use any environment variable inside this file
and it will be expaneded. (default: None)
-f, --force 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,
Expand Down
7 changes: 4 additions & 3 deletions web/server/codechecker_server/cmd/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ def add_arguments_to_parser(parser):
"configuration file is: \n"
"{\n"
" \"server\": [\n"
" \"--workspace=/home/<username>/workspace\","
"\n"
" \"--workspace=$HOME/workspace\",\n"
" \"--port=9090\"\n"
" ]\n"
"}.")
"}.\n"
"You can use any environment variable inside "
"this file and it will be expaneded.")

dbmodes = parser.add_argument_group("configuration database arguments")

Expand Down
8 changes: 6 additions & 2 deletions web/tests/functional/cli_config/test_store_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,23 @@ def setUp(self):

def test_valid_config(self):
""" Store with a valid configuration file. """
cc_env = env.codechecker_env()
cc_env["CC_REPORT_DIR"] = self.codechecker_cfg['reportdir']

with open(self.config_file, 'w+',
encoding="utf-8", errors="ignore") as config_f:
json.dump({
'store': [
'--name=' + 'store_config',
'--trim-path-prefix=$HOME',
'--url=' + env.parts_to_url(self.codechecker_cfg),
self.codechecker_cfg['reportdir']]}, config_f)
'$CC_REPORT_DIR']}, config_f)

store_cmd = [env.codechecker_cmd(), 'store', '--config',
self.config_file]

subprocess.check_output(
store_cmd, encoding="utf-8", errors="ignore")
store_cmd, env=cc_env, encoding="utf-8", errors="ignore")

def test_invalid_config(self):
""" Store with an invalid configuration file. """
Expand Down

0 comments on commit c3f6347

Please sign in to comment.