コード例 #1
0
def handle_check(args):
    """
    Runs the original build and logs the buildactions.
    Based on the log runs the analysis.
    """
    try:
        if not host_check.check_zlib():
            sys.exit(1)

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

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

        log_file = build_manager.check_log_file(args, context)

        if not log_file:
            LOG.error("Failed to generate compilation command file: " +
                      log_file)
            sys.exit(1)

        actions = log_parser.parse_log(log_file, args.add_compiler_defaults)

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

        sql_server = SQLServer.from_cmdline_args(args,
                                                 context.codechecker_workspace,
                                                 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()

        LOG.debug("Checker server started.")

        analyzer.run_check(args, actions, context)

        LOG.info("Analysis has finished.")

        log_startserver_hint(args)

    except Exception as ex:
        LOG.error(ex)
        import traceback
        print(traceback.format_exc())
    finally:
        if not args.keep_tmp:
            if log_file:
                LOG.debug('Removing temporary log file: ' + log_file)
                os.remove(log_file)
コード例 #2
0
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.codechecker_workspace,
                                                 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)
コード例 #3
0
def handle_server(args):
    """
    Starts the report viewer server.
    """
    if not host_check.check_zlib():
        sys.exit(1)

    workspace = args.workspace

    # WARNING
    # In case of SQLite args.dbaddress default value is used
    # for which the is_localhost should return true.
    if util.is_localhost(args.dbaddress) and not os.path.exists(workspace):
        os.makedirs(workspace)

    suppress_handler = generic_package_suppress_handler.\
        GenericSuppressHandler()
    if args.suppress is None:
        LOG.warning('No suppress file was given, suppressed results will '
                    'be only stored in the database.')
    else:
        if not os.path.exists(args.suppress):
            LOG.error('Suppress file ' + args.suppress + ' not found!')
            sys.exit(1)

    context = generic_package_context.get_context()
    context.codechecker_workspace = workspace
    session_manager.SessionManager.CodeChecker_Workspace = workspace
    context.db_username = args.dbusername

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

    sql_server = SQLServer.from_cmdline_args(args,
                                             context.codechecker_workspace,
                                             context.migration_root, check_env)
    conn_mgr = client.ConnectionManager(sql_server, args.check_address,
                                        args.check_port)
    if args.check_port:
        LOG.debug('Starting CodeChecker server and database server.')
        sql_server.start(context.db_version_info,
                         wait_for_start=True,
                         init=True)
        conn_mgr.start_report_server()
    else:
        LOG.debug('Starting database.')
        sql_server.start(context.db_version_info,
                         wait_for_start=True,
                         init=True)

    # Start database viewer.
    db_connection_string = sql_server.get_connection_string()

    suppress_handler.suppress_file = args.suppress
    LOG.debug('Using suppress file: ' + str(suppress_handler.suppress_file))

    checker_md_docs = os.path.join(context.doc_root, 'checker_md_docs')
    checker_md_docs_map = os.path.join(checker_md_docs, 'checker_doc_map.json')
    with open(checker_md_docs_map, 'r') as dFile:
        checker_md_docs_map = json.load(dFile)

    package_data = {
        'www_root': context.www_root,
        'doc_root': context.doc_root,
        'checker_md_docs': checker_md_docs,
        'checker_md_docs_map': checker_md_docs_map
    }

    client_db_access_server.start_server(package_data, args.view_port,
                                         db_connection_string,
                                         suppress_handler, args.not_host_only,
                                         context.db_version_info)
コード例 #4
0
def handle_server(args):
    """
    starts the report viewer server
    """
    if not host_check.check_zlib():
        LOG.error("zlib error")
        sys.exit(1)

    try:
        workspace = args.workspace
    except AttributeError:
        # if no workspace value was set for some reason
        # in args set the default value
        workspace = util.get_default_workspace()

    # WARNING
    # in case of SQLite args.dbaddress default value is used
    # for which the is_localhost should return true

    local_db = util.is_localhost(args.dbaddress)
    if local_db and not os.path.exists(workspace):
        os.makedirs(workspace)

    if args.suppress is None:
        LOG.warning(
            'WARNING! No suppress file was given, suppressed results will be only stored in the database.'
        )

    else:
        if not os.path.exists(args.suppress):
            LOG.error('Suppress file ' + args.suppress + ' not found!')
            sys.exit(1)

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

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

    sql_server = SQLServer.from_cmdline_args(args,
                                             context.codechecker_workspace,
                                             context.migration_root, check_env)
    conn_mgr = client.ConnectionManager(sql_server, args.check_address,
                                        args.check_port)
    if args.check_port:
        LOG.debug('Starting codechecker server and database server.')
        sql_server.start(context.db_version_info,
                         wait_for_start=True,
                         init=True)
        conn_mgr.start_report_server(context.db_version_info)
    else:
        LOG.debug('Starting database.')
        sql_server.start(context.db_version_info,
                         wait_for_start=True,
                         init=True)

    # start database viewer
    db_connection_string = sql_server.get_connection_string()

    suppress_handler = generic_package_suppress_handler.GenericSuppressHandler(
    )
    try:
        suppress_handler.suppress_file = args.suppress
        LOG.debug('Using suppress file: ' +
                  str(suppress_handler.suppress_file))
    except AttributeError as aerr:
        # suppress file was not set
        LOG.debug(aerr)

    package_data = {}
    package_data['www_root'] = context.www_root
    package_data['doc_root'] = context.doc_root

    checker_md_docs = os.path.join(context.doc_root, 'checker_md_docs')

    checker_md_docs_map = os.path.join(checker_md_docs, 'checker_doc_map.json')

    package_data['checker_md_docs'] = checker_md_docs

    with open(checker_md_docs_map, 'r') as dFile:
        checker_md_docs_map = json.load(dFile)

    package_data['checker_md_docs_map'] = checker_md_docs_map

    client_db_access_server.start_server(package_data, args.view_port,
                                         db_connection_string,
                                         suppress_handler, args.not_host_only,
                                         context.db_version_info)
コード例 #5
0
def handle_check(args):
    """
    Runs the original build and logs the buildactions
    Based on the log runs the analysis
    """
    try:

        if not host_check.check_zlib():
            LOG.error("zlib error")
            sys.exit(1)

        try:
            workspace = args.workspace
        except AttributeError:
            # if no workspace value was set for some reason
            # in args set the default value
            workspace = util.get_default_workspace()

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

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

        log_file = build_manager.check_log_file(args)

        if not log_file:
            log_file = build_manager.generate_log_file(args, context)
        if not log_file:
            LOG.error("Failed to generate compilation command file: " +
                      log_file)
            sys.ecit(1)

        try:
            actions = log_parser.parse_log(log_file)
        except Exception as ex:
            LOG.error(ex)
            sys.exit(1)

        if not actions:
            LOG.warning('There are no build actions in the log file.')
            sys.exit(1)

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

        sql_server = SQLServer.from_cmdline_args(args,
                                                 context.codechecker_workspace,
                                                 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(context.db_version_info)

        LOG.debug("Checker server started.")

        analyzer.run_check(args, actions, context)

        LOG.info("Analysis has finished.")

        db_data = ""
        if args.postgresql:
            db_data += " --postgresql" \
                    +  " --dbname " + args.dbname \
                    +  " --dbport " + str(args.dbport) \
                    +  " --dbusername " + args.dbusername

        LOG.info("To view results run:\nCodeChecker server -w " + workspace +
                 db_data)

    except Exception as ex:
        LOG.error(ex)
        import traceback
        print(traceback.format_exc())