Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#126]: Update tools and ubuntu image #127

Merged
merged 9 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,3 @@ jobs:
extra-mypy-options: "--ignore-missing-imports --show-error-codes"
extra-flake8-options: "--max-line-length=120 --ignore=E203,E402"
extra-pycodestyle-options: "--max-line-length=120 --ignore=E203,E402"


4 changes: 3 additions & 1 deletion .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
uses: ludeeus/action-shellcheck@master
with:
ignore_names: llvm.sh # External file
1 change: 0 additions & 1 deletion .github/workflows/test_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,3 @@ jobs:

***
### [Result for pull_request_target (non CMake)](https://github.com/JacobDomagala/TestRepo/pull/7#issuecomment-1404101648)

2 changes: 0 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ jobs:
- name: Test with pytest
run: |
pytest


6 changes: 3 additions & 3 deletions docker/static_analysis.dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM ubuntu:23.04 as base
FROM ubuntu:24.04 AS base

# Define versions as environment variables
ENV CLANG_VERSION=18 \
CPPCHECK_VERSION=2.14.0 \
ENV CLANG_VERSION=20 \
CPPCHECK_VERSION=2.16.0 \
CXX=clang++ \
CC=clang \
DEBIAN_FRONTEND=noninteractive
Expand Down
8 changes: 4 additions & 4 deletions entrypoint_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ else
cat cppcheck_*.txt > cppcheck.txt

# Excludes for clang-tidy are handled in python script
debug_print "Running run-clang-tidy-18 $CLANG_TIDY_ARGS -p $(pwd) $files_to_check >>clang_tidy.txt 2>&1"
eval run-clang-tidy-18 "$CLANG_TIDY_ARGS" -p "$(pwd)" "$files_to_check" >clang_tidy.txt 2>&1 || true
debug_print "Running run-clang-tidy-20 $CLANG_TIDY_ARGS -p $(pwd) $files_to_check >>clang_tidy.txt 2>&1"
eval run-clang-tidy-20 "$CLANG_TIDY_ARGS" -p "$(pwd)" "$files_to_check" >clang_tidy.txt 2>&1 || true

else
# Excludes for clang-tidy are handled in python script
debug_print "Running cppcheck -j $num_proc $files_to_check $CPPCHECK_ARGS --output-file=cppcheck.txt ..."
eval cppcheck -j "$num_proc" "$files_to_check" "$CPPCHECK_ARGS" --output-file=cppcheck.txt || true

debug_print "Running run-clang-tidy-18 $CLANG_TIDY_ARGS $files_to_check >>clang_tidy.txt 2>&1"
eval run-clang-tidy-18 "$CLANG_TIDY_ARGS" "$files_to_check" >clang_tidy.txt 2>&1 || true
debug_print "Running run-clang-tidy-20 $CLANG_TIDY_ARGS $files_to_check >>clang_tidy.txt 2>&1"
eval run-clang-tidy-20 "$CLANG_TIDY_ARGS" "$files_to_check" >clang_tidy.txt 2>&1 || true
fi

cd /
Expand Down
40 changes: 29 additions & 11 deletions llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ BASE_URL="http://apt.llvm.org"
needed_binaries=(lsb_release wget add-apt-repository gpg)
missing_binaries=()
for binary in "${needed_binaries[@]}"; do
if ! which "$binary" &>/dev/null ; then
missing_binaries+=("$binary")
if ! which $binary &>/dev/null ; then
missing_binaries+=($binary)
fi
done
if [[ ${#missing_binaries[@]} -gt 0 ]] ; then
echo "You are missing some tools this script requires: " "${missing_binaries[@]}"
echo "You are missing some tools this script requires: ${missing_binaries[@]}"
echo "(hint: apt install lsb-release wget software-properties-common gnupg)"
exit 4
fi

# Set default values for commandline arguments
# We default to the current stable branch of LLVM
LLVM_VERSION=$CURRENT_LLVM_STABLE
ALL=0
DISTRO=$(lsb_release -is)
VERSION=$(lsb_release -sr)
UBUNTU_CODENAME=""
CODENAME_FROM_ARGUMENTS=""
# Obtain VERSION_CODENAME and UBUNTU_CODENAME (for Ubuntu and its derivatives)
# shellcheck disable=SC1091
source /etc/os-release
DISTRO=${DISTRO,,}
case ${DISTRO} in
Expand Down Expand Up @@ -76,18 +76,21 @@ esac
if [ "$#" -ge 1 ] && [ "${1::1}" != "-" ]; then
if [ "$1" != "all" ]; then
LLVM_VERSION=$1
else
# special case for ./llvm.sh all
ALL=1
fi
OPTIND=2
if [ "$#" -ge 2 ]; then
if [ "$2" == "all" ]; then
# Install all packages
ALL=1
OPTIND=3
fi
fi
fi

while getopts ":hm:n:" arg; do
# shellcheck disable=SC2220
case $arg in
h)
usage
Expand Down Expand Up @@ -124,7 +127,9 @@ LLVM_VERSION_PATTERNS[15]="-15"
LLVM_VERSION_PATTERNS[16]="-16"
LLVM_VERSION_PATTERNS[17]="-17"
LLVM_VERSION_PATTERNS[18]="-18"
LLVM_VERSION_PATTERNS[19]=""
LLVM_VERSION_PATTERNS[19]="-19"
LLVM_VERSION_PATTERNS[20]="-20"
LLVM_VERSION_PATTERNS[21]=""

if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then
echo "This script does not support LLVM version $LLVM_VERSION"
Expand All @@ -138,7 +143,7 @@ if [[ -n "${CODENAME}" ]]; then
REPO_NAME="deb ${BASE_URL}/${CODENAME}/ llvm-toolchain${LINKNAME}${LLVM_VERSION_STRING} main"

# check if the repository exists for the distro and version
if ! wget -q --method=HEAD "${BASE_URL}/${CODENAME}" &> /dev/null; then
if ! wget -q --method=HEAD ${BASE_URL}/${CODENAME} &> /dev/null; then
if [[ -n "${CODENAME_FROM_ARGUMENTS}" ]]; then
echo "Specified codename '${CODENAME}' is not supported by this script."
else
Expand All @@ -156,12 +161,25 @@ if [[ ! -f /etc/apt/trusted.gpg.d/apt.llvm.org.asc ]]; then
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
fi

# shellcheck disable=SC2006
if [[ -z "`apt-key list 2> /dev/null | grep -i llvm`" ]]; then
# Delete the key in the old format
apt-key del AF4F7421
apt-key del AF4F7421 || true
fi
if [[ "${VERSION_CODENAME}" == "bookworm" ]]; then
# add it twice to workaround:
# https://github.com/llvm/llvm-project/issues/62475
add-apt-repository -y "${REPO_NAME}"
fi

add-apt-repository -y "${REPO_NAME}"
apt-get update
PKG="clang-$LLVM_VERSION lld-$LLVM_VERSION clangd-$LLVM_VERSION clang-tidy-$LLVM_VERSION"
apt-get install -y "$PKG"
PKG="clang-$LLVM_VERSION lldb-$LLVM_VERSION lld-$LLVM_VERSION clangd-$LLVM_VERSION clang-tidy-$LLVM_VERSION clang-format-$LLVM_VERSION clang-tools-$LLVM_VERSION"
if [[ $ALL -eq 1 ]]; then
# same as in test-install.sh
# No worries if we have dups
PKG="$PKG clang-tidy-$LLVM_VERSION clang-format-$LLVM_VERSION clang-tools-$LLVM_VERSION llvm-$LLVM_VERSION-dev lld-$LLVM_VERSION lldb-$LLVM_VERSION llvm-$LLVM_VERSION-tools libomp-$LLVM_VERSION-dev libc++-$LLVM_VERSION-dev libc++abi-$LLVM_VERSION-dev libclang-common-$LLVM_VERSION-dev libclang-$LLVM_VERSION-dev libclang-cpp$LLVM_VERSION-dev libunwind-$LLVM_VERSION-dev"
if test $LLVM_VERSION -gt 14; then
PKG="$PKG libclang-rt-$LLVM_VERSION-dev libpolly-$LLVM_VERSION-dev"
fi
fi
apt-get install -y $PKG
9 changes: 6 additions & 3 deletions src/sa_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ def create_or_edit_comment(comment_body):
pull_request.create_issue_comment(body=comment_body)


def generate_output(is_note, file_path, file_line_start, file_line_end, description):
def generate_output(
is_note, prefix_and_file_path, file_line_start, file_line_end, description
):
"""
Generate a formatted output string based on the details of a code issue.

Expand All @@ -344,14 +346,15 @@ def generate_output(is_note, file_path, file_line_start, file_line_end, descript
"""

if not is_note:
prefix, file_path = prefix_and_file_path
if TARGET_REPO_NAME != REPO_NAME:
if file_path not in FILES_WITH_ISSUES:
try:
with open(f"{file_path}", encoding="utf-8") as file:
with open(f"{prefix}/{file_path}", encoding="utf-8") as file:
lines = file.readlines()
FILES_WITH_ISSUES[file_path] = lines
except FileNotFoundError:
print(f"Error: The file '{file_path}' was not found.")
print(f"Error: The file '{prefix}/{file_path}' was not found.")

modified_content = FILES_WITH_ISSUES[file_path][
file_line_start - 1 : file_line_end - 1
Expand Down
6 changes: 5 additions & 1 deletion src/static_analysis_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ def create_comment_for_output(
)
was_note = is_note
new_line = utils.generate_output(
is_note, file_path, file_line_start, file_line_end, description
is_note,
(prefix, file_path),
file_line_start,
file_line_end,
description,
)

if utils.check_for_char_limit(new_line):
Expand Down
2 changes: 1 addition & 1 deletion src/static_analysis_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def create_comment_for_output(tool_output, files_changed_in_pr, output_to_consol
)

new_line = utils.generate_output(
False, file_path, file_line_start, file_line_end, description
False, ("", file_path), file_line_start, file_line_end, description
)

if utils.check_for_char_limit(new_line):
Expand Down
Loading