From afe828495e8a399cc7d31156e74e70cc5e6d8082 Mon Sep 17 00:00:00 2001 From: JacobDomagala Date: Wed, 19 Feb 2025 10:24:58 +0100 Subject: [PATCH 1/9] [#126]: Update ubuntu version in docker --- docker/static_analysis.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/static_analysis.dockerfile b/docker/static_analysis.dockerfile index 1f380e9..3d60501 100644 --- a/docker/static_analysis.dockerfile +++ b/docker/static_analysis.dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:23.04 as base +FROM ubuntu:24.04 as base # Define versions as environment variables ENV CLANG_VERSION=18 \ From dd723bf3bbedffca9b1a87dcdd46ececdbb92f5d Mon Sep 17 00:00:00 2001 From: JacobDomagala Date: Wed, 19 Feb 2025 10:25:31 +0100 Subject: [PATCH 2/9] [#126]: Update llvm script --- llvm.sh | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/llvm.sh b/llvm.sh index 491c785..2f58e83 100644 --- a/llvm.sh +++ b/llvm.sh @@ -27,12 +27,12 @@ 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 @@ -40,12 +40,12 @@ 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 @@ -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 @@ -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" @@ -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 @@ -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" +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 From 632aa67f2b46a488dc20228ed2ce490d3701e6cc Mon Sep 17 00:00:00 2001 From: JacobDomagala Date: Wed, 19 Feb 2025 10:26:33 +0100 Subject: [PATCH 3/9] [#126]: Update cppcheck and clang versions --- docker/static_analysis.dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/static_analysis.dockerfile b/docker/static_analysis.dockerfile index 3d60501..a8a52d9 100644 --- a/docker/static_analysis.dockerfile +++ b/docker/static_analysis.dockerfile @@ -1,8 +1,8 @@ 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 From 7e2854fe8f1e5c3b56a72055b8ccc78891343897 Mon Sep 17 00:00:00 2001 From: JacobDomagala Date: Wed, 19 Feb 2025 10:38:23 +0100 Subject: [PATCH 4/9] [#126]: Fix docker warning --- docker/static_analysis.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/static_analysis.dockerfile b/docker/static_analysis.dockerfile index a8a52d9..57ddc9f 100644 --- a/docker/static_analysis.dockerfile +++ b/docker/static_analysis.dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:24.04 as base +FROM ubuntu:24.04 AS base # Define versions as environment variables ENV CLANG_VERSION=20 \ From 09864cb4c13356d48db6becb4c216bcb00709c9e Mon Sep 17 00:00:00 2001 From: JacobDomagala Date: Wed, 19 Feb 2025 10:41:18 +0100 Subject: [PATCH 5/9] [#126]: Exclude llvm.sh from shellcheck --- .github/workflows/shellcheck.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index 7855743..4d3ffd0 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -13,4 +13,6 @@ jobs: steps: - uses: actions/checkout@v3 - name: Run ShellCheck - uses: ludeeus/action-shellcheck@master \ No newline at end of file + uses: ludeeus/action-shellcheck@master + with: + ignore_names: llvm.sh # External file \ No newline at end of file From 12461d3b1bd4edbbaae9eff4bffa5aac91d23e1a Mon Sep 17 00:00:00 2001 From: JacobDomagala Date: Wed, 19 Feb 2025 11:24:41 +0100 Subject: [PATCH 6/9] [#126]: Update usage of clang-tidy --- entrypoint_cpp.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/entrypoint_cpp.sh b/entrypoint_cpp.sh index d8851d8..d840545 100644 --- a/entrypoint_cpp.sh +++ b/entrypoint_cpp.sh @@ -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 / From ef5110299124815f3092bac3cdf4f8a60c52c8b7 Mon Sep 17 00:00:00 2001 From: JacobDomagala Date: Wed, 19 Feb 2025 14:01:42 +0100 Subject: [PATCH 7/9] [#126]: Fix issues --- llvm.sh | 2 +- src/sa_utils.py | 6 +++--- src/static_analysis_cpp.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/llvm.sh b/llvm.sh index 2f58e83..2066ab3 100644 --- a/llvm.sh +++ b/llvm.sh @@ -173,7 +173,7 @@ fi add-apt-repository -y "${REPO_NAME}" apt-get update -PKG="clang-$LLVM_VERSION lldb-$LLVM_VERSION lld-$LLVM_VERSION clangd-$LLVM_VERSION" +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 diff --git a/src/sa_utils.py b/src/sa_utils.py index 9b13f22..075f03e 100644 --- a/src/sa_utils.py +++ b/src/sa_utils.py @@ -318,7 +318,7 @@ 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, file_path, file_line_start, file_line_end, description, prefix=""): """ Generate a formatted output string based on the details of a code issue. @@ -347,11 +347,11 @@ def generate_output(is_note, file_path, file_line_start, file_line_end, descript 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 diff --git a/src/static_analysis_cpp.py b/src/static_analysis_cpp.py index ff39a6a..ca23f9a 100644 --- a/src/static_analysis_cpp.py +++ b/src/static_analysis_cpp.py @@ -64,7 +64,7 @@ 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, file_path, file_line_start, file_line_end, description, prefix ) if utils.check_for_char_limit(new_line): From 7af4f7e9dc1fc31b59e9f55a5c616544b1810d2a Mon Sep 17 00:00:00 2001 From: JacobDomagala Date: Wed, 19 Feb 2025 14:55:12 +0100 Subject: [PATCH 8/9] [#126]: Fix pylint warning --- src/sa_utils.py | 3 ++- src/static_analysis_cpp.py | 2 +- src/static_analysis_python.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sa_utils.py b/src/sa_utils.py index 075f03e..251da29 100644 --- a/src/sa_utils.py +++ b/src/sa_utils.py @@ -318,7 +318,7 @@ 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, prefix=""): +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. @@ -344,6 +344,7 @@ 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: diff --git a/src/static_analysis_cpp.py b/src/static_analysis_cpp.py index ca23f9a..0a0b301 100644 --- a/src/static_analysis_cpp.py +++ b/src/static_analysis_cpp.py @@ -64,7 +64,7 @@ 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, prefix + is_note, (prefix, file_path), file_line_start, file_line_end, description ) if utils.check_for_char_limit(new_line): diff --git a/src/static_analysis_python.py b/src/static_analysis_python.py index b5fce05..0a420b9 100644 --- a/src/static_analysis_python.py +++ b/src/static_analysis_python.py @@ -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): From 6379f8a1638df7bfae57feef9998cefa7cb12ba2 Mon Sep 17 00:00:00 2001 From: JacobDomagala Date: Wed, 19 Feb 2025 15:17:49 +0100 Subject: [PATCH 9/9] [#126]: Run black --- .github/workflows/linter.yml | 2 -- .github/workflows/shellcheck.yml | 2 +- .github/workflows/test_action.yml | 1 - .github/workflows/unit_tests.yml | 2 -- src/sa_utils.py | 4 +++- src/static_analysis_cpp.py | 6 +++++- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index fc0c240..0469509 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -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" - - diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index 4d3ffd0..5699a54 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -15,4 +15,4 @@ jobs: - name: Run ShellCheck uses: ludeeus/action-shellcheck@master with: - ignore_names: llvm.sh # External file \ No newline at end of file + ignore_names: llvm.sh # External file diff --git a/.github/workflows/test_action.yml b/.github/workflows/test_action.yml index c29f311..3af048c 100644 --- a/.github/workflows/test_action.yml +++ b/.github/workflows/test_action.yml @@ -74,4 +74,3 @@ jobs: *** ### [Result for pull_request_target (non CMake)](https://github.com/JacobDomagala/TestRepo/pull/7#issuecomment-1404101648) - diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 44bab2d..74957e3 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -23,5 +23,3 @@ jobs: - name: Test with pytest run: | pytest - - diff --git a/src/sa_utils.py b/src/sa_utils.py index 251da29..e6b376d 100644 --- a/src/sa_utils.py +++ b/src/sa_utils.py @@ -318,7 +318,9 @@ def create_or_edit_comment(comment_body): pull_request.create_issue_comment(body=comment_body) -def generate_output(is_note, prefix_and_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. diff --git a/src/static_analysis_cpp.py b/src/static_analysis_cpp.py index 0a0b301..ff8fa5b 100644 --- a/src/static_analysis_cpp.py +++ b/src/static_analysis_cpp.py @@ -64,7 +64,11 @@ def create_comment_for_output( ) was_note = is_note new_line = utils.generate_output( - is_note, (prefix, 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):