anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: ericsson/codechecker
Issue: handle viewer 'Address already in use' exception

Handle viewer  `Address already in use` exception, provide a proper error message to the users.

Changed files:
codechecker_lib/arg_handler.py

diff --git a/codechecker_lib/arg_handler.py b/codechecker_lib/arg_handler.py
index 02a8808d..d93bd3f3 100644
--- a/codechecker_lib/arg_handler.py
+++ b/codechecker_lib/arg_handler.py
@@ -6,10 +6,12 @@
 """
 Handle command line arguments.
 """
+import errno
 import json
 import multiprocessing
 import os
 import shutil
+import socket
 import sys
 import tempfile
 
@@ -157,12 +159,21 @@ def handle_server(args):
                     '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)
+    try:
+        client_db_access_server.start_server(package_data,
+                                             args.view_port,
+                                             db_connection_string,
+                                             suppress_handler,
+                                             args.not_host_only,
+                                             context.db_version_info)
+    except socket.error as err:
+        if err.errno == errno.EADDRINUSE:
+            LOG.error("Server can't be started, maybe the given port number "
+                      "({}) is already used. Check the connection "
+                      "parameters.".format(args.view_port))
+            sys.exit(1)
+        else:
+            raise
 
 
 def handle_log(args):
Repository: ericsson/codechecker
Issue: Using wrong database name for checking database existence

When the database is password protected then an error happens when checking database existence, because the common `postgres` database is being looked up in the `.pgpass` file.

Changed files:
codechecker_lib/database_handler.py

diff --git a/codechecker_lib/database_handler.py b/codechecker_lib/database_handler.py
index 70c5413e..b0f27726 100644
--- a/codechecker_lib/database_handler.py
+++ b/codechecker_lib/database_handler.py
@@ -301,6 +301,13 @@ class PostgreSQLServer(SQLServer):
     def _get_connection_string(self, database):
         """
         Helper method for getting the connection string for the given database.
+
+        database -- The user can force the database name in the returning
+        connection string. However the password, if any, provided e.g. in a
+        .pgpass file will be queried based on the database name which is given
+        as a command line argument, even if it has a default value. The reason
+        is that sometimes a connection with a common database name is needed,
+        (e.g. 'postgres'), which requires less user permission.
         """
 
         port = str(self.port)
@@ -312,7 +319,7 @@ class PostgreSQLServer(SQLServer):
                 password = pgpass.get_password_from_file(pfilepath,
                                                          self.host,
                                                          port,
-                                                         database,
+                                                         self.database,
                                                          self.user)
 
         extra_args = {'client_encoding': 'utf8'}
Repository: ericsson/codechecker
Issue: suppression should be stored only once

Suppression should be run unique.
Currently the same bug hash can be stored multiple times for suppression. 
This can happen if the bug was suppressed in the suppress file before and suppressed later in the source file too.
After the suppress information from the suppress file is stored to the database and suppress information is available in the source file too, the source file suppress message should overwrite the already stored suppress information in the database.

Changed files:
storage_server/report_server.py

diff --git a/storage_server/report_server.py b/storage_server/report_server.py
index 0a05106d..e77ee417 100644
--- a/storage_server/report_server.py
+++ b/storage_server/report_server.py
@@ -526,13 +526,19 @@ class CheckerReportHandler(object):
         try:
             suppressList = []
             for bug_to_suppress in bugs_to_suppress:
-                suppress_bug = SuppressBug(run_id,
-                                           bug_to_suppress.bug_hash,
-                                           bug_to_suppress.file_name,
-                                           bug_to_suppress.comment)
-                suppressList.append(suppress_bug)
+                res = self.session.query(SuppressBug) \\
+                    .filter(SuppressBug.hash == bug_to_suppress.bug_hash,
+                            SuppressBug.run_id == run_id,
+                            SuppressBug.file_name == bug_to_suppress.file_name)
+
+                if res.one_or_none():
+                    res.update({'comment': bug_to_suppress.comment})
+                else:
+                    self.session.add(SuppressBug(run_id,
+                                                 bug_to_suppress.bug_hash,
+                                                 bug_to_suppress.file_name,
+                                                 bug_to_suppress.comment))
 
-            self.session.bulk_save_objects(suppressList)
             self.session.commit()
 
         except Exception as ex:
Repository: ericsson/codechecker
Issue: orphan checker name element in bug filter

In Codechecker Run Overview, checker filter dropdown, there is an orphan elment "(1)"  under the Unspecified checkers list.

clicking on it, lists all results.

Reproducible by checking 3.1.2
http://md-mtas2.tsp.eth.ericsson.se:9997/#run=2


Changed files:
storage_server/report_server.py

diff --git a/storage_server/report_server.py b/storage_server/report_server.py
index 0ea36638..a26058ea 100644
--- a/storage_server/report_server.py
+++ b/storage_server/report_server.py
@@ -417,6 +417,8 @@ class CheckerReportHandler(object):
             action = self.session.query(BuildAction).get(build_action_id)
             assert action is not None
 
+            checker_id = checker_id or 'NOT FOUND'
+
             # TODO: perfomance issues when executing the following query on
             # large databaseses?
             reports = self.session.query(self.report_ident) \\
Repository: ericsson/codechecker
Issue: fix analysis summary

Compilation command count shows all the processed compilation commands this is handled wrong in case some of the source files are skipped during the analysis based on the skip file


Changed files:
codechecker_lib/analysis_manager.py

diff --git a/codechecker_lib/analysis_manager.py b/codechecker_lib/analysis_manager.py
index 5e27f740..3c5f997b 100644
--- a/codechecker_lib/analysis_manager.py
+++ b/codechecker_lib/analysis_manager.py
@@ -29,15 +29,19 @@ def worker_result_handler(results):
 
     successful_analysis = defaultdict(int)
     failed_analisys = defaultdict(int)
+    skipped_num = 0
 
-    for res, analyzer_type in results:
-        if res == 0:
-            successful_analysis[analyzer_type] += 1
+    for res, skipped, analyzer_type in results:
+        if skipped:
+            skipped_num += 1
         else:
-            failed_analisys[analyzer_type] += 1
+            if res == 0:
+                successful_analysis[analyzer_type] += 1
+            else:
+                failed_analisys[analyzer_type] += 1
 
     LOG.info("----==== Summary ====----")
-    LOG.info('Total analyzed compilation commands: ' + str(len(results)))
+    LOG.info('Total compilation commands: ' + str(len(results)))
     if successful_analysis:
         LOG.info('Successfully analyzed')
         for analyzer_type, res in successful_analysis.iteritems():
@@ -47,6 +51,9 @@ def worker_result_handler(results):
         LOG.info("Failed to analyze")
         for analyzer_type, res in failed_analisys.iteritems():
             LOG.info('  ' + analyzer_type + ': ' + str(res))
+
+    if skipped_num:
+        LOG.info('Skipped compilation commands: ' + str(skipped_num))
     LOG.info("----=================----")
 
 def check(check_data):
@@ -62,6 +69,7 @@ def check(check_data):
     try:
         # if one analysis fails the check fails
         return_codes = 0
+        skipped = False
         for source in action.sources:
 
             # if there is no skiplist handler there was no skip list file
@@ -71,6 +79,7 @@ def check(check_data):
 
             if skp_handler and skp_handler.should_skip(source):
                 LOG.debug_analyzer(source_file_name + ' is skipped')
+                skipped = True
                 continue
 
             # construct analyzer env
@@ -120,7 +129,7 @@ def check(check_data):
             if not args.keep_tmp:
                 rh.clean_results()
 
-        return (return_codes, action.analyzer_type)
+        return (return_codes, skipped, action.analyzer_type)
 
     except Exception as e:
         LOG.debug_analyzer(str(e))
Repository: ericsson/codechecker
Issue: FilePath and FileId consistency in ReportDetails.executionPath

FilePath and FileId seems to be inconsistent when the path does not consist of only one file, but multiple files.


Changed files:
viewer_server/client_db_access_handler.py

diff --git a/viewer_server/client_db_access_handler.py b/viewer_server/client_db_access_handler.py
index 5cafea70..9503eff7 100644
--- a/viewer_server/client_db_access_handler.py
+++ b/viewer_server/client_db_access_handler.py
@@ -388,13 +388,14 @@ class ThriftRequestHandler():
 
         while event.next is not None:
 
+            event = session.query(BugPathEvent).get(event.next)
+
             file_path = file_path_cache.get(event.file_id)
             if not file_path:
                 f = session.query(File).get(event.file_id)
                 file_path = f.filepath
                 file_path_cache[event.file_id] = file_path
 
-            event = session.query(BugPathEvent).get(event.next)
             bug_events.append((event, file_path))
 
         return bug_events
@@ -418,13 +419,14 @@ class ThriftRequestHandler():
             bug_points.append((bug_point, file_path))
             while bug_point.next is not None:
 
+                bug_point = session.query(BugReportPoint).get(bug_point.next)
+
                 file_path = file_path_cache.get(bug_point.file_id)
                 if not file_path:
                     f = session.query(File).get(bug_point.file_id)
                     file_path = f.filepath
                     file_path_cache[bug_point.file_id] = file_path
 
-                bug_point = session.query(BugReportPoint).get(bug_point.next)
                 bug_points.append((bug_point, file_path))
 
         return bug_points
Repository: ericsson/codechecker
Issue: Getting report details takes a long time

When the report database is large, getting report details takes a long time and the report server uses gigabytes of memory.


Changed files:
viewer_server/client_db_access_handler.py

diff --git a/viewer_server/client_db_access_handler.py b/viewer_server/client_db_access_handler.py
index 38828d3a..b51b18cb 100644
--- a/viewer_server/client_db_access_handler.py
+++ b/viewer_server/client_db_access_handler.py
@@ -452,7 +452,7 @@ class ThriftRequestHandler():
                                         filePath=file_path))
 
             reportsToBuild = session.query(ReportsToBuildActions)\\
-                                .filter(ReportsToBuildActions.report_id == Report.id)
+                                .filter(ReportsToBuildActions.report_id == report.id)
 
             buildTargets = []
             if reportsToBuild:
Repository: ericsson/codechecker
Issue: Better skip file handling

A "bug" should be skipped if its path's last point/step should be skipped according to a skip file (given by --skip command line option).


Changed files:
codechecker_lib/analyzer.py, codechecker_lib/client.py

diff --git a/codechecker_lib/analyzer.py b/codechecker_lib/analyzer.py
index 6bae9a3d..2be3830b 100644
--- a/codechecker_lib/analyzer.py
+++ b/codechecker_lib/analyzer.py
@@ -193,9 +193,6 @@ def run(analyzer, action):
             sys.exit(os.EX_OK)
 
     signal.signal(signal.SIGINT, signal_handler)
-
-    LOG.info(id(analyzer))
-
     current_cmd = list(analyzer.cmd)
 
     for checker_name, enabled in analyzer.checkers:
diff --git a/codechecker_lib/client.py b/codechecker_lib/client.py
index 6f5a34bf..f72b2b13 100644
--- a/codechecker_lib/client.py
+++ b/codechecker_lib/client.py
@@ -51,28 +51,26 @@ def send_plist_content(connection, plist_file, build_action_id, run_id,
 
     report_ids = []
     for bug in bugs:
+        events = bug.events()
+        if events and should_skip(events[-1].start_pos.file_path):
+            # Issue #20: this bug is in a file which should be skipped
+            LOG.debug(bug.hash_value + ' is skipped (in ' +
+                      events[-1].start_pos.file_path + ")")
+            continue
+
         # create remaining data for bugs and send them to the server
         bug_paths = []
-        skip_bug = True
         for path in bug.paths():
-            if not should_skip(path.start_pos.file_path):
-                skip_bug = False
             bug_paths.append(shared.ttypes.BugPathPos(path.start_pos.line,
                 path.start_pos.col, path.end_pos.line, path.end_pos.col,
                 file_ids[path.start_pos.file_path]))
 
         bug_events = []
         for event in bug.events():
-            if not should_skip(event.start_pos.file_path):
-                skip_bug = False
             bug_events.append(shared.ttypes.BugPathEvent(event.start_pos.line,
                 event.start_pos.col, event.end_pos.line, event.end_pos.col,
                 event.msg, file_ids[event.start_pos.file_path]))
 
-        if skip_bug:
-            LOG.info(bug.hash_value + ' is skipped.')
-            continue
-
         bug_hash = bug.hash_value
         bug_hash_type = bug.hash_type
         LOG.debug('Bug hash: ' + bug_hash)
Repository: ericsson/codechecker
Issue: --verbose debug_analyzer does not print analysis calls

CodeChecker analyze ./TinyXML/build.json --analyzer clangsa -o tmp -c -j10 --add-compiler-defaults --verbose debug_analyzer

should print how the analyzers were invoked (invocation comannd line) and output the std error and stdout of the invocation.

Today it is only printed on --verbose debug log level



Changed files:
libcodechecker/analyze/analysis_manager.py, libcodechecker/analyze/analyzers/analyzer_base.py

diff --git a/libcodechecker/analyze/analysis_manager.py b/libcodechecker/analyze/analysis_manager.py
index 5bd7e4d9..05471b51 100644
--- a/libcodechecker/analyze/analysis_manager.py
+++ b/libcodechecker/analyze/analysis_manager.py
@@ -324,10 +324,16 @@ def check(check_data):
                         LOG.debug("[ZIP] Writing analyzer STDOUT to /stdout")
                         archive.writestr("stdout", rh.analyzer_stdout)
 
+                        if not quiet_output_on_stdout:
+                            LOG.debug_analyzer('\\n' + rh.analyzer_stdout)
+
                     if len(rh.analyzer_stderr) > 0:
                         LOG.debug("[ZIP] Writing analyzer STDERR to /stderr")
                         archive.writestr("stderr", rh.analyzer_stderr)
 
+                        if not quiet_output_on_stdout:
+                            LOG.debug_analyzer('\\n' + rh.analyzer_stderr)
+
                     LOG.debug("Generating dependent headers via compiler...")
                     try:
                         dependencies = set(create_dependencies(rh.buildaction))
diff --git a/libcodechecker/analyze/analyzers/analyzer_base.py b/libcodechecker/analyze/analyzers/analyzer_base.py
index 2d8dbbeb..bf122c9e 100644
--- a/libcodechecker/analyze/analyzers/analyzer_base.py
+++ b/libcodechecker/analyze/analyzers/analyzer_base.py
@@ -93,7 +93,7 @@ class SourceAnalyzer(object):
         # Construct the analyzer cmd.
         analyzer_cmd = self.construct_analyzer_cmd(res_handler)
 
-        LOG.debug('\\n' + ' '.join(analyzer_cmd))
+        LOG.debug_analyzer('\\n' + ' '.join(analyzer_cmd))
 
         res_handler.analyzer_cmd = analyzer_cmd
         analyzer_cmd = ' '.join(analyzer_cmd)
Repository: ericsson/codechecker
Issue: Server should not start in case of incorrectly formated json file

I have a typo in my configuration file:
```
[WARNING] [10:13:23] {SESSION MANAGER} - session_manager.py:149 load_session_cfg() - No JSON object could be decoded
[WARNING] [10:13:23] {SESSION MANAGER} - session_manager.py:151 load_session_cfg() - Not valid user authentication file: /var/lib/jenkins/.codechecker/session_config.json

```

In that case, the server should not start:
* it is risky 
* this is clearly not what I want when I am making a mistake in the configuration


Changed files:
libcodechecker/session_manager.py, libcodechecker/server/server.py

diff --git a/libcodechecker/server/server.py b/libcodechecker/server/server.py
index 4b024e47..16661538 100644
--- a/libcodechecker/server/server.py
+++ b/libcodechecker/server/server.py
@@ -19,6 +19,7 @@ from random import sample
 import stat
 import socket
 import ssl
+import sys
 import urllib
 
 try:
@@ -748,6 +749,12 @@ def start_server(config_directory, package_data, port, db_conn_string,
                      .format(root_file))
             root_sha = __make_root_file(root_file)
 
+    try:
+        manager = session_manager.SessionManager(root_sha, force_auth)
+    except IOError, ValueError:
+        LOG.error("The server's authentication config file is invalid!")
+        sys.exit(1)
+
     http_server = CCSimpleHttpServer(server_addr,
                                      RequestHandler,
                                      config_directory,
@@ -757,9 +764,7 @@ def start_server(config_directory, package_data, port, db_conn_string,
                                      suppress_handler,
                                      context,
                                      check_env,
-                                     session_manager.SessionManager(
-                                         root_sha, force_auth)
-                                     )
+                                     manager)
 
     try:
         instance_manager.register(os.getpid(),
diff --git a/libcodechecker/session_manager.py b/libcodechecker/session_manager.py
index 7e074e01..95580992 100644
--- a/libcodechecker/session_manager.py
+++ b/libcodechecker/session_manager.py
@@ -145,10 +145,12 @@ def load_session_cfg(session_cfg_file):
     except IOError:
         LOG.debug('Failed to open user authentication file: ' +
                   session_cfg_file)
+        raise
     except ValueError as verr:
         LOG.warning(verr)
         LOG.warning('Not valid user authentication file: ' +
                     session_cfg_file)
+        raise
 
     return scfg_dict
 
@@ -442,7 +444,11 @@ class SessionManager_Client:
                                         ".codechecker.passwords.json")
         LOG.debug(session_cfg_file)
 
-        scfg_dict = load_session_cfg(session_cfg_file)
+        try:
+            scfg_dict = load_session_cfg(session_cfg_file)
+        except (IOError, ValueError):
+            # On the client's side, continue execution with defaults.
+            scfg_dict = {}
 
         if not scfg_dict.get("credentials"):
             scfg_dict["credentials"] = {}
Repository: ericsson/codechecker
Issue: --enable-all with other options doesn't run most of the clang-tidy checkers

I am running the command:
`CodeChecker check -j 13 -b "hg pull -u && hg update -r default && ./mach build -j 23" -o codechecker-results --enable-all --enable alpha --disable google-readability-casting --disable llvm-include-order --disable google-readability-braces-around-statements
`

Unfortunately, with this serie of enable/disable, most of the clang-tidy checkers are not executed.

Changed files:
libcodechecker/libhandlers/check.py

diff --git a/libcodechecker/libhandlers/check.py b/libcodechecker/libhandlers/check.py
index da5a2e91..9cc13c25 100644
--- a/libcodechecker/libhandlers/check.py
+++ b/libcodechecker/libhandlers/check.py
@@ -439,6 +439,7 @@ def main(args):
                           'capture_analysis_output',
                           'ctu_phases',
                           'ctu_in_memory',
+                          'enable_all',
                           'ordered_checkers'  # --enable and --disable.
                           ]
         for key in args_to_update:
Repository: ericsson/codechecker
Issue: cmd sum only for specified runs

Get statistics only for specified runs if run names are given for the cmd sum.

Changed files:
libcodechecker/cmd/cmd_line_client.py

diff --git a/libcodechecker/cmd/cmd_line_client.py b/libcodechecker/cmd/cmd_line_client.py
index 36ca241d..397ac37a 100644
--- a/libcodechecker/cmd/cmd_line_client.py
+++ b/libcodechecker/cmd/cmd_line_client.py
@@ -41,7 +41,11 @@ def check_run_names(client, check_names):
     maps run names to runs. The dictionary contains only the runs in
     check_names or all runs if check_names is empty or None.
     """
-    run_info = {run.name: run for run in client.getRunData(None)}
+    run_filter = ttypes.RunFilter()
+    run_filter.names = check_names
+    run_filter.exactMatch = check_names is not None
+
+    run_info = {run.name: run for run in client.getRunData(run_filter)}
 
     if not check_names:
         return run_info
Repository: ericsson/codechecker
Issue: CodeChecker cmd diff --new shows resolved results

CodeChecker cmd diff, when called with --new should only show bug with unresolved, new, reopened status.

Changed files:
libcodechecker/cmd/cmd_line_client.py

diff --git a/libcodechecker/cmd/cmd_line_client.py b/libcodechecker/cmd/cmd_line_client.py
index 055ff7a0..2ab27eb3 100644
--- a/libcodechecker/cmd/cmd_line_client.py
+++ b/libcodechecker/cmd/cmd_line_client.py
@@ -168,6 +168,14 @@ def handle_diff_results(args):
 
         report_filter = ttypes.ReportFilter()
         add_filter_conditions(report_filter, args.filter)
+
+        # Do not show resolved bugs in compare mode new.
+        if cmp_data.diffType == ttypes.DiffType.NEW:
+            report_filter.detectionStatus = [
+                ttypes.DetectionStatus.NEW,
+                ttypes.DetectionStatus.UNRESOLVED,
+                ttypes.DetectionStatus.REOPENED]
+
         sort_mode = [(ttypes.SortMode(
             ttypes.SortType.FILENAME,
             ttypes.Order.ASC))]
Repository: ericsson/codechecker
Issue: CodeChecker store fails (sqlite)

Git tag information    : 6.0.1-8-ga3d8f81   
I am using sqlite. My system: Ubuntu 17.04

I ran the command:
`CodeChecker check -b "make clean;make" -o "/home/peters/codechecker_results"`
which worked fine. At least some .plist files two .json and one .json.lock file have been created in the directory ~/codechecker_results

Then I tried:
`CodeChecker store /home/peters/codechecker_results/ -n test`
which failed with the following error message:
`[13:25] - Storing analysis results for run 'test'`
`[13:25] - Storage failed: 'unicode' does not have the buffer interface`

I executed the store-command with the verbose debug option turned on, which then returns the following log messages:
[store.log](https://github.com/Ericsson/codechecker/files/1362532/store.log)


Changed files:
libcodechecker/libhandlers/store.py

diff --git a/libcodechecker/libhandlers/store.py b/libcodechecker/libhandlers/store.py
index ab7f45a4..40faea33 100644
--- a/libcodechecker/libhandlers/store.py
+++ b/libcodechecker/libhandlers/store.py
@@ -322,7 +322,7 @@ def main(args):
 
         client.massStoreRun(args.name,
                             args.tag if 'tag' in args else None,
-                            context.version,
+                            str(context.version),
                             b64zip,
                             'force' in args)
Repository: ericsson/codechecker
Issue: Analysis runs show the *store* duration

In the database, the duration of the `store` call is saved. Instead, we should use the check durations available in the `metadata.json`.

Or either add the duration of store to the duration of the analysis, but I believe it's the analysis length which could matter to users.

Thanks to @bruntib, storage is blazing fast anyways.

Changed files:
libcodechecker/libhandlers/store.py, libcodechecker/server/run_db_model.py, libcodechecker/analyze/store_handler.py

diff --git a/libcodechecker/analyze/store_handler.py b/libcodechecker/analyze/store_handler.py
index 452c8ff4..0c26b73e 100644
--- a/libcodechecker/analyze/store_handler.py
+++ b/libcodechecker/analyze/store_handler.py
@@ -239,8 +239,8 @@ def addCheckerRun(session, storage_session, command, name, tag, username,
         elif run:
             # There is already a run, update the results.
             run.date = datetime.now()
-            # Increment update counter and the command.
             run.command = command
+            run.duration = -1
             session.flush()
             run_id = run.id
         else:
diff --git a/libcodechecker/libhandlers/store.py b/libcodechecker/libhandlers/store.py
index 5022806e..ab7f45a4 100644
--- a/libcodechecker/libhandlers/store.py
+++ b/libcodechecker/libhandlers/store.py
@@ -231,6 +231,8 @@ def assemble_zip(inputs, zip_file, client):
                         LOG.warning("Skipping '{0}' because it contains "
                                     "a missing source file."
                                     .format(plist_file))
+                elif f == 'metadata.json':
+                    zipf.write(plist_file, os.path.join('reports', f))
 
         necessary_hashes = client.getMissingContentHashes(hash_to_file.keys())
         for f, h in file_to_hash.items():
diff --git a/libcodechecker/server/run_db_model.py b/libcodechecker/server/run_db_model.py
index 61bdbc8b..32929f82 100644
--- a/libcodechecker/server/run_db_model.py
+++ b/libcodechecker/server/run_db_model.py
@@ -64,7 +64,8 @@ class Run(Base):
         self.duration = -1
 
     def mark_finished(self):
-        self.duration = ceil((datetime.now() - self.date).total_seconds())
+        if self.duration == -1:
+            self.duration = ceil((datetime.now() - self.date).total_seconds())
 
 
 class RunHistory(Base):
Repository: ericsson/codechecker
Issue: add-compiler-defaults problems


- [ ]  --add-compiler-defaults option should cut out the "sysroot" arg from the original build action and call the cross compiler detection in (log_parser.py)

- [ ]  auto-detected include paths should be added by -isystem to clang (instead of -I) to get at the end of the inclusion list

- [ ] clang tidy does not get the auto-detected target and include pahts, however it should


Changed files:
libcodechecker/analyze/log_parser.py, libcodechecker/log/option_parser.py, libcodechecker/analyze/analyzers/analyzer_clang_tidy.py

diff --git a/libcodechecker/analyze/analyzers/analyzer_clang_tidy.py b/libcodechecker/analyze/analyzers/analyzer_clang_tidy.py
index 87b2f63f..e1e1108f 100644
--- a/libcodechecker/analyze/analyzers/analyzer_clang_tidy.py
+++ b/libcodechecker/analyze/analyzers/analyzer_clang_tidy.py
@@ -111,6 +111,8 @@ class ClangTidy(analyzer_base.SourceAnalyzer):
 
             analyzer_cmd.extend(self.buildaction.analyzer_options)
 
+            analyzer_cmd.extend(self.buildaction.compiler_includes)
+
             return analyzer_cmd
 
         except Exception as ex:
diff --git a/libcodechecker/analyze/log_parser.py b/libcodechecker/analyze/log_parser.py
index f41a29ff..521f4b99 100644
--- a/libcodechecker/analyze/log_parser.py
+++ b/libcodechecker/analyze/log_parser.py
@@ -62,7 +62,7 @@ def get_compiler_includes(compiler, lang, compile_opts, extra_opts=None):
             if line.startswith(end_mark):
                 do_append = False
             if do_append:
-                include_paths.append("-I" + line)
+                include_paths.append("-isystem " + line)
             if line.startswith(start_mark):
                 do_append = True
 
diff --git a/libcodechecker/log/option_parser.py b/libcodechecker/log/option_parser.py
index dddc307b..8a19324b 100644
--- a/libcodechecker/log/option_parser.py
+++ b/libcodechecker/log/option_parser.py
@@ -52,7 +52,8 @@ COMPILE_OPTION_MAP_REGEX = {
     '^-f.*': 0,
     '-m.*': 0,
     '^-Wno-.*': 0,
-    '^-m(32|64)$': 0
+    '^-m(32|64)$': 0,
+    '^--sysroot=': 0
 }
 
 # Linker options.
Repository: ericsson/codechecker
Issue: server start failed with default sqlite database

CodeChecker server -w workspace command fails if the workspace directory does not exists.


Changed files:
codechecker_lib/arg_handler.py

diff --git a/codechecker_lib/arg_handler.py b/codechecker_lib/arg_handler.py
index 1ed7c5fb..8b60d29f 100644
--- a/codechecker_lib/arg_handler.py
+++ b/codechecker_lib/arg_handler.py
@@ -98,6 +98,8 @@ def handle_server(args):
     if not args.workspace and util.is_localhost(args.dbaddress):
         LOG.info("Workspace is required when database server run on localhost.")
         sys.exit(1)
+    elif args.workspace and not os.path.exists(args.workspace):
+        os.makedirs(args.workspace)
 
     if args.suppress is None:
         LOG.warning('WARNING! No suppress file was given, suppressed results will be only stored in the database.')
Repository: ericsson/codechecker
Issue: handle alembic exception

Alembic might throw an CommandError exception if an older CodeChecker tries to connect to a database with a newer db schema in it.
Handle alembic errors in the [database_handler.py](https://github.com/Ericsson/codechecker/blob/03fd2a04fe8bfad4c56d586130efcbcc6955a440/codechecker_lib/database_handler.py#L64) while trying to create or migrate the database schema.


Changed files:
codechecker_lib/database_handler.py

diff --git a/codechecker_lib/database_handler.py b/codechecker_lib/database_handler.py
index 3eb4f111..a842a737 100644
--- a/codechecker_lib/database_handler.py
+++ b/codechecker_lib/database_handler.py
@@ -15,6 +15,7 @@ import time
 from abc import ABCMeta, abstractmethod
 
 import sqlalchemy
+from alembic.util import CommandError
 from alembic import command, config
 from sqlalchemy import event
 from sqlalchemy.engine import Engine
@@ -96,6 +97,11 @@ class SQLServer(object):
         except sqlalchemy.exc.SQLAlchemyError as alch_err:
             LOG.error(str(alch_err))
             sys.exit(1)
+        except CommandError as cerr:
+            LOG.error("Database schema and CodeChecker is incompatible."
+                      "Please update CodeChecker.")
+            LOG.debug(str(cerr))
+            sys.exit(1)
 
     @abstractmethod
     def start(self, db_version_info, wait_for_start=True, init=False):
Repository: ericsson/codechecker
Issue: Buggy 'CodeChecker parse --print-steps' filename outputs when a report is ranging across TUs.

**Describe the bug**
'CodeChecker parse --print-steps' prints incorrect filenames for some report steps when the report ranges across multiple translation units. Specifically, all the filenames are assumed to be the same as the first step's filename.

**CodeChecker version**
```
CodeChecker analyzer version:
---------------------------------------------------------------
Kind                 | Version
---------------------------------------------------------------
Base package version | 6.10.1
Package build date   | 2019-08-29T17:09
Git commit ID (hash) | 400ec527568fdfee5e4f02d1384d408bac2745b4
Git tag information  | 6.10.1
---------------------------------------------------------------
```

**Possible bug fix**
```
243                     for index, event in enumerate(events): 
244                         output.write(index_format % (index + 1))        
245                         source_file = report.files[event['location']['file']]    
246                         # patched (begin)                                                                     
247                         trimmed_source_file = \\    
248                             util.trim_path_prefixes(source_file,             
249                                                     self._trim_path_prefixes)   
250                         # patched (end)            
251                         output.write(       
252                             self.__format_bug_event(None,         
253                                                     None,         
254                                                     event,           
255                                                     trimmed_source_file))     
```            
Modifying `analyzer/codechecker_analyzer/cmd/parse.py` as above by adding Line 247~249 resolved the problem.


Changed files:
analyzer/codechecker_analyzer/cmd/parse.py

diff --git a/analyzer/codechecker_analyzer/cmd/parse.py b/analyzer/codechecker_analyzer/cmd/parse.py
index e31ca85d..21ce7822 100644
--- a/analyzer/codechecker_analyzer/cmd/parse.py
+++ b/analyzer/codechecker_analyzer/cmd/parse.py
@@ -243,6 +243,9 @@ class PlistToPlaintextFormatter(object):
                     for index, event in enumerate(events):
                         output.write(index_format % (index + 1))
                         source_file = report.files[event['location']['file']]
+                        trimmed_source_file = \\
+                            util.trim_path_prefixes(source_file,
+                                                    self._trim_path_prefixes)
                         output.write(
                             self.__format_bug_event(None,
                                                     None,
Repository: ericsson/codechecker
Issue: When many products are added (>30) the product list page takes ~6s to load 

Try to reduce this time.

Measured with CodeChecker 6.7.1, postgresql

Changed files:
libcodechecker/server/server.py

diff --git a/libcodechecker/server/server.py b/libcodechecker/server/server.py
index a2692122..1d76d060 100644
--- a/libcodechecker/server/server.py
+++ b/libcodechecker/server/server.py
@@ -560,7 +560,7 @@ class Product(object):
         Initiates the actual connection to the database configured for the
         product.
 
-        Eeach time the connect is called the db_status is updated.
+        Each time the connect is called the db_status is updated.
         """
 
         LOG.debug("Checking '{0}' database.".
@@ -580,7 +580,6 @@ class Product(object):
 
         try:
             LOG.debug("Trying to connect to the database")
-            db_status = sql_server.connect()
 
             # Create the SQLAlchemy engine.
             self.__engine = sql_server.create_engine()
@@ -589,7 +588,7 @@ class Product(object):
             self.__session = sessionmaker(bind=self.__engine)
 
             self.__engine.execute('SELECT 1')
-            self.__db_status = db_status
+            self.__db_status = sql_server.check_schema()
             self.__last_connect_attempt = None
 
             if self.__db_status == DBStatus.SCHEMA_MISSING and init_db:
Repository: ericsson/codechecker
Issue: store --force does not work

[INFO 2018-11-06 10:00] - Storing analysis results for run 'TinyXML'
[INFO 2018-11-06 10:00] - argument --force was specified: the run with name 'TinyXML' will be deleted.
[ERROR 2018-11-06 10:00] - API call error: massStoreRun
[ERROR 2018-11-06 10:00] - RequestFailed(errorCode=2, extraInfo=None, _message='(psycopg2.IntegrityError) duplicate key value violates unique constraint "uq_runs_name"\\nDETAIL:  Key (name)=(TinyXML) already exists.\\n [SQL: \\'INSERT INTO runs (date, duration, name, version, command, can_delete) VALUES (%(date)s, %(duration)s, %(name)s, %(version)s, %(command)s, %(can_delete)s) RETURNING runs.id\\'] [parameters: {\\'name\\': \\'TinyXML\\', \\'duration\\': -1, \\'version\\': \\'6.8.1\\', \\'command\\': u\\'/home/compass/srv/CodeCheckerv6/workspace/install/CodeChecker/cc_bin/CodeChecker.py analyze -e sensitive /home/compass/srv/CodeCheckerv6/source/tinyxml2-6.2.0/build/compile_commands.json -j24 -o /home/compass/srv/CodeCheckerv6/workspace/reports\\', \\'can_delete\\': True, \\'date\\': datetime.datetime(2018, 11, 6, 10, 0, 3, 873541)}]')


Changed files:
libcodechecker/server/api/store_handler.py

diff --git a/libcodechecker/server/api/store_handler.py b/libcodechecker/server/api/store_handler.py
index c8405d4c..08ebc9fd 100644
--- a/libcodechecker/server/api/store_handler.py
+++ b/libcodechecker/server/api/store_handler.py
@@ -229,6 +229,9 @@ def addCheckerRun(session, command, name, tag, username,
 
             LOG.info('Removing previous analysis results ...')
             session.delete(run)
+            # Not flushing after delete leads to a constraint violation error
+            # later, when adding run entity with the same name as the old one.
+            session.flush()
 
             checker_run = Run(name, version, command)
             session.add(checker_run)
Repository: ericsson/codechecker
Issue: [CTU] Compiler default C++ dialect is not added when generating the PCH files

**Describe the bug**
Compiler default C++ dialect is added to the analyzer command, but it is not added to the compiler invocation which generates the PCH ast files.
This causes C++ language dialect mismatches and consequently false positive ODR errors during CTU analysis.

**CodeChecker version**
All

**To Reproduce**
Steps to reproduce the behavior
0. Apply this patch:
```
diff --git a/lib/CrossTU/CrossTranslationUnit.cpp b/lib/CrossTU/CrossTranslationUnit.cpp
index 4423fed..d15cc85 100644
--- a/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/lib/CrossTU/CrossTranslationUnit.cpp
@@ -342,6 +342,7 @@ CrossTranslationUnitContext::importDefinition(const FunctionDecl *FD) {
                     [&](const ImportError &IE) {
                       switch (IE.Error) {
                       case ImportError::NameConflict:
+                        llvm_unreachable("NameConflict");
                         ++NumNameConflicts;
                         break;
                       case ImportError::UnsupportedConstruct:
```
1. Ctu analyse bitcoin with gcc5 on Ubuntu 16.04 with boost 1.65
    This will create a PCH file for univalue.cpp with the default C++ dialect, which is C++14 in case of Clang7.
2. Analyse the univalue_get.cpp file (which has gnu++98 set). This loads `univalue.cpp.ast` and there we have the mismatch (and unreachable fires).


Changed files:
libcodechecker/analyze/analyzers/ctu_triple_arch.py

diff --git a/libcodechecker/analyze/analyzers/ctu_triple_arch.py b/libcodechecker/analyze/analyzers/ctu_triple_arch.py
index 9c8a45df..24dad8f7 100644
--- a/libcodechecker/analyze/analyzers/ctu_triple_arch.py
+++ b/libcodechecker/analyze/analyzers/ctu_triple_arch.py
@@ -35,6 +35,10 @@ def get_compile_command(action, config, source='', output=''):
         cmd.extend(['-o', output])
     if source:
         cmd.append(source)
+
+    if all(not opt.startswith('-std=') for opt in action.analyzer_options):
+        cmd.append(action.compiler_standard)
+
     return cmd
Repository: ericsson/codechecker
Issue: checker profiles cannot be listed does not list the available profiles

**Describe the bug**
CodeChecker checkers --profile list 
does not list the available profiles. Returns with an empty list.

In earlier versions it returned this:
/6.11.1/CodeChecker/bin/CodeChecker checkers --profile list
 default
 sensitive
 security
 portability
 extreme




**CodeChecker version**
CodeChecker analyzer version:
---------------------------------------------------------------
Kind                 | Version
---------------------------------------------------------------
Base package version | 6.12.0
Package build date   | 2020-05-11T22:04
Git commit ID (hash) | 24c0414c8f5250ce81534d43d9cf64b9b07a430e
Git tag information  | 6.12
---------------------------------------------------------------

CodeChecker web version:
------------------------------------------------------------------------
Kind                          | Version
------------------------------------------------------------------------
Base package version          | 6.12.0
Package build date            | 2020-05-11T22:04
Git commit ID (hash)          | 24c0414c8f5250ce81534d43d9cf64b9b07a430e
Git tag information           | 6.12
Server supported API (Thrift) | 6.26
Client API (Thrift)           | 6.26



Changed files:
analyzer/codechecker_analyzer/cmd/checkers.py, analyzer/tests/functional/cmdline/test_cmdline.py

diff --git a/analyzer/codechecker_analyzer/cmd/checkers.py b/analyzer/codechecker_analyzer/cmd/checkers.py
index 50575eb3..82fe1863 100644
--- a/analyzer/codechecker_analyzer/cmd/checkers.py
+++ b/analyzer/codechecker_analyzer/cmd/checkers.py
@@ -209,7 +209,7 @@ def main(args):
             rows = context.available_profiles.items()
         else:
             header = ['Profile name']
-            rows = ([key] for key in context.available_profiles.keys())
+            rows = [(key, "") for key in context.available_profiles.keys()]
 
         if args.output_format in ['csv', 'json']:
             header = list(map(uglify, header))
diff --git a/analyzer/tests/functional/cmdline/test_cmdline.py b/analyzer/tests/functional/cmdline/test_cmdline.py
index 82f786ee..7baca598 100644
--- a/analyzer/tests/functional/cmdline/test_cmdline.py
+++ b/analyzer/tests/functional/cmdline/test_cmdline.py
@@ -88,6 +88,14 @@ class TestCmdline(unittest.TestCase):
         checkers_cmd = [env.codechecker_cmd(), 'checkers']
         self.assertEqual(0, run_cmd(checkers_cmd)[0])
 
+    def test_checkers_profile(self):
+        """ Listing available checker profiles. """
+
+        checkers_cmd = [env.codechecker_cmd(), 'checkers', '--profile', 'list']
+        out = run_cmd(checkers_cmd)
+        self.assertEqual(0, out[0])
+        self.assertEqual(True, "default" in out[1])
+
     def test_analyzers(self):
         """ Listing available analyzers. """
Repository: ericsson/codechecker
Issue: Crash when relative path is given for SQLite db

```
(venv) xazax@cc:~/Checker_Xerces$ CodeChecker server --sqlite db.sqlite --not-host-only -v 15010
Traceback (most recent call last):
  File "/mnt/storage/xazax/Checker_Xerces/codechecker/build/CodeChecker/cc_bin/CodeChecker.py", line 101, in main
    args.func(args)
  File "/mnt/storage/xazax/Checker_Xerces/codechecker/build/CodeChecker/lib/python2.7/libcodechecker/libhandlers/server.py", line 332, in __handle
    main(args)
  File "/mnt/storage/xazax/Checker_Xerces/codechecker/build/CodeChecker/lib/python2.7/libcodechecker/libhandlers/server.py", line 414, in main
    os.makedirs(os.path.dirname(args.sqlite))
  File "/mnt/storage/xazax/Checker_Xerces/codechecker/venv/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 2] No such file or directory: ''
```
Also, default product is not created. Is this bug or intended?

Changed files:
web/server/codechecker_server/cmd/server.py

diff --git a/web/server/codechecker_server/cmd/server.py b/web/server/codechecker_server/cmd/server.py
index 10236f47..23b85b0c 100644
--- a/web/server/codechecker_server/cmd/server.py
+++ b/web/server/codechecker_server/cmd/server.py
@@ -394,6 +394,10 @@ def add_arguments_to_parser(parser):
             args.sqlite = args.sqlite.replace('<CONFIG_DIRECTORY>',
                                               args.config_directory)
 
+        # Convert relative sqlite file path to absolute.
+        if 'sqlite' in args:
+            args.sqlite = os.path.abspath(args.sqlite)
+
         if 'postgresql' not in args:
             # Later called database modules need the argument to be actually
             # present, even though the default is suppressed in the optstring.
Repository: ericsson/codechecker
Issue: Empty CodeChecker invocation triggers error

**Describe the bug**
```
(venv) xazax@cc:~/codechecker/build/CodeChecker/bin$ CodeChecker
Traceback (most recent call last):
  File "/home/xazax/codechecker/build/CodeChecker/cc_bin/CodeChecker.py", line 127, in main
    args.func(args)
AttributeError: 'Namespace' object has no attribute 'func'
```

**CodeChecker version**
```
CodeChecker analyzer version:
---------------------------------------------------------------
Kind                 | Version
---------------------------------------------------------------
Base package version | 6.12.0
Package build date   | 2020-03-05T11:46
Git commit ID (hash) | bc8e63c611af937e6ac2b9f747279136bd3eb5e7
Git tag information  | 6.12
---------------------------------------------------------------

CodeChecker web version:
------------------------------------------------------------------------
Kind                          | Version
------------------------------------------------------------------------
Base package version          | 6.12.0
Package build date            | 2020-03-05T11:46
Git commit ID (hash)          | bc8e63c611af937e6ac2b9f747279136bd3eb5e7
Git tag information           | 6.12
Server supported API (Thrift) | 6.26
Client API (Thrift)           | 6.26
------------------------------------------------------------------------
```

**To Reproduce**
See the invocation above.

**Expected behaviour**
Print the help text.

**Desktop (please complete the following information)**
 - OS: Linux
 - Browser: Not applicable
 - Version: Version of what? Template needs to be clarified.

**Additional context**
No additiona context.



Changed files:
analyzer/tests/functional/cmdline/test_cmdline.py, bin/CodeChecker.py

diff --git a/analyzer/tests/functional/cmdline/test_cmdline.py b/analyzer/tests/functional/cmdline/test_cmdline.py
index 8c5e25c5..8f60c2ae 100644
--- a/analyzer/tests/functional/cmdline/test_cmdline.py
+++ b/analyzer/tests/functional/cmdline/test_cmdline.py
@@ -46,6 +46,12 @@ class TestCmdline(unittest.TestCase):
         # Get the CodeChecker cmd if needed for the tests.
         self._codechecker_cmd = env.codechecker_cmd()
 
+    def test_no_subcommand(self):
+        """ Call CodeChecker without subcommand. """
+
+        main_cmd = [env.codechecker_cmd()]
+        self.assertEqual(0, run_cmd(main_cmd)[0])
+
     def test_version_help(self):
         """ Test the 'analyzer-version' subcommand. """
 
diff --git a/bin/CodeChecker.py b/bin/CodeChecker.py
index 1c410441..4089d2fd 100755
--- a/bin/CodeChecker.py
+++ b/bin/CodeChecker.py
@@ -124,7 +124,10 @@ output.
                 sys.argv.extend(cfg_args)
                 args = parser.parse_args()
 
-        args.func(args)
+        try:
+            args.func(args)
+        except AttributeError:
+            parser.print_help()
 
     except KeyboardInterrupt as kb_err:
         print(str(kb_err))