Skip to content

Commit

Permalink
Remake 'plist' as a wrapper over either 'store' or 'parse'.
Browse files Browse the repository at this point in the history
  • Loading branch information
whisperity committed May 9, 2017
1 parent f2baeab commit 5d4d4f7
Show file tree
Hide file tree
Showing 6 changed files with 341 additions and 216 deletions.
118 changes: 0 additions & 118 deletions bin/CodeChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,6 @@
analyzers = ' '.join(list(analyzer_types.supported_analyzers))


class OrderedCheckersAction(argparse.Action):
"""
Action to store enabled and disabled checkers
and keep ordering from command line.
Create separate lists based on the checker names for
each analyzer.
"""

def __init__(self, option_strings, dest, nargs=None, **kwargs):
if nargs is not None:
raise ValueError("nargs not allowed")
super(OrderedCheckersAction, self).__init__(option_strings, dest,
**kwargs)

def __call__(self, parser, namespace, value, option_string=None):

if 'ordered_checkers' not in namespace:
namespace.ordered_checkers = []
ordered_checkers = namespace.ordered_checkers
ordered_checkers.append((value, self.dest == 'enable'))

namespace.ordered_checkers = ordered_checkers


# -----------------------------------------------------------------------------
class DeprecatedOptionAction(argparse.Action):
"""
Expand Down Expand Up @@ -112,45 +87,6 @@ def add_database_arguments(parser):
help='Database user name.')


# TODO: Superseded by libcodechecker/analyze.py
def add_analyzer_arguments(parser):
"""
Analyzer related arguments.
"""
parser.add_argument('-e', '--enable',
default=argparse.SUPPRESS,
action=OrderedCheckersAction,
help='Enable checker.')
parser.add_argument('-d', '--disable',
default=argparse.SUPPRESS,
action=OrderedCheckersAction,
help='Disable checker.')
parser.add_argument('--keep-tmp', action="store_true",
dest="keep_tmp", required=False,
help="Keep temporary report files "
"generated during the analysis.")

parser.add_argument('--analyzers', nargs='+',
dest="analyzers", required=False,
default=[analyzer_types.CLANG_SA,
analyzer_types.CLANG_TIDY],
help="Select which analyzer should be enabled.\n"
"Currently supported analyzers are: " +
analyzers + "\ne.g. '--analyzers " + analyzers + "'")

parser.add_argument('--saargs', dest="clangsa_args_cfg_file",
required=False, default=argparse.SUPPRESS,
help="File with arguments which will be forwarded "
"directly to the Clang static analyzer "
"without modification.")

parser.add_argument('--tidyargs', dest="tidy_args_cfg_file",
required=False, default=argparse.SUPPRESS,
help="File with arguments which will be forwarded "
"directly to the Clang tidy analyzer "
"without modification.")


def main(subcommands=None):
"""
CodeChecker main command line.
Expand Down Expand Up @@ -216,11 +152,6 @@ def _warn_deprecated_command(cmd_name):
workspace_help_msg = 'Directory where the CodeChecker can' \
' store analysis related data.'

name_help_msg = 'Name of the analysis.'

jobs_help_msg = 'Number of jobs. ' \
'Start multiple processes for faster analysis.'

# --------------------------------------
# Checkers parser.
checker_p = subparsers.add_parser('checkers',
Expand Down Expand Up @@ -336,55 +267,6 @@ def _warn_deprecated_command(cmd_name):
logger.add_verbose_arguments(debug_parser)
debug_parser.set_defaults(func=arg_handler.handle_debug)

# --------------------------------------
# Plist parser.
plist_parser = subparsers.add_parser('plist',
formatter_class=ADHF,
help='Parse plist files in '
'the given directory and '
'store them to the database '
'or print to the standard '
'output.')
old_subcommands.append('plist')

plist_parser.add_argument('-w', '--workspace', type=str,
dest="workspace",
default=util.get_default_workspace(),
help=workspace_help_msg)

plist_parser.add_argument('-n', '--name', type=str,
dest="name", required=True,
default=argparse.SUPPRESS,
help=name_help_msg)

plist_parser.add_argument('-d', '--directory', type=str,
dest="directory", required=True,
help='Path of a directory containing plist '
'files to parse.')

plist_parser.add_argument('-j', '--jobs', type=int, dest="jobs",
default=1, required=False,
help=jobs_help_msg)

plist_parser.add_argument('-s', '--steps', action="store_true",
dest="print_steps", help='Print steps.')

plist_parser.add_argument('--stdout', action="store_true",
dest="stdout",
required=False, default=False,
help='Print results to stdout instead of '
'storing to the database.')

plist_parser.add_argument('--force', action="store_true",
dest="force", default=False, required=False,
help='Delete analysis results form the '
'database if a run with the given '
'name already exists.')

add_database_arguments(plist_parser)
logger.add_verbose_arguments(plist_parser)
plist_parser.set_defaults(func=arg_handler.handle_plist)

# --------------------------------------
# Package version info.
version_parser = subparsers.add_parser('version',
Expand Down
3 changes: 3 additions & 0 deletions bin/codechecker-plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# DO_NOT_INSTALL_TO_PATH
This file marks 'CodeChecker plist' to be a valid command, but prohibits
use as 'codechecker-plist'.
10 changes: 0 additions & 10 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -953,16 +953,6 @@ positional arguments:
optional arguments:
-h, --help show this help message and exit
~~~~~~~~~~~~~~~~~~~~~
## 6. plist mode:
Clang Static Analyzer's scan-build script can generate analyis output into plist xml files.
In this You can import these files into the database.
You will need to specify containing the plist files afther the -d option.

Example:
~~~~~~~~~~~~~~~~~~~~~
CodeChecker plist -d ./results_plist -n myresults
~~~~~~~~~~~~~~~~~~~~~


## 7. debug mode:

Expand Down
6 changes: 1 addition & 5 deletions libcodechecker/analyze/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
# License. See LICENSE.TXT for details.
# -------------------------------------------------------------------------
"""
Prepare and start different analisys types
Prepare and start different analysis types
"""
import copy
import json
import os
import shlex
import subprocess
import sys
import time

from libcodechecker import client
from libcodechecker.logger import LoggerFactory
from libcodechecker.analyze import analysis_manager
from libcodechecker.analyze import analyzer_env
Expand Down
84 changes: 1 addition & 83 deletions libcodechecker/arg_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
# License. See LICENSE.TXT for details.
# -------------------------------------------------------------------------
"""
Handle command line arguments.
Handle old-style subcommand invocation.
"""
import errno
import json
import multiprocessing
import os
import psutil
import socket
import shutil
import socket
import sys
import tempfile

from libcodechecker import client
from libcodechecker import debug_reporter
Expand All @@ -24,13 +20,10 @@
from libcodechecker import host_check
from libcodechecker import session_manager
from libcodechecker import util
from libcodechecker.analyze import analyzer
from libcodechecker.analyze import analyzer_env
from libcodechecker.analyze import log_parser
from libcodechecker.analyze.analyzers import analyzer_types
from libcodechecker.database_handler import SQLServer
from libcodechecker.log import build_action
from libcodechecker.log import build_manager
from libcodechecker.logger import LoggerFactory
from libcodechecker.server import client_db_access_server
from libcodechecker.server import instance_manager
Expand Down Expand Up @@ -244,81 +237,6 @@ def handle_debug(args):
args.force)


def consume_plist(item):
plist, args, context = item
LOG.info('Consuming ' + plist)

action = build_action.BuildAction()
action.analyzer_type = analyzer_types.CLANG_SA
action.original_command = 'Imported from PList directly'

rh = analyzer_types.construct_result_handler(args,
action,
context.run_id,
args.directory,
context.severity_map,
None,
None,
not args.stdout)

rh.analyzer_returncode = 0
rh.buildaction.analyzer_type = 'Build action from plist'
rh.buildaction.original_command = plist
rh.analyzer_cmd = ''
rh.analyzed_source_file = '' # TODO: fill from plist.
rh.result_file = os.path.join(args.directory, plist)
rh.handle_results()


def handle_plist(args):
context = generic_package_context.get_context()
context.codechecker_workspace = args.workspace
context.db_username = args.dbusername

if not args.stdout:
args.workspace = os.path.realpath(args.workspace)
if not os.path.isdir(args.workspace):
os.mkdir(args.workspace)

check_env = analyzer_env.get_check_env(context.path_env_extra,
context.ld_lib_path_extra)

sql_server = SQLServer.from_cmdline_args(args,
context.migration_root,
check_env)

conn_mgr = client.ConnectionManager(sql_server,
'localhost',
util.get_free_port())

sql_server.start(context.db_version_info, wait_for_start=True,
init=True)

conn_mgr.start_report_server()

with client.get_connection() as connection:
context.run_id = connection.add_checker_run(' '.join(sys.argv),
args.name,
context.version,
args.force)

pool = multiprocessing.Pool(args.jobs)

try:
items = [(plist, args, context)
for plist in os.listdir(args.directory)]
pool.map_async(consume_plist, items, 1).get(float('inf'))
pool.close()
except Exception:
pool.terminate()
raise
finally:
pool.join()

if not args.stdout:
log_startserver_hint(args)


def handle_version_info(args):
"""
Get and print the version information from the
Expand Down
Loading

0 comments on commit 5d4d4f7

Please sign in to comment.