From 989766268d8aa4d79ba8eda3d31ce1b4645faad9 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 11:39:36 +0200 Subject: [PATCH 01/10] Add init.sh for yaml-cpp --- test/foss/yaml-cpp/init.sh | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 test/foss/yaml-cpp/init.sh diff --git a/test/foss/yaml-cpp/init.sh b/test/foss/yaml-cpp/init.sh new file mode 100755 index 00000000..f86d5160 --- /dev/null +++ b/test/foss/yaml-cpp/init.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# Copyright 2023 Ericsson AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +git clone --recurse https://github.com/jbeder/yaml-cpp.git test-proj +cd test-proj +git checkout yaml-cpp-0.7.0 + +# This file must be in the root of the project to be analyzed for bazelisk to work +cp ../../templates/.bazelversion ./.bazelversion + +# Add codechecker to the project +cat <> BUILD.bazel +#------------------------------------------------------- + +# codechecker rules +load( + "@bazel_codechecker//src:codechecker.bzl", + "codechecker_test", +) +load( + "@bazel_codechecker//src:code_checker.bzl", + "code_checker_test", +) + + +codechecker_test( + name = "codechecker_test", + targets = [ + ":yaml-cpp", + ], +) + +code_checker_test( + name = "code_checker_test", + targets = [ + ":yaml-cpp", + ], +) + +#------------------------------------------------------- +EOF + +# Add codechecker_bazel repo to WORKSPACE +cat ../../templates/WORKSPACE.template >> WORKSPACE From cb1915a45b190980ebc6b76cdc02500a1c67a6a8 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 11:46:16 +0200 Subject: [PATCH 02/10] Add CI for FOSS --- .github/workflows/foss.yml | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/foss.yml diff --git a/.github/workflows/foss.yml b/.github/workflows/foss.yml new file mode 100644 index 00000000..c00c46c9 --- /dev/null +++ b/.github/workflows/foss.yml @@ -0,0 +1,71 @@ +name: codechecker-bazel-tests + +# Triggers the workflow on push or pull request events. +on: [push, pull_request] + +permissions: read-all + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + # TODO: Move installation of tools to a composite action (or use a docker img) + # TODO: Generalize to handle multiple projects + # TODO: Add script to run tests locally + # TODO: Document how to add new project to the list. + foss_test: + name: "Test rules on FOSS project: yaml-cpp" + runs-on: ubuntu-24.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set bazel version to 6.5.0 + run: echo "6.5.0" > .bazelversion + + - name: Setup Bazel + uses: bazel-contrib/setup-bazel@0.15.0 + + - name: Install python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install CodeChecker analyzers + run: | + sudo apt-get update --quiet + sudo apt-get install --no-install-recommends \ + clang \ + clang-tools \ + clang-tidy + # The default naming of the clang-extdef-mapping, needed for CTU, is + # installed by clang-tools also contains the major version + # (e.g. clang-extdef-mapping-18), but the bazel rules reference it + # without the version number. To this end, we use update-alternatives + # to rename the binary to omit it. + sudo update-alternatives --install \ + /usr/bin/clang-extdef-mapping \ + clang-extdef-mapping \ + /usr/bin/clang-extdef-mapping-$(clang --version | head -n 1 | + sed -E 's/.*version ([0-9]+)\..*/\1/') \ + 100 + + - name: Install CodeChecker + run: pip3 install codechecker + + - name: Setup yaml-cpp + run: | + cd test/foss/yaml-cpp + sh init.sh + + - name: Run Bazel CodeChecker + run: | + cd test/foss/yaml-cpp/test-proj + bazel build :codechecker_test + + - name: Run Per-File Bazel CodeChecker + run: | + cd test/foss/yaml-cpp/test-proj + bazel build :code_checker_test From 07558fb8c52659e6eaf48057e56214ab35846aa0 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 11:47:06 +0200 Subject: [PATCH 03/10] Add license --- .github/workflows/foss.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/foss.yml b/.github/workflows/foss.yml index c00c46c9..9da91ad4 100644 --- a/.github/workflows/foss.yml +++ b/.github/workflows/foss.yml @@ -1,3 +1,17 @@ +# Copyright 2023 Ericsson AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: codechecker-bazel-tests # Triggers the workflow on push or pull request events. From 33cf09ecd8685017515c25fae81b724b5a77047d Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 19 Aug 2025 08:28:16 +0200 Subject: [PATCH 04/10] Add readme for foss --- test/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/README.md b/test/README.md index f5092dd2..79c96424 100644 --- a/test/README.md +++ b/test/README.md @@ -67,3 +67,19 @@ python3 -m unittest discover unit/my_test_dir -vvv > ``` **For a test template look into unit/template** + +## Testing on open source projects + +## Add a new open source project: + +1. Create a folder in the foss folder with the name of the project. +2. The folder should contain: + - init.sh + +3. The init.sh script should: + - Clone the test project into a folder named `test-proj`. + - To ensure the project doesn't change over time, check out a specific tag or commit instead of a branch! + - Copy the .bazelversion file from the templates directory into the test-proj directory. + - Append the WORKSPACE.template file to the WORKSPACE file of the project. + - Append the codechecker rules to the BUILD file of the project. + - There can be only two targets, codechecker_test and code_checker_test From 5044ff05f1009ed3f4a4868962acf9b6e13becd9 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 19 Aug 2025 12:01:43 +0200 Subject: [PATCH 05/10] Rename jobs for easier distinction --- .github/workflows/foss.yml | 2 +- .github/workflows/unit_test.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/foss.yml b/.github/workflows/foss.yml index 9da91ad4..96bba9e3 100644 --- a/.github/workflows/foss.yml +++ b/.github/workflows/foss.yml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: codechecker-bazel-tests +name: codechecker-bazel-foss-tests # Triggers the workflow on push or pull request events. on: [push, pull_request] diff --git a/.github/workflows/unit_test.yaml b/.github/workflows/unit_test.yaml index ecc3eea9..f1208e50 100644 --- a/.github/workflows/unit_test.yaml +++ b/.github/workflows/unit_test.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: codechecker-bazel-tests +name: codechecker-bazel-unit-tests # Triggers the workflow on push or pull request events. on: [push, pull_request] From 9a8f2d3ffb4cf2b68ba8cb9efe8ca07f0c1cf676 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 19 Aug 2025 12:07:24 +0200 Subject: [PATCH 06/10] Add templates --- test/foss/templates/.bazelversion | 1 + test/foss/templates/WORKSPACE.template | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/foss/templates/.bazelversion create mode 100644 test/foss/templates/WORKSPACE.template diff --git a/test/foss/templates/.bazelversion b/test/foss/templates/.bazelversion new file mode 100644 index 00000000..f22d756d --- /dev/null +++ b/test/foss/templates/.bazelversion @@ -0,0 +1 @@ +6.5.0 diff --git a/test/foss/templates/WORKSPACE.template b/test/foss/templates/WORKSPACE.template new file mode 100644 index 00000000..c71ed019 --- /dev/null +++ b/test/foss/templates/WORKSPACE.template @@ -0,0 +1,20 @@ +#---------------------------------------------------- + +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +local_repository( + name = "bazel_codechecker", + path = "../../../", +) + +load( + "@bazel_codechecker//src:tools.bzl", + "register_default_codechecker", + "register_default_python_toolchain", +) + +register_default_python_toolchain() + +register_default_codechecker() + +#---------------------------------------------------- From bc3c31b5b0812e3e9f7b071dfe83fb7ab0f4106f Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 19 Aug 2025 12:10:06 +0200 Subject: [PATCH 07/10] Correct path --- test/foss/templates/WORKSPACE.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/foss/templates/WORKSPACE.template b/test/foss/templates/WORKSPACE.template index c71ed019..6b73e87f 100644 --- a/test/foss/templates/WORKSPACE.template +++ b/test/foss/templates/WORKSPACE.template @@ -4,7 +4,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") local_repository( name = "bazel_codechecker", - path = "../../../", + path = "../../../../", ) load( From 5f6336b204815abbfc8cd2167e81445b4e33e6c3 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 29 Aug 2025 15:21:23 +0200 Subject: [PATCH 08/10] Use composite env setup --- .github/workflows/foss.yml | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/.github/workflows/foss.yml b/.github/workflows/foss.yml index 96bba9e3..22ee48f5 100644 --- a/.github/workflows/foss.yml +++ b/.github/workflows/foss.yml @@ -36,38 +36,8 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Set bazel version to 6.5.0 - run: echo "6.5.0" > .bazelversion - - - name: Setup Bazel - uses: bazel-contrib/setup-bazel@0.15.0 - - - name: Install python - uses: actions/setup-python@v5 - with: - python-version: '3.12' - - - name: Install CodeChecker analyzers - run: | - sudo apt-get update --quiet - sudo apt-get install --no-install-recommends \ - clang \ - clang-tools \ - clang-tidy - # The default naming of the clang-extdef-mapping, needed for CTU, is - # installed by clang-tools also contains the major version - # (e.g. clang-extdef-mapping-18), but the bazel rules reference it - # without the version number. To this end, we use update-alternatives - # to rename the binary to omit it. - sudo update-alternatives --install \ - /usr/bin/clang-extdef-mapping \ - clang-extdef-mapping \ - /usr/bin/clang-extdef-mapping-$(clang --version | head -n 1 | - sed -E 's/.*version ([0-9]+)\..*/\1/') \ - 100 - - - name: Install CodeChecker - run: pip3 install codechecker + - name: Setup environment + uses: ./.github/platform_environment_setup/ubuntu - name: Setup yaml-cpp run: | From b37478544f1ff5d848a8a82a1a5f44422e30d641 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 1 Sep 2025 16:41:01 +0200 Subject: [PATCH 09/10] Add rhel9 runner --- .github/workflows/foss.yml | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/.github/workflows/foss.yml b/.github/workflows/foss.yml index 22ee48f5..3a9c0e3f 100644 --- a/.github/workflows/foss.yml +++ b/.github/workflows/foss.yml @@ -24,11 +24,9 @@ concurrency: cancel-in-progress: true jobs: - # TODO: Move installation of tools to a composite action (or use a docker img) # TODO: Generalize to handle multiple projects # TODO: Add script to run tests locally - # TODO: Document how to add new project to the list. - foss_test: + foss_ubuntu_test: name: "Test rules on FOSS project: yaml-cpp" runs-on: ubuntu-24.04 @@ -53,3 +51,30 @@ jobs: run: | cd test/foss/yaml-cpp/test-proj bazel build :code_checker_test + + foss_rhel_test: + name: "Test rules on FOSS project: yaml-cpp" + runs-on: ubuntu-24.04 + container: redhat/ubi9:latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup environment + uses: ./.github/platform_environment_setup/rhel9 + + - name: Setup yaml-cpp + run: | + cd test/foss/yaml-cpp + sh init.sh + + - name: Run Bazel CodeChecker + run: | + cd test/foss/yaml-cpp/test-proj + bazel build :codechecker_test + + - name: Run Per-File Bazel CodeChecker + run: | + cd test/foss/yaml-cpp/test-proj + bazel build :code_checker_test From bb96e0093bd86aed8d5e38f0edfb205b50d4ebe4 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 1 Sep 2025 16:47:22 +0200 Subject: [PATCH 10/10] Fix extension --- .github/workflows/{foss.yml => foss.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{foss.yml => foss.yaml} (100%) diff --git a/.github/workflows/foss.yml b/.github/workflows/foss.yaml similarity index 100% rename from .github/workflows/foss.yml rename to .github/workflows/foss.yaml