Пример #1
0
Supported analyzer types.
"""


import os
import re

from codechecker_analyzer import env
from codechecker_common.logger import get_logger

from .. import host_check

from .clangtidy.analyzer import ClangTidy
from .clangsa.analyzer import ClangSA

LOG = get_logger('analyzer')

supported_analyzers = {ClangSA.ANALYZER_NAME: ClangSA,
                       ClangTidy.ANALYZER_NAME: ClangTidy}


def is_ctu_capable(context):
    """ Detects if the current clang is CTU compatible. """
    enabled_analyzers, _ = \
        check_supported_analyzers([ClangSA.ANALYZER_NAME], context)
    if not enabled_analyzers:
        return False

    clangsa_cfg = ClangSA.construct_config_handler([], context)

    return clangsa_cfg.ctu_capability.is_ctu_capable
Пример #2
0
from __future__ import division
from __future__ import absolute_import

import getpass
import json
import os
import psutil
import socket
import stat

import portalocker

from codechecker_common.logger import get_logger
from codechecker_common.util import load_json_or_empty

LOG = get_logger('system')


def __get_instance_descriptor_path(folder=None):
    if not folder:
        folder = os.path.expanduser("~")

    return os.path.join(folder, ".codechecker.instances.json")


def __make_instance_descriptor_file(folder=None):
    descriptor = __get_instance_descriptor_path(folder)
    if not os.path.exists(descriptor):
        with open(descriptor, 'w') as f:
            json.dump([], f)
        os.chmod(descriptor, stat.S_IRUSR | stat.S_IWUSR)
Пример #3
0
# -------------------------------------------------------------------------
"""
Result handler for Clang Tidy.
"""
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

from codechecker_common import report
from codechecker_common.logger import get_logger

from ..result_handler_base import ResultHandler

from . import output_converter

LOG = get_logger('report')


def generate_plist_from_tidy_result(output_file, tidy_stdout):
    """
    Generate a plist file from the clang tidy analyzer results.
    """
    parser = output_converter.OutputParser()

    messages = parser.parse_messages(tidy_stdout)

    plist_converter = output_converter.PListConverter()
    plist_converter.add_messages(messages)

    plist_converter.write_to_file(output_file)
Пример #4
0
"""
Helpers to profile.
"""

from datetime import datetime
import cProfile
import pstats

from functools import wraps

from io import StringIO

from codechecker_common import logger
from codechecker_common.logger import get_logger

LOG = get_logger('profiler')


class Timer(object):
    """
    Simple timer context manager
    to measure code block execution time.
    """
    def __init__(self, block_name=''):
        self.block_name = block_name

    def __enter__(self):
        self.before = datetime.now()

    def __exit__(self, timer_type, value, traceback):
        after = datetime.now()
Пример #5
0
from datetime import datetime
import cProfile
import pstats

from functools import wraps

try:
    from StringIO import StringIO
except ImportError:
    from io import BytesIO as StringIO

from codechecker_common import logger
from codechecker_common.logger import get_logger

LOG = get_logger('profiler')


class Timer(object):
    """
    Simple timer context manager
    to measure code block execution time.
    """
    def __init__(self, block_name=''):
        self.block_name = block_name

    def __enter__(self):
        self.before = datetime.now()

    def __exit__(self, timer_type, value, traceback):
        after = datetime.now()
Пример #6
0
def init_logger(level, logger_name='system'):
    logger.setup_logger(level)
    global LOG
    LOG = logger.get_logger(logger_name)
Пример #7
0
def init_logger(level, stream=None, logger_name='system'):
    logger.setup_logger(level, stream)
    global LOG
    LOG = logger.get_logger(logger_name)
Пример #8
0
for the plist_parser module.
"""
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import copy
import json
import os
import plistlib
import re

from codechecker_common.logger import get_logger
from codechecker_common.report import generate_report_hash

LOG = get_logger('analyzer.tidy')


class Note(object):
    """
    Represents a note and also this is the base class of Message.
    """

    def __init__(self, path, line, column, message):
        self.path = path
        self.line = line
        self.column = column
        self.message = message

    def __eq__(self, other):
        return self.path == other.path and \
Пример #9
0
# -------------------------------------------------------------------------
#                     The CodeChecker Infrastructure
#   This file is distributed under the University of Illinois Open Source
#   License. See LICENSE.TXT for details.
# -------------------------------------------------------------------------
"""
Config handler for Clang Tidy analyzer.
"""


from codechecker_common.logger import get_logger

from .. import config_handler

LOG = get_logger('analyzer.tidy')


class ClangTidyConfigHandler(config_handler.AnalyzerConfigHandler):
    """
    Configuration handler for Clang-tidy analyzer.
    """

    def __init__(self):
        super(ClangTidyConfigHandler, self).__init__()

    def set_checker_enabled(self, checker_name, enabled=True):
        """
        Enable checker, keep description if already set.
        """
        if checker_name.startswith('W') or \
           checker_name.startswith('clang-diagnostic-'):
Пример #10
0
#  LLVM Exceptions. See LICENSE for license information.
#  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------
"""
Clang Static analyzer configuration handler.
"""
import os

from codechecker_analyzer import env
from codechecker_common.logger import get_logger
from .ctu_autodetection import CTUAutodetection

from .. import config_handler

LOG = get_logger('analyzer.clangsa')


class ClangSAConfigHandler(config_handler.AnalyzerConfigHandler):
    """
    Configuration handler for the clang static analyzer.
    """

    def __init__(self, environ):
        super(ClangSAConfigHandler, self).__init__()
        self.ctu_dir = ''
        self.ctu_on_demand = False
        self.log_file = ''
        self.path_env_extra = ''
        self.ld_lib_path_extra = ''
        self.enable_z3 = False
Пример #11
0
from .database.config_db_model import Session as SessionRecord
from .database.config_db_model import SystemPermission

UNSUPPORTED_METHODS = []

try:
    from .auth import cc_ldap
except ImportError:
    UNSUPPORTED_METHODS.append('ldap')

try:
    from .auth import cc_pam
except ImportError:
    UNSUPPORTED_METHODS.append('pam')

LOG = get_logger("server")
SESSION_COOKIE_NAME = _SCN


def generate_session_token():
    """
    Returns a random session token.
    """
    return uuid.UUID(bytes=os.urandom(16)).hex


def get_worker_processes(scfg_dict, default=10):
    """
    Return number of worker processes from the config dictionary.

    Return 'worker_processes' field from the config dictionary or returns the
Пример #12
0
# -------------------------------------------------------------------------
"""
Clang Static analyzer configuration handler.
"""

from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import re

from codechecker_common.logger import get_logger

from .. import config_handler

LOG = get_logger('analyzer.clangsa')


class ClangSAConfigHandler(config_handler.AnalyzerConfigHandler):
    """
    Configuration handler for the clang static analyzer.
    """

    def __init__(self):
        super(ClangSAConfigHandler, self).__init__()
        self.__checker_configs = []
        self.ctu_dir = ''
        self.log_file = ''
        self.path_env_extra = ''
        self.ld_lib_path_extra = ''
Пример #13
0
def init_logger(level, logger_name='system'):
    logger.setup_logger(level)
    global LOG
    LOG = logger.get_logger(logger_name)
Пример #14
0
from .database.config_db_model import SystemPermission

UNSUPPORTED_METHODS = []

try:
    from .auth import cc_ldap
except ImportError:
    UNSUPPORTED_METHODS.append('ldap')

try:
    from .auth import cc_pam
except ImportError:
    UNSUPPORTED_METHODS.append('pam')


LOG = get_logger("server")
SESSION_COOKIE_NAME = _SCN


class _Session(object):
    """A session for an authenticated, privileged client connection."""

    def __init__(self, token, username, groups,
                 session_lifetime, refresh_time, is_root=False, database=None,
                 last_access=None, can_expire=True):

        self.token = token
        self.user = username
        self.groups = groups

        self.session_lifetime = session_lifetime
Пример #15
0
from codechecker_server import instance_manager, server
from codechecker_server.database import database
from codechecker_server.database.config_db_model \
    import IDENTIFIER as CONFIG_META
from codechecker_server.database.config_db_model \
    import Product as ORMProduct
from codechecker_server.database.run_db_model \
    import IDENTIFIER as RUN_META
from codechecker_server.env import is_localhost

from codechecker_web.shared import webserver_context, database_status, \
    host_check
from codechecker_web.shared.env import get_default_workspace, get_user_input

LOG = logger.get_logger('server')


def get_argparser_ctor_args():
    """
    This method returns a dict containing the kwargs for constructing an
    argparse.ArgumentParser (either directly or as a subparser).
    """

    return {
        'prog':
        'CodeChecker server',
        'formatter_class':
        argparse.ArgumentDefaultsHelpFormatter,

        # Description is shown when the command's help is queried directly
Пример #16
0
from __future__ import division
from __future__ import absolute_import

import os
import pickle
import platform
import subprocess
import sys
from uuid import uuid4

from codechecker_common.logger import get_logger

from .. import analyzer_env
from . import host_check

LOG = get_logger('buildlogger')


def execute_buildcmd(command, silent=False, env=None, cwd=None):
    """
    Execute the the build command and continuously write
    the output from the process to the standard output.
    """
    proc = subprocess.Popen(command,
                            bufsize=-1,
                            env=env,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            cwd=cwd,
                            shell=True)
Пример #17
0
import re
import shlex
import subprocess
import sys
import tempfile
import traceback

from codechecker_analyzer.analyzers import clangsa

from codechecker_common.logger import get_logger
from codechecker_common.util import load_json_or_empty

from .. import gcc_toolchain
from .build_action import BuildAction

LOG = get_logger('buildlogger')

SOURCE_EXTENSIONS = {
    ".c", ".cc", ".cp", ".cpp", ".cxx", ".c++", ".o", ".so", ".a"
}

# Replace gcc/g++ build target options with values accepted by Clang.
REPLACE_OPTIONS_MAP = {
    '-mips32': ['-target', 'mips', '-mips32'],
    '-mips64': ['-target', 'mips64', '-mips64'],
    '-mpowerpc': ['-target', 'powerpc'],
    '-mpowerpc64': ['-target', 'powerpc64']
}

# The compilation flags of which the prefix is any of these regular expressions
# will not be included in the output Clang command.
Пример #18
0
"""
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import glob
import os
import shutil
import tempfile

from codechecker_common.logger import get_logger

from .. import analyzer_base
from . import ctu_triple_arch

LOG = get_logger('analyzer')


def generate_func_map_lines(fnmap_dir):
    """ Iterate over all lines of input files in random order. """

    files = glob.glob(os.path.join(fnmap_dir, '*'))
    for filename in files:
        with open(filename, 'r') as in_file:
            for line in in_file:
                yield line


def create_global_ctu_function_map(func_map_lines):
    """ Takes iterator of individual function maps and creates a global map
    keeping only unique names. We leave conflicting names out of CTU.
Пример #19
0
#                     The CodeChecker Infrastructure
#   This file is distributed under the University of Illinois Open Source
#   License. See LICENSE.TXT for details.
# -------------------------------------------------------------------------
"""
Parsers for the analyzer output formats (plist ...) should create this
Report which will be stored.
"""


import json

from codechecker_common.logger import get_logger
from codechecker_common import util

LOG = get_logger('report')


class Report(object):
    """
    Just a minimal separation of the main section
    from the path section for easier skip/suppression handling
    and result processing.
    """
    def __init__(self, main, bugpath, files):
        # Dictionary containing checker name, report hash,
        # main report position, report message ...
        self.__main = main

        # Dictionary containing bug path related data
        # with control, event ... sections.
Пример #20
0
import json
import shared

from Authentication_v6.ttypes import *

from codechecker_common.logger import get_logger
from codechecker_common.profiler import timeit
from codechecker_common.util import generate_session_token, DBSession

from ..database.config_db_model import Session
from ..permissions import handler_from_scope_params as make_handler
from ..permissions import require_manager, require_permission
from ..server import permissions

LOG = get_logger('server')


class ThriftAuthHandler(object):
    """
    Handle Thrift authentication requests.
    """

    def __init__(self, manager, auth_session, config_database):
        self.__manager = manager
        self.__auth_session = auth_session
        self.__config_db = config_database

    def __require_privilaged_access(self):
        """
        Checks if privilaged access is enabled for the server. Throws an
Пример #21
0
stdout.
"""

import argparse
import os
import shutil
import tempfile

from codechecker_analyzer import analyzer_context
from codechecker_analyzer.analyzers import analyzer_types
from codechecker_analyzer.arg import OrderedCheckersAction

from codechecker_common import arg, logger
from codechecker_common.source_code_comment_handler import REVIEW_STATUS_VALUES

LOG = logger.get_logger('system')


def get_argparser_ctor_args():
    """
    This method returns a dict containing the kwargs for constructing an
    argparse.ArgumentParser (either directly or as a subparser).
    """

    return {
        'prog':
        'CodeChecker check',
        'formatter_class':
        arg.RawDescriptionDefaultHelpFormatter,

        # Description is shown when the command's help is queried directly
Пример #22
0
from shared.ttypes import Permission, RequestFailed, ErrorCode

from codechecker_client import client as libclient

from codechecker_common import logger
from codechecker_common import util
from codechecker_common import plist_parser
from codechecker_common.output_formatters import twodim_to_str
from codechecker_common.source_code_comment_handler import \
    SourceCodeCommentHandler
from codechecker_common.util import sizeof_fmt
from codechecker_common.util import split_product_url

from codechecker_web.shared import webserver_context, host_check

LOG = logger.get_logger('system')

MAX_UPLOAD_SIZE = 1 * 1024 * 1024 * 1024  # 1GiB


def get_argparser_ctor_args():
    """
    This method returns a dict containing the kwargs for constructing an
    argparse.ArgumentParser (either directly or as a subparser).
    """

    return {
        'prog': 'CodeChecker store',
        'formatter_class': argparse.ArgumentDefaultsHelpFormatter,

        # Description is shown when the command's help is queried directly
Пример #23
0
from .tmp import get_tmp_dir_hash

from .api.authentication import ThriftAuthHandler as AuthHandler_v6
from .api.config_handler import ThriftConfigHandler as ConfigHandler_v6
from .api.product_server import ThriftProductHandler as ProductHandler_v6
from .api.report_server import ThriftRequestHandler as ReportHandler_v6
from .api.server_info_handler import \
    ThriftServerInfoHandler as ServerInfoHandler_v6
from .database import database, db_cleanup
from .database.config_db_model import Product as ORMProduct, \
    Configuration as ORMConfiguration
from .database.database import DBSession
from .database.run_db_model import IDENTIFIER as RUN_META, Run, RunLock

LOG = get_logger('server')


class RequestHandler(SimpleHTTPRequestHandler):
    """
    Handle thrift and browser requests
    Simply modified and extended version of SimpleHTTPRequestHandler
    """
    auth_session = None

    def __init__(self, request, client_address, server):
        BaseHTTPRequestHandler.__init__(self, request, client_address, server)

    def log_message(self, msg_format, *args):
        """ Silencing http server. """
        return
Пример #24
0
#   License. See LICENSE.TXT for details.
# -------------------------------------------------------------------------
"""
Functions to check the host machine and the analyzers for various
features, dependecies and configurations.
"""

from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import os

from codechecker_common.logger import get_logger

LOG = get_logger('system')


def check_zlib():
    """ Check if zlib compression is available.
    If wrong libraries are installed on the host machine it is
    possible the the compression fails which is required to
    store data into the database.
    """
    try:
        import zlib
        zlib.compress('Compress this')
        return True
    except Exception as ex:
        LOG.error(str(ex))
        LOG.error('Failed to import zlib module.')
Пример #25
0
from codechecker_common import util
from codechecker_common.env import get_check_env

from codechecker_server import instance_manager, server
from codechecker_server.database import database
from codechecker_server.database.config_db_model \
    import IDENTIFIER as CONFIG_META
from codechecker_server.database.config_db_model \
    import Product as ORMProduct
from codechecker_server.database.run_db_model \
    import IDENTIFIER as RUN_META

from codechecker_web.shared import webserver_context, database_status, \
    host_check

LOG = logger.get_logger('server')


def get_argparser_ctor_args():
    """
    This method returns a dict containing the kwargs for constructing an
    argparse.ArgumentParser (either directly or as a subparser).
    """

    return {
        'prog': 'CodeChecker server',
        'formatter_class': argparse.ArgumentDefaultsHelpFormatter,

        # Description is shown when the command's help is queried directly
        'description': "The CodeChecker Web server is used to handle the "
                       "storage and navigation of analysis results. A "