Skip to content

Commit c15abc8

Browse files
authored
Merge pull request #4645 from barnabasdomozi/config_directory_rework
Rework config_directory
2 parents 9d01ee0 + ce73536 commit c15abc8

8 files changed

Lines changed: 62 additions & 93 deletions

File tree

docs/web/products.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ database arguments:
158158
is the server which will make the database connection.
159159
160160
--sqlite SQLITE_FILE Path of the SQLite database file to use. All paths will
161-
be relative to the server's <CONFIG_DIRECTORY>. If an
161+
be relative to the server's <WORKSPACE_DIRECTORY>. If an
162162
SQLite server needs to have a different directory, use
163163
symlinks inside the config directory.
164164
(default: <ENDOPINT>.sqlite)

docs/web/user_guide.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ optional arguments:
164164
-h, --help show this help message and exit
165165
-w WORKSPACE, --workspace WORKSPACE
166166
Directory where CodeChecker can store analysis result
167-
related data, such as the database. (Cannot be
168-
specified at the same time with '--sqlite' or
169-
'--config-directory'.) (default:
167+
related data, such as the database. (default:
170168
/home/<username>/.codechecker)
171169
-f CONFIG_DIRECTORY, --config-directory CONFIG_DIRECTORY
172170
Directory where CodeChecker server should read server-
@@ -215,7 +213,7 @@ optional arguments:
215213
216214
configuration database arguments:
217215
--sqlite SQLITE_FILE Path of the SQLite database file to use. (default:
218-
<CONFIG_DIRECTORY>/config.sqlite)
216+
<WORKSPACE_DIRECTORY>/config.sqlite)
219217
--postgresql Specifies that a PostgreSQL database is to be used
220218
instead of SQLite. See the "PostgreSQL arguments"
221219
section on how to configure the database connection.

web/client/codechecker_client/cli/cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ def __register_add(parser):
779779
required=False,
780780
help="Path of the SQLite database file to use. "
781781
"All paths will be relative to the server's "
782-
"<CONFIG_DIRECTORY>. If an SQLite server "
782+
"<WORKSPACE_DIRECTORY>. If an SQLite server "
783783
"needs to have a different directory, use "
784784
"symlinks inside the config directory.")
785785

web/server/codechecker_server/api/product_server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def getProductConfiguration(self, product_id):
294294
# Strip the config directory from the path, to allow for
295295
# easier editing
296296
config_dir = \
297-
os.path.normpath(self.__server.config_directory) + "/"
297+
os.path.normpath(self.__server.workspace_directory) + "/"
298298
if args['sqlite'].startswith(config_dir):
299299
db_name = args['sqlite'][len(config_dir):]
300300
else:
@@ -428,8 +428,8 @@ def addProduct(self, product):
428428
codechecker_api_shared.ttypes.ErrorCode.DATABASE,
429429
"SQLite database must be given by relative path!")
430430

431-
dbc.database = path_for_fake_root(os.path.join("/", dbc.database),
432-
self.__server.config_directory)
431+
dbc.database = path_for_fake_root(os.path.join(
432+
"/", dbc.database), self.__server.workspace_directory)
433433

434434
# Check if the database is already in use by another product.
435435
db_in_use = self.__server.is_database_used(product)
@@ -610,7 +610,7 @@ def editProduct(self, product_id, new_config):
610610
"SQLite database must be given by relative path!")
611611
dbc.database = path_for_fake_root(
612612
os.path.join("/", dbc.database),
613-
self.__server.config_directory)
613+
self.__server.workspace_directory)
614614

615615
# Some values come encoded as Base64, decode these.
616616
displayed_name = convert.from_b64(new_config.displayedName_b64) \

web/server/codechecker_server/cli/server.py

Lines changed: 32 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,11 @@ def add_arguments_to_parser(parser):
8585
default=default_workspace,
8686
required=False,
8787
help="Directory where CodeChecker can store analysis "
88-
"result related data, such as the database. "
89-
"(Cannot be specified at the same time with "
90-
"'--sqlite' or '--config-directory'.)")
88+
"result related data, such as the database.")
9189

9290
parser.add_argument('-f', '--config-directory',
9391
type=str,
9492
dest="config_directory",
95-
default=default_workspace,
9693
required=False,
9794
help="Directory where CodeChecker server should read "
9895
"server-specific configuration (such as "
@@ -169,9 +166,6 @@ def add_arguments_to_parser(parser):
169166
type=str,
170167
dest="sqlite",
171168
metavar='SQLITE_FILE',
172-
default=os.path.join(
173-
'<CONFIG_DIRECTORY>',
174-
"config.sqlite"),
175169
required=False,
176170
help="Path of the SQLite database file to use.")
177171

@@ -373,54 +367,24 @@ def arg_match(options):
373367
# is intended later on.
374368
delattr(args, 'not_host_only')
375369

376-
# --workspace and --sqlite cannot be specified either, as
377-
# both point to a database location.
378-
options = ['--sqlite', '--workspace']
379-
options_short = ['--sqlite', '-w']
380-
if set(arg_match(options)) == set(options) or \
381-
set(arg_match(options_short)) == set(options_short):
382-
parser.error("argument --sqlite: not allowed with "
383-
"argument --workspace")
384-
385-
# --workspace and --config-directory also aren't allowed together now,
386-
# the latter one is expected to replace the earlier.
387-
options = ['--config-directory', '--workspace']
388-
options_short = ['--config-directory', '-w']
389-
if set(arg_match(options)) == set(options) or \
390-
set(arg_match(options_short)) == set(options_short):
391-
parser.error("argument --config-directory: not allowed with "
392-
"argument --workspace")
393-
394-
# If workspace is specified, sqlite is workspace/config.sqlite
395-
# and config_directory is the workspace directory.
396-
if arg_match(['--workspace', '-w']):
370+
# If config_directory is not specified, it will be the same
371+
# as the workspace directory.
372+
if not args.config_directory:
397373
args.config_directory = args.workspace
374+
375+
# If sqlite path is not specified, it will be set to
376+
# workspace/config.sqlite
377+
if not args.sqlite:
398378
args.sqlite = os.path.join(args.workspace,
399379
'config.sqlite')
400-
setattr(args, 'dbdatadir', os.path.join(args.workspace,
401-
'pgsql_data'))
402-
403-
# Workspace should not exist as a Namespace key.
404-
delattr(args, 'workspace')
405-
406-
if '<CONFIG_DIRECTORY>' in args.sqlite:
407-
# Replace the placeholder variable with the actual value.
408-
args.sqlite = args.sqlite.replace('<CONFIG_DIRECTORY>',
409-
args.config_directory)
410380

411381
# Convert relative sqlite file path to absolute.
412-
if 'sqlite' in args:
413-
args.sqlite = os.path.abspath(args.sqlite)
382+
args.sqlite = os.path.abspath(args.sqlite)
414383

415384
if 'postgresql' not in args:
416385
# Later called database modules need the argument to be actually
417386
# present, even though the default is suppressed in the optstring.
418387
setattr(args, 'postgresql', False)
419-
420-
# This is not needed by the database starter as we are
421-
# running SQLite.
422-
if 'dbdatadir' in args:
423-
delattr(args, 'dbdatadir')
424388
else:
425389
# If --postgresql is given, --sqlite is useless.
426390
delattr(args, 'sqlite')
@@ -429,6 +393,10 @@ def arg_match(options):
429393
if "list" in args or "stop" in args or "stop_all" in args:
430394
setattr(args, "instance_manager", True)
431395

396+
# Log directories
397+
LOG.info(f"Workspace directory: {args.workspace}")
398+
LOG.info(f"Config directory: {args.config_directory}")
399+
432400
# If everything is fine, do call the handler for the subcommand.
433401
return main(args)
434402

@@ -808,7 +776,7 @@ def __instance_management(args):
808776
if 'stop' in args and \
809777
not (i['port'] == args.view_port and
810778
os.path.abspath(i['workspace']) ==
811-
os.path.abspath(args.config_directory)):
779+
os.path.abspath(args.workspace)):
812780
continue
813781

814782
try:
@@ -836,7 +804,7 @@ def __reload_config(args):
836804
if 'reload' in args and \
837805
not (i['port'] == args.view_port and
838806
os.path.abspath(i['workspace']) ==
839-
os.path.abspath(args.config_directory)):
807+
os.path.abspath(args.workspace)):
840808
continue
841809

842810
try:
@@ -890,13 +858,6 @@ def server_init_start(args):
890858
if not host_check.check_zlib():
891859
raise ModuleNotFoundError("zlib is not available on the system!")
892860

893-
# WARNING
894-
# In case of SQLite args.dbaddress default value is used
895-
# for which the is_localhost should return true.
896-
if is_localhost(args.dbaddress) and \
897-
not os.path.exists(args.config_directory):
898-
os.makedirs(args.config_directory)
899-
900861
# Make sure the SQLite file can be created if it not exists.
901862
if 'sqlite' in args and \
902863
not os.path.isdir(os.path.dirname(args.sqlite)):
@@ -907,7 +868,7 @@ def server_init_start(args):
907868
"option. The server will ask for users to authenticate!")
908869

909870
context = webserver_context.get_context()
910-
context.codechecker_workspace = args.config_directory
871+
context.codechecker_workspace = args.workspace
911872
context.db_username = args.dbusername
912873

913874
environ = env.extend(context.path_env_extra,
@@ -993,8 +954,8 @@ def server_init_start(args):
993954

994955
# Create the main database link from the arguments passed over the
995956
# command line.
996-
cfg_dir = os.path.abspath(args.config_directory)
997-
default_product_path = os.path.join(cfg_dir, 'Default.sqlite')
957+
workspace_dir = os.path.abspath(args.workspace)
958+
default_product_path = os.path.join(workspace_dir, 'Default.sqlite')
998959
create_default_product = 'sqlite' in args and \
999960
not os.path.exists(default_product_path)
1000961

@@ -1073,6 +1034,7 @@ def server_init_start(args):
10731034

10741035
try:
10751036
return server.start_server(args.config_directory,
1037+
args.workspace,
10761038
package_data,
10771039
args.view_port,
10781040
cfg_sql_server,
@@ -1098,17 +1060,21 @@ def main(args):
10981060
Setup a logger server based on the configuration and
10991061
manage the CodeChecker server.
11001062
"""
1101-
workspace = (
1102-
args.config_directory
1103-
if "config_directory" in args and not hasattr(args, "instance_manager")
1104-
else None
1105-
)
11061063

11071064
# Create workspace directory before logging is initialized.
1108-
if workspace and not os.path.exists(args.config_directory):
1109-
LOG.info("Creating non existing config directory: %s",
1110-
args.config_directory)
1111-
os.makedirs(args.config_directory)
1065+
workspace = None
1066+
if not hasattr(args, "instance_manager"):
1067+
workspace = args.workspace
1068+
1069+
if not os.path.exists(workspace):
1070+
LOG.info("Creating non existing workspace directory: %s",
1071+
workspace)
1072+
os.makedirs(workspace)
1073+
1074+
if not os.path.exists(args.config_directory):
1075+
LOG.info("Creating non existing config directory: %s",
1076+
args.config_directory)
1077+
os.makedirs(args.config_directory)
11121078

11131079
with logger.LogCfgServer(
11141080
args.verbose if "verbose" in args else None, workspace=workspace

web/server/codechecker_server/server.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ def __init__(self,
802802
server_address,
803803
RequestHandlerClass,
804804
config_directory,
805+
workspace_directory,
805806
product_db_sql_server,
806807
pckg_data,
807808
context,
@@ -814,6 +815,7 @@ def __init__(self,
814815
LOG.debug("Initializing HTTP server...")
815816

816817
self.config_directory = config_directory
818+
self.workspace_directory = workspace_directory
817819
self.www_root = pckg_data['www_root']
818820
self.doc_root = pckg_data['doc_root']
819821
self.version = pckg_data['version']
@@ -1147,10 +1149,11 @@ def formatted_address(self) -> str:
11471149
return f"[{str(self.address)}]:{self.port}"
11481150

11491151

1150-
def start_server(config_directory: str, package_data, port: int,
1151-
config_sql_server, listen_address: str,
1152-
force_auth: bool, skip_db_cleanup: bool,
1153-
context, check_env, machine_id: str) -> int:
1152+
def start_server(config_directory: str, workspace_directory: str,
1153+
package_data, port: int, config_sql_server,
1154+
listen_address: str, force_auth: bool,
1155+
skip_db_cleanup: bool, context, check_env,
1156+
machine_id: str) -> int:
11541157
"""
11551158
Starts the HTTP server to handle Web client and Thrift requests, execute
11561159
background jobs.
@@ -1260,6 +1263,7 @@ def _cleanup_incomplete_tasks(action: str) -> int:
12601263
http_server = server_clazz((listen_address, port),
12611264
RequestHandler,
12621265
config_directory,
1266+
workspace_directory,
12631267
config_sql_server,
12641268
package_data,
12651269
context,

web/tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ SHUTDOWN_GLOBAL_SERVERS_CMD = \
6262
echo "Shutting down server..."; \
6363
HOME="$${TEST_ROOT}" ${CODECHECKER_CMD} server -l; \
6464
HOME="$${TEST_ROOT}" ${CODECHECKER_CMD} server \
65-
--config-directory $${TEST_ROOT} \
65+
--workspace $${TEST_ROOT} \
6666
--port `cat "$${TEST_ROOT}/serverport"` --stop; \
6767
rm -f "$${TEST_ROOT}/serverport"; \
6868
HOME="$${TEST_ROOT}" ${CODECHECKER_CMD} server -l; \

web/tests/libtest/codechecker.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,10 @@ def store(codechecker_cfg, test_project_name):
554554
return oserr.errno
555555

556556

557-
def serv_cmd(config_dir, port, pg_config=None, serv_args=None):
557+
def serv_cmd(workspace_dir, port, pg_config=None, serv_args=None):
558558

559559
server_cmd = ['CodeChecker', 'server',
560-
'--config-directory', config_dir]
560+
'--workspace', workspace_dir]
561561

562562
server_cmd.extend(['--host', 'localhost',
563563
'--port', str(port)])
@@ -570,7 +570,8 @@ def serv_cmd(config_dir, port, pg_config=None, serv_args=None):
570570
server_cmd.append('--postgresql')
571571
server_cmd += _pg_db_config_to_cmdline_params(pg_config)
572572
else:
573-
server_cmd += ['--sqlite', os.path.join(config_dir, 'config.sqlite')]
573+
server_cmd += ['--sqlite', os.path.join(workspace_dir,
574+
'config.sqlite')]
574575

575576
print(' '.join(server_cmd))
576577

@@ -586,11 +587,11 @@ def start_or_get_server(auth_required=False):
586587
server_type = 'global_auth_server' if auth_required else \
587588
'global_simple_server'
588589

589-
config_dir = os.path.join(workspace_root, server_type)
590-
if not os.path.exists(config_dir):
591-
os.makedirs(config_dir)
590+
workspace_dir = os.path.join(workspace_root, server_type)
591+
if not os.path.exists(workspace_dir):
592+
os.makedirs(workspace_dir)
592593

593-
portfile = os.path.join(config_dir, 'serverport')
594+
portfile = os.path.join(workspace_dir, 'serverport')
594595

595596
if os.path.exists(portfile):
596597
print("A server appears to be already running...")
@@ -599,21 +600,21 @@ def start_or_get_server(auth_required=False):
599600
else:
600601
if auth_required:
601602
# Set up the root user and the authentication for the server.
602-
env.enable_auth(config_dir)
603+
env.enable_auth(workspace_dir)
603604

604605
port = env.get_free_port()
605-
print("Setting up CodeChecker server in " + config_dir + " :" +
606+
print("Setting up CodeChecker server in " + workspace_dir + " :" +
606607
str(port))
607608

608609
with open(portfile, 'w', encoding="utf-8", errors="ignore") as f:
609610
f.write(str(port))
610611

611612
pg_config = env.get_postgresql_cfg()
612613

613-
server_cmd = serv_cmd(config_dir, port, pg_config)
614+
server_cmd = serv_cmd(workspace_dir, port, pg_config)
614615

615616
print("Starting server...")
616-
server_stdout = os.path.join(config_dir,
617+
server_stdout = os.path.join(workspace_dir,
617618
str(os.getpid()) + ".out")
618619

619620
with open(server_stdout, "w",
@@ -622,7 +623,7 @@ def start_or_get_server(auth_required=False):
622623
server_cmd,
623624
stdout=server_out,
624625
stderr=server_out,
625-
env=env.test_env(config_dir),
626+
env=env.test_env(workspace_dir),
626627
encoding="utf-8",
627628
errors="ignore")
628629

0 commit comments

Comments
 (0)