Skip to content

Commit

Permalink
Merge pull request Ericsson#163 from igalex/sqlite_support
Browse files Browse the repository at this point in the history
SQLite support
  • Loading branch information
gyorb committed Nov 26, 2015
2 parents 51e32fd + 64c6472 commit 456b92f
Show file tree
Hide file tree
Showing 16 changed files with 550 additions and 435 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ script:
- ./test_package.py -p ./codechecker_package/CodeChecker -v stable --dbport 5432 --dbusername postgres
- export CODECHECKER_DB_DRIVER=pg8000
- ./test_package.py -p ./codechecker_package/CodeChecker -v stable --dbport 5432 --dbusername postgres
- unset CODECHECKER_DB_DRIVER
- ./test_package.py -p ./codechecker_package/CodeChecker -v stable --sqlite
- ./test_quickcheck.py -p ./codechecker_package/CodeChecker
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CodeChecker replaces [scan-build](http://clang-analyzer.llvm.org/scan-build.html
It provides
* a new command line tool for analyzing projects
* dynamic web based defect viewer (instead of static html)
* a Postgresql based defect storage & management
* a PostgreSQL/SQLite based defect storage & management
* incremental bug reporting (show only new bugs compared to a baseline)
* suppression of false positives
* better integration with build systems (through the LD_PRELOAD mechanism)
Expand Down Expand Up @@ -55,12 +55,12 @@ If your clang version does not have these features you will see warning messages

### Runtime requirements
* [Clang Static analyzer](http://clang-analyzer.llvm.org/) (latest stable or [trunk](http://clang.llvm.org/get_started.html))
* [Postgresql](http://www.postgresql.org/ "PostgreSql") (> 9.3.5)
* [PostgreSQL](http://www.postgresql.org/ "PostgreSQL") (> 9.3.5) (optional)
* [Python2](https://www.python.org/) (> 2.7)
* [Alembic](https://pypi.python.org/pypi/alembic) (>=0.8.2)
* [SQLAlchemy](http://www.sqlalchemy.org/) (> 1.0.2)
- [PyPi SQLAlchemy](https://pypi.python.org/pypi/SQLAlchemy) (> 1.0.2)
* [psycopg2](http://initd.org/psycopg/ "psycopg2") (> 2.5.4) or [pg8000](https://github.com/mfenniak/pg8000 "pg8000") (>= 1.10.0)
* [psycopg2](http://initd.org/psycopg/ "psycopg2") (> 2.5.4) or [pg8000](https://github.com/mfenniak/pg8000 "pg8000") (>= 1.10.0) (optional)
- [PyPi psycopg2](https://pypi.python.org/pypi/psycopg2/2.6.1) __requires lbpq!__
- [PyPi pg8000](https://pypi.python.org/pypi/pg8000)
* Thrift python modules
Expand Down
58 changes: 22 additions & 36 deletions codechecker/CodeChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ def __call__(self, parser, namespace, value=None, option_string=None):
LOG.warning("Deprecated command line option in use: '" + option_string + "'")


def add_database_arguments(parser):
'''Helper method for adding database arguments to an argument parser.'''

parser.add_argument('--sqlite', dest="sqlite",
action='store_true', required=False,
help='Use sqlite database.')
parser.add_argument('--dbport', type=int, dest="dbport",
default=8764, required=False,
help='Postgres server port.')
parser.add_argument('--dbaddress', type=str, dest="dbaddress",
default="localhost", required=False,
help='Postgres database server address')
parser.add_argument('--dbname', type=str, dest="dbname",
default="codechecker", required=False,
help='Name of the database.')
parser.add_argument('--dbusername', type=str, dest="dbusername",
default='codechecker', required=False,
help='Database user name.')

# ------------------------------------------------------------------------------
def main():
'''
Expand Down Expand Up @@ -137,22 +156,11 @@ def signal_handler(sig, frame):
dest="keep_tmp", required=False,
help='Keep temporary report files \
after sending data to database storage server.')
check_parser.add_argument('--dbaddress', type=str, dest="dbaddress",
default="localhost", required=False,
help='Postgres database server address.')
check_parser.add_argument('--dbport', type=int, dest="dbport",
default=8764, required=False,
help='Postgres database server port.')
check_parser.add_argument('--dbname', type=str, dest="dbname",
default="codechecker", required=False,
help='Name of the database.')
check_parser.add_argument('--dbusername', type=str, dest="dbusername",
default='codechecker', required=False,
help='Database user name.')
check_parser.add_argument('--update', action="store_true",
dest="update", default=False, required=False,
help='Incremental parsing, \
update the results of a previous run.')
add_database_arguments(check_parser)
check_parser.set_defaults(func=arg_handler.handle_check)

# --------------------------------------
Expand Down Expand Up @@ -204,18 +212,6 @@ def signal_handler(sig, frame):
help='Directory where the codechecker \
stored analysis related data \
(automatically created posgtreSql database).')
server_parser.add_argument('--dbport', type=int, dest="dbport",
default=8764, required=False,
help='Postgres server port.')
server_parser.add_argument('--dbaddress', type=str, dest="dbaddress",
default="localhost", required=False,
help='Postgres database server address')
server_parser.add_argument('--dbname', type=str, dest="dbname",
default="codechecker", required=False,
help='Name of the database.')
server_parser.add_argument('--dbusername', type=str, dest="dbusername",
default='codechecker', required=False,
help='Database user name.')
server_parser.add_argument('-v', '--view-port', type=int, dest="view_port",
default=11444, required=False,
help='Port used for viewing.')
Expand All @@ -231,6 +227,7 @@ def signal_handler(sig, frame):
server_parser.add_argument('--check-address', type=str,
dest="check_address", default="localhost",
required=False, help='Server address.')
add_database_arguments(server_parser)
server_parser.set_defaults(func=arg_handler.handle_server)

# --------------------------------------
Expand All @@ -248,21 +245,10 @@ def signal_handler(sig, frame):
dest="workspace", required=False,
help='Directory where the codechecker stores \
analysis related data.')
debug_parser.add_argument('--dbport', type=int, dest="dbport",
default=8764, required=False,
help='Postgres server port.')
debug_parser.add_argument('--dbaddress', type=str, dest="dbaddress",
default="localhost", required=False,
help='Postgres database server address')
debug_parser.add_argument('--dbname', type=str, dest="dbname",
default="codechecker", required=False,
help='Name of the database.')
debug_parser.add_argument('--dbusername', type=str, dest="dbusername",
default='codechecker', required=False,
help='Database user name.')
debug_parser.add_argument('-f', '--force', action="store_true",
dest="force", required=False, default=False,
help='Generate dump for all failed action.')
add_database_arguments(debug_parser)
debug_parser.set_defaults(func=arg_handler.handle_debug)

# --------------------------------------
Expand Down
75 changes: 27 additions & 48 deletions codechecker_lib/arg_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from codechecker_lib import analyzer_env
from codechecker_lib import host_check
from codechecker_lib import generic_package_suppress_handler
from codechecker_lib.database_handler import SQLServer

LOG = logger.get_new_logger('ARGHANDLER')

Expand Down Expand Up @@ -136,11 +137,11 @@ def signal_handler(*arg, **kwarg):
def check_options_validity(args):
# Args must has workspace and dbaddress
if args.workspace and not util.is_localhost(args.dbaddress):
LOG.info("Workspace is not required when postgreSql server run on remote host.")
LOG.info("Workspace is not required when database server run on remote host.")
sys.exit(1)

if not args.workspace and util.is_localhost(args.dbaddress):
LOG.info("Workspace is required when postgreSql server run on localhost.")
LOG.info("Workspace is required when database server run on localhost.")
sys.exit(1)


Expand All @@ -166,21 +167,12 @@ def handle_list_checkers(args):
print('')


def setup_connection_manager_db(args):
client.ConnectionManager.database_host = args.dbaddress
client.ConnectionManager.database_port = args.dbport


def handle_server(args):

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

if not host_check.check_postgresql_driver():
LOG.error("postgresql driver error")
sys.exit(1)

check_options_validity(args)
if args.suppress is None:
LOG.warning('WARNING! No suppress file was given, suppressed results will be only stored in the database.')
Expand All @@ -194,32 +186,24 @@ def handle_server(args):
context.codechecker_workspace = args.workspace
context.db_username = args.dbusername

setup_connection_manager_db(args)

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

client.ConnectionManager.run_env = check_env

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 postgres.')
client.ConnectionManager.host = args.check_address
client.ConnectionManager.port = args.check_port
client.ConnectionManager.run_env = check_env

# starts posgres
client.ConnectionManager.start_server(args.dbname, context)
LOG.debug('Starting codechecker server and database server.')
sql_server.start(wait_for_start=True, init=True)
conn_mgr.start_report_server(context.db_version_info)
else:
LOG.debug('Starting postgres.')
client.ConnectionManager.start_postgres(context, init_db=False)

client.ConnectionManager.block_until_db_start_proc_free(context)
LOG.debug('Starting database.')
sql_server.start(wait_for_start=True, init=False)

# start database viewer
db_connection_string = util.create_postgresql_connection_string(
args.dbusername, args.dbaddress, args.dbport, args.dbname)

db_connection_string = sql_server.get_connection_string()
suppress_handler = generic_package_suppress_handler.GenericSuppressHandler()
suppress_handler.suppress_file = args.suppress
LOG.debug('Using suppress file: ' + str(suppress_handler.suppress_file))
Expand Down Expand Up @@ -260,23 +244,20 @@ def handle_log(args):


def handle_debug(args):
setup_connection_manager_db(args)

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

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

client.ConnectionManager.run_env = check_env

client.ConnectionManager.start_postgres(context)
sql_server = SQLServer.from_cmdline_args(args,
context.codechecker_workspace,
context.migration_root,
check_env)
sql_server.start(wait_for_start=True, init=False)

client.ConnectionManager.block_until_db_start_proc_free(context)

debug_reporter.debug(context, args.dbusername, args.dbaddress,
args.dbport, args.dbname, args.force)
debug_reporter.debug(context, sql_server.get_connection_string(), args.force)

def _check_generate_log_file(args, context, silent=False):
'''Returns a build command log file for check/quickcheck command.'''
Expand Down Expand Up @@ -316,10 +297,6 @@ def handle_check(args):
LOG.error("zlib error")
sys.exit(1)

if not host_check.check_postgresql_driver():
LOG.error("postgresql driver error")
sys.exit(1)

args.workspace = os.path.realpath(args.workspace)
if not os.path.isdir(args.workspace):
os.mkdir(args.workspace)
Expand Down Expand Up @@ -353,8 +330,11 @@ def handle_check(args):
LOG.warning('There are no build actions in the log file.')
sys.exit(1)

setup_connection_manager_db(args)
client.ConnectionManager.port = util.get_free_port()
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())

if args.jobs <= 0:
args.jobs = 1
Expand All @@ -368,9 +348,8 @@ def handle_check(args):
if os.path.exists(suppress_file):
send_suppress = True

client.ConnectionManager.run_env = check_env

client.ConnectionManager.start_server(args.dbname, context)
sql_server.start(wait_for_start=True, init=True)
conn_mgr.start_report_server(context.db_version_info)

LOG.debug("Checker server started.")

Expand Down
Loading

0 comments on commit 456b92f

Please sign in to comment.