From d10f5827c21dabd3a69dc681a4bf97533b5dba09 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh Date: Tue, 16 Jul 2024 10:15:39 +0200 Subject: [PATCH 01/11] Setup SonarCloud analysis --- .github/workflows/clang-analysis.yml | 64 ++++++++++++++++++++++++++++ sonar-project.properties | 11 +++++ 2 files changed, 75 insertions(+) create mode 100644 .github/workflows/clang-analysis.yml create mode 100644 sonar-project.properties diff --git a/.github/workflows/clang-analysis.yml b/.github/workflows/clang-analysis.yml new file mode 100644 index 00000000000000..07b3d251291431 --- /dev/null +++ b/.github/workflows/clang-analysis.yml @@ -0,0 +1,64 @@ +name: Clang Tests + +permissions: + contents: read + +on: + workflow_dispatch: + push: + pull_request: + +concurrency: + +jobs: + check_clang: + steps: + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + - name: Install sonar-scanner + uses: SonarSource/sonarcloud-github-c-cpp@v2 + - name: Setup ccache + uses: hendrikmuhs/ccache-action@v1 + with: + # A full build of llvm, clang, lld, and lldb takes about 250MB + # of ccache space. There's not much reason to have more than this, + # because we usually won't need to save cache entries from older + # builds. Also, there is an overall 10GB cache limit, and each + # run creates a new cache entry so we want to ensure that we have + # enough cache space for all the tests to run at once and still + # fit under the 10 GB limit. + # Default to 2G to workaround: https://github.com/hendrikmuhs/ccache-action/issues/174 + max-size: 2G + key: clang-build-sonar + variant: sccache + - name: Build and Test + shell: bash + id: build-llvm + run: | + builddir="/mnt/build/" + mkdir -p $builddir + echo "llvm-builddir=$builddir" >> "$GITHUB_OUTPUT" + cmake -G Ninja \ + -B "$builddir" \ + -S llvm \ + -DCMAKE_EXPORT_COMPILE_COMMANDS \ + -DLLVM_ENABLE_PROJECTS="clang;lldb;libclc" \ + -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_ENABLE_ASSERTIONS=ON \ + -DLLDB_INCLUDE_TESTS=OFF \ + -DCMAKE_C_COMPILER_LAUNCHER=sccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DCMAKE_C_COMPILER=clang + ninja -C "$builddir" check-clang + - name: Run sonar-scanner + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.compile-commands=/mnt/build/compile_commands.json diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000000000..c268bf89038deb --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,11 @@ +sonar.projectKey=necto_llvm-project +sonar.organization=necto +sonar.sources=clang/lib + +# This is the name and version displayed in the SonarCloud UI. +#sonar.projectName=llvm-project +#sonar.projectVersion=1.0 + + +# Encoding of the source code. Default is default system encoding +#sonar.sourceEncoding=UTF-8 From cca2ee39bb25e8f37798136db8c7e5f77e101371 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh Date: Tue, 16 Jul 2024 10:16:51 +0200 Subject: [PATCH 02/11] Runs on ubuntu-latest --- .github/workflows/clang-analysis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/clang-analysis.yml b/.github/workflows/clang-analysis.yml index 07b3d251291431..91c0b1cb7266b1 100644 --- a/.github/workflows/clang-analysis.yml +++ b/.github/workflows/clang-analysis.yml @@ -12,6 +12,7 @@ concurrency: jobs: check_clang: + runs-on: 'ubuntu-latest' steps: - name: Setup Python uses: actions/setup-python@v5 From 72e9d97f77f65c19110153ecf1d503072ff3a8b2 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh Date: Tue, 16 Jul 2024 10:31:29 +0200 Subject: [PATCH 03/11] Remove stray spec --- .github/workflows/clang-analysis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/clang-analysis.yml b/.github/workflows/clang-analysis.yml index 91c0b1cb7266b1..2c29c8e0f3249a 100644 --- a/.github/workflows/clang-analysis.yml +++ b/.github/workflows/clang-analysis.yml @@ -8,8 +8,6 @@ on: push: pull_request: -concurrency: - jobs: check_clang: runs-on: 'ubuntu-latest' From 8ef2b7d21c103835d6c658f82de4dabe231ef043 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh Date: Tue, 16 Jul 2024 10:41:01 +0200 Subject: [PATCH 04/11] fix builddir --- .../{clang-analysis.yml => sonarcloud-analysis.yml} | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) rename .github/workflows/{clang-analysis.yml => sonarcloud-analysis.yml} (92%) diff --git a/.github/workflows/clang-analysis.yml b/.github/workflows/sonarcloud-analysis.yml similarity index 92% rename from .github/workflows/clang-analysis.yml rename to .github/workflows/sonarcloud-analysis.yml index 2c29c8e0f3249a..ab6000c0c936a7 100644 --- a/.github/workflows/clang-analysis.yml +++ b/.github/workflows/sonarcloud-analysis.yml @@ -1,4 +1,4 @@ -name: Clang Tests +name: SonarCloud Analysis permissions: contents: read @@ -39,7 +39,7 @@ jobs: shell: bash id: build-llvm run: | - builddir="/mnt/build/" + builddir="$PWD/build" mkdir -p $builddir echo "llvm-builddir=$builddir" >> "$GITHUB_OUTPUT" cmake -G Ninja \ @@ -59,5 +59,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} + LLVM_BUILDDIR: ${{ steps.build-llvm.outputs.llvm-builddir }} run: | - sonar-scanner --define sonar.cfamily.compile-commands=/mnt/build/compile_commands.json + sonar-scanner --define sonar.cfamily.compile-commands="$LLVM_BUILDDIR/compile_commands.json" From ff676e40a767afc9b1f742f50448a425e5f6eb19 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh Date: Tue, 16 Jul 2024 10:43:55 +0200 Subject: [PATCH 05/11] fix cmake incantation --- .github/workflows/sonarcloud-analysis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sonarcloud-analysis.yml b/.github/workflows/sonarcloud-analysis.yml index ab6000c0c936a7..9e9ae246632abb 100644 --- a/.github/workflows/sonarcloud-analysis.yml +++ b/.github/workflows/sonarcloud-analysis.yml @@ -9,7 +9,7 @@ on: pull_request: jobs: - check_clang: + sonarcloud: runs-on: 'ubuntu-latest' steps: - name: Setup Python @@ -45,7 +45,7 @@ jobs: cmake -G Ninja \ -B "$builddir" \ -S llvm \ - -DCMAKE_EXPORT_COMPILE_COMMANDS \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DLLVM_ENABLE_PROJECTS="clang;lldb;libclc" \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_ENABLE_ASSERTIONS=ON \ From 6b298a6f496cd373662c6f12a91c694688ac0e74 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh Date: Tue, 16 Jul 2024 10:46:14 +0200 Subject: [PATCH 06/11] Install ninja --- .github/workflows/sonarcloud-analysis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/sonarcloud-analysis.yml b/.github/workflows/sonarcloud-analysis.yml index 9e9ae246632abb..35d53f5194aa93 100644 --- a/.github/workflows/sonarcloud-analysis.yml +++ b/.github/workflows/sonarcloud-analysis.yml @@ -16,6 +16,9 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.11' + - name: Install Ninja + if: runner.os != 'Linux' + uses: llvm/actions/install-ninja@main - uses: actions/checkout@v4 with: fetch-depth: 1 From aa2513b9d3ab314a6ca623be4c77ff37c9197730 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh Date: Tue, 16 Jul 2024 10:49:03 +0200 Subject: [PATCH 07/11] Do install ninja --- .github/workflows/sonarcloud-analysis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/sonarcloud-analysis.yml b/.github/workflows/sonarcloud-analysis.yml index 35d53f5194aa93..d7695f179168d9 100644 --- a/.github/workflows/sonarcloud-analysis.yml +++ b/.github/workflows/sonarcloud-analysis.yml @@ -17,7 +17,6 @@ jobs: with: python-version: '3.11' - name: Install Ninja - if: runner.os != 'Linux' uses: llvm/actions/install-ninja@main - uses: actions/checkout@v4 with: From 3825b854a763546b5d161551144d309775e3deed Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh Date: Tue, 16 Jul 2024 13:35:57 +0200 Subject: [PATCH 08/11] Set container and reduce build, don't run tests --- .github/workflows/sonarcloud-analysis.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sonarcloud-analysis.yml b/.github/workflows/sonarcloud-analysis.yml index d7695f179168d9..6bc63284786beb 100644 --- a/.github/workflows/sonarcloud-analysis.yml +++ b/.github/workflows/sonarcloud-analysis.yml @@ -11,13 +11,13 @@ on: jobs: sonarcloud: runs-on: 'ubuntu-latest' + container: + image: 'ghcr.io/llvm/ci-ubuntu-22.04:latest' steps: - name: Setup Python uses: actions/setup-python@v5 with: python-version: '3.11' - - name: Install Ninja - uses: llvm/actions/install-ninja@main - uses: actions/checkout@v4 with: fetch-depth: 1 @@ -37,9 +37,9 @@ jobs: max-size: 2G key: clang-build-sonar variant: sccache - - name: Build and Test + - name: Config CMake shell: bash - id: build-llvm + id: config-llvm run: | builddir="$PWD/build" mkdir -p $builddir @@ -56,11 +56,16 @@ jobs: -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ -DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_C_COMPILER=clang - ninja -C "$builddir" check-clang + - name: Minimal Build + shell: bash + env: + LLVM_BUILDDIR: ${{ steps.config-llvm.outputs.llvm-builddir }} + run: | + ninja -v -C "$LLVM_BUILDDIR" libLLVM.so libclang.so - name: Run sonar-scanner env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} - LLVM_BUILDDIR: ${{ steps.build-llvm.outputs.llvm-builddir }} + LLVM_BUILDDIR: ${{ steps.config-llvm.outputs.llvm-builddir }} run: | sonar-scanner --define sonar.cfamily.compile-commands="$LLVM_BUILDDIR/compile_commands.json" From 6214d5195e1a8aaed664b2e8f393459794428404 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh Date: Tue, 16 Jul 2024 13:39:58 +0200 Subject: [PATCH 09/11] Install unzip --- .github/workflows/sonarcloud-analysis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/sonarcloud-analysis.yml b/.github/workflows/sonarcloud-analysis.yml index 6bc63284786beb..6716da946529c0 100644 --- a/.github/workflows/sonarcloud-analysis.yml +++ b/.github/workflows/sonarcloud-analysis.yml @@ -21,6 +21,11 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 1 + # necessary for install sonar-scanner + - name: Install unzip + run: | + apt update + apt install unzip - name: Install sonar-scanner uses: SonarSource/sonarcloud-github-c-cpp@v2 - name: Setup ccache From 396d2db70bfdfa02cafd2665ba6f0b41e4aa9d5d Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh Date: Tue, 16 Jul 2024 13:45:20 +0200 Subject: [PATCH 10/11] Try different set of targets --- .github/workflows/sonarcloud-analysis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud-analysis.yml b/.github/workflows/sonarcloud-analysis.yml index 6716da946529c0..cc0e955d120e02 100644 --- a/.github/workflows/sonarcloud-analysis.yml +++ b/.github/workflows/sonarcloud-analysis.yml @@ -66,7 +66,12 @@ jobs: env: LLVM_BUILDDIR: ${{ steps.config-llvm.outputs.llvm-builddir }} run: | - ninja -v -C "$LLVM_BUILDDIR" libLLVM.so libclang.so + ninja -v -C "$LLVM_BUILDDIR" \ + ClangAttrDocTable \ + Opcodes \ + clangAnalysisFlowSensitiveResources \ + clangBasic \ + ClangOpenCLBuiltinsImpl - name: Run sonar-scanner env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From a62c990d6b7b9101a20774f541127dbf441fa0c4 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh Date: Tue, 16 Jul 2024 19:02:51 +0200 Subject: [PATCH 11/11] fix sonar token --- .github/workflows/sonarcloud-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud-analysis.yml b/.github/workflows/sonarcloud-analysis.yml index cc0e955d120e02..b56c0f9f258316 100644 --- a/.github/workflows/sonarcloud-analysis.yml +++ b/.github/workflows/sonarcloud-analysis.yml @@ -75,7 +75,7 @@ jobs: - name: Run sonar-scanner env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} LLVM_BUILDDIR: ${{ steps.config-llvm.outputs.llvm-builddir }} run: | sonar-scanner --define sonar.cfamily.compile-commands="$LLVM_BUILDDIR/compile_commands.json"