Skip to content

Commit

Permalink
Merge pull request #4030 from Szelethus/gcc_analyzer_native_support
Browse files Browse the repository at this point in the history
Gcc analyzer native support
  • Loading branch information
bruntib authored Oct 16, 2023
2 parents 0a3cc8b + 0ceff53 commit bb3baa5
Show file tree
Hide file tree
Showing 25 changed files with 785 additions and 34 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main' -y
# Required for g++-13, as the latest LTS at the time of this change hasn't made it available.
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test

sudo apt-get update -q

sudo apt-get install \
g++-9 \
g++-13 \
gcc-multilib \
libc6-dev-i386 \
libpq-dev \
Expand All @@ -20,3 +22,4 @@ sudo apt-get install \
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-14 9999
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-14 9999
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-14 9999
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 9999
4 changes: 2 additions & 2 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ jobs:
- name: "Install run-time dependencies (Linux)"
if: ${{ matrix.os == 'ubuntu-20.04' }}
run:
sudo apt-get update && sudo apt-get install g++ clang clang-tidy cppcheck
sudo apt-get update && sudo apt-get install g++-13 clang clang-tidy cppcheck

- name: "Install run-time dependencies (OSX)"
if: ${{ matrix.os == 'macos-10.15' }}
run:
brew install llvm cppcheck
brew install llvm cppcheck g++-13

- name: "Install run-time dependencies (Windows)"
if: ${{ matrix.os == 'windows-2019' }}
Expand Down
11 changes: 8 additions & 3 deletions analyzer/codechecker_analyzer/analyzers/analyzer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import sys
import shlex

from typing import Optional

from codechecker_analyzer import analyzer_context
from codechecker_common.logger import get_logger

Expand Down Expand Up @@ -55,11 +57,14 @@ def resolve_missing_binary(cls, configured_binary, environ):
raise NotImplementedError("Subclasses should implement this!")

@classmethod
def version_compatible(cls, configured_binary, environ):
def is_binary_version_incompatible(cls, configured_binary, environ) \
-> Optional[str]:
"""
CodeChecker can only execute certain versions of analyzers.
This function should return True if the analyzer binary is
compatible with the current CodeChecker version.
Returns a error object (an optional string). If the return value is
None, the analyzer binary is compatible with the current CodeChecker
version. Otherwise, the it should be a message describing the precise
version mismatch.
"""
raise NotImplementedError("Subclasses should implement this!")

Expand Down
14 changes: 10 additions & 4 deletions analyzer/codechecker_analyzer/analyzers/analyzer_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
from .clangtidy.analyzer import ClangTidy
from .clangsa.analyzer import ClangSA
from .cppcheck.analyzer import Cppcheck
from .gcc.analyzer import Gcc

LOG = get_logger('analyzer')

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


def is_ctu_capable():
Expand Down Expand Up @@ -184,9 +186,11 @@ def check_supported_analyzers(analyzers):
# Check version compatibility of the analyzer binary.
if analyzer_bin:
analyzer = supported_analyzers[analyzer_name]
if not analyzer.version_compatible(analyzer_bin, check_env):
error = analyzer.is_binary_version_incompatible(analyzer_bin,
check_env)
if error:
failed_analyzers.add((analyzer_name,
"Incompatible version."))
f"Incompatible version: {error}"))
available_analyzer = False

if not analyzer_bin or \
Expand Down Expand Up @@ -219,7 +223,9 @@ def construct_analyzer(buildaction,

except Exception as ex:
LOG.debug_analyzer(ex)
return None
# We should've detected well before this point that something is off
# with the analyzer. We can't recover here.
raise


def build_config_handlers(args, enabled_analyzers):
Expand Down
6 changes: 3 additions & 3 deletions analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,11 @@ def resolve_missing_binary(cls, configured_binary, environ):
return clang

@classmethod
def version_compatible(cls, configured_binary, environ):
def is_binary_version_incompatible(cls, configured_binary, environ):
"""
Check the version compatibility of the given analyzer binary.
We support pretty much every ClangSA version.
"""
return True
return None

def construct_result_handler(self, buildaction, report_output,
skiplist_handler):
Expand Down
6 changes: 3 additions & 3 deletions analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,11 @@ def resolve_missing_binary(cls, configured_binary, environ):
return clangtidy

@classmethod
def version_compatible(cls, configured_binary, environ):
def is_binary_version_incompatible(cls, configured_binary, environ):
"""
Check the version compatibility of the given analyzer binary.
We support pretty much every Clang-Tidy version.
"""
return True
return None

def construct_result_handler(self, buildaction, report_output,
skiplist_handler):
Expand Down
7 changes: 4 additions & 3 deletions analyzer/codechecker_analyzer/analyzers/cppcheck/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def __get_analyzer_version(cls, analyzer_binary, env):
return []

@classmethod
def version_compatible(cls, configured_binary, environ):
def is_binary_version_incompatible(cls, configured_binary, environ):
"""
Check the version compatibility of the given analyzer binary.
"""
Expand All @@ -361,9 +361,10 @@ def version_compatible(cls, configured_binary, environ):
# The analyzer version should be above 1.80 because '--plist-output'
# argument was introduced in this release.
if analyzer_version >= StrictVersion("1.80"):
return True
return None

return False
return "CppCheck binary found is too old at " \
f"v{str(analyzer_version).strip()}; minimum version is 1.80"

def construct_result_handler(self, buildaction, report_output,
skiplist_handler):
Expand Down
7 changes: 7 additions & 0 deletions analyzer/codechecker_analyzer/analyzers/gcc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -------------------------------------------------------------------------
#
# Part of the CodeChecker project, under the Apache License v2.0 with
# LLVM Exceptions. See LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------
Loading

0 comments on commit bb3baa5

Please sign in to comment.