Skip to content

Commit

Permalink
Refactoring sub-command directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
csordasmarton committed Feb 28, 2019
1 parent d7a2a6f commit 0910e15
Show file tree
Hide file tree
Showing 23 changed files with 75 additions and 111 deletions.
14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,9 @@ package: clean_package build_dir gen-docs thrift userguide build_plist_to_html b
mkdir -p $(CC_BUILD_LIBCC_DIR) && \
mkdir -p $(CC_BUILD_LIB_DIR)/codechecker && \
cp -r $(ROOT)/libcodechecker/* $(CC_BUILD_LIBCC_DIR) && \
cp -r $(CC_ANALYZER)/cmd/* $(CC_BUILD_LIBCC_DIR)/libhandlers && \
cp -r $(CC_ANALYZER)/codechecker_analyzer $(CC_BUILD_LIB_DIR) && \
cp -r $(CC_WEB)/codechecker_web $(CC_BUILD_LIB_DIR) && \
cp -r $(CC_WEB)/cmd/* $(CC_BUILD_LIBCC_DIR)/libhandlers && \
cp -r $(CC_SERVER)/cmd/* $(CC_BUILD_LIBCC_DIR)/libhandlers && \
cp -r $(CC_SERVER)/codechecker_server $(CC_BUILD_LIB_DIR) && \
cp -r $(CC_CLIENT)/cmd/* $(CC_BUILD_LIBCC_DIR)/libhandlers && \
cp -r $(CC_CLIENT)/codechecker_client $(CC_BUILD_LIB_DIR)

# Copy sub-commands.
Expand All @@ -93,11 +89,11 @@ package: clean_package build_dir gen-docs thrift userguide build_plist_to_html b
./scripts/build/extend_version_file.py -r $(ROOT) -b $(BUILD_DIR) && \
mkdir -p $(CC_BUILD_DIR)/cc_bin && \
./scripts/build/create_commands.py -b $(BUILD_DIR) \
$(ROOT)/bin \
$(CC_WEB)/bin \
$(CC_SERVER)/bin \
$(CC_CLIENT)/bin \
$(CC_ANALYZER)/bin
$(ROOT)/bin:libcodechecker/cmd \
$(CC_WEB)/bin:codechecker_web/cmd \
$(CC_SERVER)/bin:codechecker_server/cmd \
$(CC_CLIENT)/bin:codechecker_client/cmd \
$(CC_ANALYZER)/bin:codechecker_analyzer/cmd

# Copy web client files.
mkdir -p $(CC_BUILD_WEB_DIR) && \
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from codechecker_analyzer.analyzers import analyzer_types

from libcodechecker import logger
from libcodechecker import libhandlers
from libcodechecker.util import RawDescriptionDefaultHelpFormatter

LOG = logger.get_logger('system')
Expand Down Expand Up @@ -484,16 +483,6 @@ def main(args):

logger.setup_logger(args.verbose if 'verbose' in args else None)

def __load_module(name):
"""Loads the given subcommand's definition from the libs."""
try:
module = libhandlers.load_module(name)
except ImportError:
LOG.error("Couldn't import subcommand '%s'", name)
raise

return module

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."""
Expand Down Expand Up @@ -532,7 +521,7 @@ def __update_if_key_exists(source, target, key):
__update_if_key_exists(args, log_args, 'quiet')
__update_if_key_exists(args, log_args, 'verbose')

log_module = __load_module('log')
import codechecker_analyzer.cmd.log as log_module
LOG.debug("Calling LOG with args:")
LOG.debug(log_args)

Expand Down Expand Up @@ -579,7 +568,7 @@ def __update_if_key_exists(source, target, key):
setattr(analyze_args, 'clean', True)
__update_if_key_exists(args, analyze_args, 'verbose')

analyze_module = __load_module('analyze')
import codechecker_analyzer.cmd.analyze as analyze_module
LOG.debug("Calling ANALYZE with args:")
LOG.debug(analyze_args)

Expand All @@ -594,7 +583,7 @@ def __update_if_key_exists(source, target, key):
__update_if_key_exists(args, parse_args, 'verbose')
__update_if_key_exists(args, parse_args, 'skipfile')

parse_module = __load_module('parse')
import codechecker_analyzer.cmd.parse as parse_module
LOG.debug("Calling PARSE with args:")
LOG.debug(parse_args)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion analyzer/tools/build-logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ This tool can capture the build process and generate a

To build the project execute
~~~~~~~
cd analyzer/tools/build-logger
make -f Makefile.manual
~~~~~~~

Expand Down
35 changes: 31 additions & 4 deletions bin/CodeChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,39 @@
from __future__ import absolute_import

import argparse
import imp
import json
import os
import signal
import sys

from libcodechecker import libhandlers

def add_subcommand(subparsers, sub_cmd, cmd_module_path):
"""
Load the subcommand module and then add the subcommand to the available
subcommands in the given subparsers collection.
subparsers has to be the return value of the add_parsers() method on an
argparse.ArgumentParser.
"""
m_path, m_name = os.path.split(cmd_module_path)
module_name = os.path.splitext(m_name)[0]

cc_bin = os.path.dirname(os.path.realpath(__file__))
full_module_path = os.path.join(cc_bin, '..', 'lib', 'python2.7', m_path)

# Load the module named as the argument.
cmd_file, cmd_path, cmd_descr = imp.find_module(module_name,
[full_module_path])
command_module = imp.load_module(module_name,
cmd_file, cmd_path, cmd_descr)

# Now that the module is loaded, construct an ArgumentParser for it.
sc_parser = subparsers.add_parser(
sub_cmd, **command_module.get_argparser_ctor_args())

# Run the method which adds the arguments to the subcommand's handler.
command_module.add_arguments_to_parser(sc_parser)


def main(subcommands=None):
Expand Down Expand Up @@ -76,12 +103,12 @@ def signal_handler(sig, frame):
if first_command in subcommands:

# Consider only the given command as an available one.
subcommands = [first_command]
subcommands = {first_command: subcommands[first_command]}

for subcommand in subcommands:

try:
libhandlers.add_subcommand(subparsers, str(subcommand))
add_subcommand(subparsers, subcommand,
subcommands[subcommand])
except (IOError, ImportError):
print("Couldn't import module for subcommand '" +
subcommand + "'... ignoring.")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def main(args):

has_analyzer_version = False
try:
from libcodechecker.libhandlers import analyzer_version
from codechecker_analyzer.cmd import analyzer_version
has_analyzer_version = True

# Print analyzer version information.
Expand All @@ -73,13 +73,13 @@ def main(args):
pass

try:
from libcodechecker.libhandlers import webserver_version
from codechecker_web.cmd import web_version

if has_analyzer_version:
print() # Print a new line to separate version information.

# Print web server version information.
print("CodeChecker web server version:")
webserver_version.print_version(output_format)
print("CodeChecker web version:")
web_version.print_version(output_format)
except Exception:
pass
64 changes: 0 additions & 64 deletions libcodechecker/libhandlers/__init__.py

This file was deleted.

23 changes: 15 additions & 8 deletions scripts/build/create_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@
LOG.addHandler(log_handler)


def copy_entry_points(input_dirs, build_dir):
def copy_entry_points(input_data, build_dir):
"""
Copy CodeChecker entry point sub-commands.
"""
package_root = os.path.join(build_dir, 'CodeChecker')
package_bin = os.path.join(package_root, 'bin')
target_cc = os.path.join(package_root, 'cc_bin')

available_commands = []
for input_dir in input_dirs:
available_commands = {}
for i in input_data:
module_name = i.split(':')[1]
input_dir = i.split(':')[0]

for input_file in glob.glob(os.path.join(input_dir, '*')):
file_name = os.path.basename(input_file)
if not file_name.endswith(".py"):
Expand All @@ -36,7 +39,10 @@ def copy_entry_points(input_dirs, build_dir):
# entry points.
if file_name.startswith("codechecker-"):
command_name = file_name.replace("codechecker-", "")
available_commands.append(command_name)

file_name = command_name.replace('-', '_')
module_path = module_name + '/' + file_name + '.py'
available_commands[command_name] = module_path

skip_content = "# DO_NOT_INSTALL_TO_PATH"
with open(input_file, 'r') as file:
Expand All @@ -57,11 +63,9 @@ def copy_entry_points(input_dirs, build_dir):
# .py files are Python code that must run in a valid env.
shutil.copy2(input_file, target_cc)

available_commands.sort()

commands_json = os.path.join(target_cc, 'commands.json')
with open(commands_json, 'w') as commands:
json.dump(available_commands, commands, sort_keys=True)
json.dump(available_commands, commands, sort_keys=True, indent=2)


if __name__ == "__main__":
Expand All @@ -76,7 +80,10 @@ def copy_entry_points(input_dirs, build_dir):
nargs='+',
metavar='folder',
help="List of directories which contains CodeChecker "
"sub-commands")
"sub-commands. The format of sub-commands is: "
"<sub-command-name>:<module-name>, where "
"<module-name> is the module where the "
"sub-command can be found.")

parser.add_argument('-b', '--build-dir',
required=True,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions web/codechecker_web/cmd/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -------------------------------------------------------------------------
# The CodeChecker Infrastructure
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
# -------------------------------------------------------------------------
File renamed without changes.
5 changes: 5 additions & 0 deletions web/server/codechecker_server/cmd/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -------------------------------------------------------------------------
# The CodeChecker Infrastructure
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
# -------------------------------------------------------------------------
File renamed without changes.
14 changes: 7 additions & 7 deletions web/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ test_novenv: pycodestyle pylint test_unit_novenv test_functional_novenv

PYCODESTYLE_TEST_CMD = pycodestyle \
--exclude=server/codechecker_server/migrations \
bin cmd codechecker_web tests \
client/bin client/codechecker_client client/cmd \
server/bin server/codechecker_server server/cmd server/tests \
bin codechecker_web tests \
client/bin client/codechecker_client \
server/bin server/codechecker_server server/tests \
tests

pycodestyle: venv_dev
$(ACTIVATE_DEV_VENV) && $(PYCODESTYLE_TEST_CMD)

PYLINT_TEST_CMD = pylint bin/codechecker-web-version cmd/web_version.py \
PYLINT_TEST_CMD = pylint bin/codechecker-web-version \
codechecker_web \
client/cmd/cmd.py client/cmd/store.py client/codechecker_client \
server/bin/codechecker-server server/cmd/server.py \
server/codechecker_server server/tests/unit \
client/bin/codechecker-cmd client/bin/codechecker-store \
client/codechecker_client \
server/bin/codechecker-server server/codechecker_server server/tests/unit \
--rcfile=$(ROOT)/.pylintrc \
--disable=all \
--enable=logging-format-interpolation,old-style-class
Expand Down

0 comments on commit 0910e15

Please sign in to comment.