Skip to content

Commit 7403841

Browse files
committed
Try to produce SARIF from linux clang
This is just horrible.
1 parent 2a2cae5 commit 7403841

File tree

5 files changed

+255
-184
lines changed

5 files changed

+255
-184
lines changed

.ci/clang-sarif-wrapper.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
# set -x
4+
set +e
5+
6+
SARIFDIR="$1"
7+
mkdir -p "$SARIFDIR"
8+
9+
shift
10+
11+
INVOCATIONHASH=$(echo "$*" | sha1sum --text - | cut -d' ' -f 1)
12+
13+
LOGNAME="$SARIFDIR/$INVOCATIONHASH.json"
14+
15+
$@ -fdiagnostics-format=sarif -Wno-sarif-format-unstable 2>"$LOGNAME"
16+
RES=$?
17+
18+
LC=$(wc -l "$LOGNAME" | cut -d' ' -f 1)
19+
if [ $LC -eq 3 ]; then
20+
# Got no warnings.
21+
exit $RES
22+
elif [ $LC -eq 4 ]; then
23+
touch "$SARIFDIR/.warnings"
24+
OUT="$(cat "$LOGNAME")"
25+
# Drop last line, which is: "$N (warning|error)[s] generated."
26+
echo "$OUT" | head -n 2 | tail -n 1 > "$LOGNAME"
27+
exit $RES
28+
else
29+
/bin/false # ???
30+
fi

.github/workflows/CI-linux.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,13 @@ jobs:
223223
BUILD_LOGGER_64_BIT_ONLY=YES BUILD_UI_DIST=NO make package
224224
export PATH="$PWD/build/CodeChecker/bin:$PATH"
225225
- name: Initialize CodeQL (for CodeQL static analysis)
226+
id: codeql-init
226227
timeout-minutes: 1
227228
if: inputs.flavor == 'CodeQLAnalysis'
228229
uses: github/codeql-action/init@v3
229230
with:
230231
languages: cpp
232+
source-root: ${{ github.workspace }}/rawspeed
231233
- name: Set up JDK 11 (for SonarCloud static analysis)
232234
timeout-minutes: 1
233235
if: inputs.flavor == 'SonarCloudStaticAnalysis' && github.repository == 'darktable-org/rawspeed' && github.event_name != 'pull_request' && github.ref_type == 'branch' && (github.ref_name == 'develop' || github.ref_name == 'stable')
@@ -264,6 +266,7 @@ jobs:
264266
env:
265267
CC: ${{ inputs.compiler-CC }}
266268
CXX: ${{ inputs.compiler-CXX }}
269+
FAMILY: ${{ inputs.compiler-family }}
267270
CLANG_TIDY: ${{ inputs.compiler-CLANG_TIDY }}
268271
GCOV: ${{ inputs.compiler-GCOV }}
269272
SRC_DIR: ${{ github.workspace }}/rawspeed
@@ -279,14 +282,16 @@ jobs:
279282
cmake -E make_directory "${INSTALL_PREFIX}"
280283
export ECO="${ECO} -DRAWSPEED_REFERENCE_SAMPLE_ARCHIVE=${RPUU_DST}"
281284
export ECO="${ECO} -DCMAKE_CXX_CLANG_TIDY_EXPORT_FIXES_DIR=${BUILD_DIR}/clang-tidy/"
282-
if [ "$FLAVOR" = "ClangTidy" ] || [ "$FLAVOR" = "ClangStaticAnalysis" ] || [ "$FLAVOR" = "ClangCTUStaticAnalysis" ] || [ "$FLAVOR" = "CodeQLAnalysis" ]; then
285+
if [ "$FAMILY" = "LLVM" ]; then
283286
export ECO="${ECO} -DRAWSPEED_ENABLE_WERROR=OFF"
287+
export ECO="${ECO} -DCMAKE_CXX_COMPILER_LAUNCHER='${SRC_DIR}/.ci/clang-sarif-wrapper.sh;${GITHUB_WORKSPACE}/clang_report/'"
284288
fi
285289
"${SRC_DIR}/.ci/ci-script.sh"
286290
- name: Build
287291
id: build
288292
timeout-minutes: ${{ inputs.flavor != 'ClangTidy' && (inputs.flavor != 'CodeQLAnalysis' && 7 || 12) || 25 }}
289293
env:
294+
FAMILY: ${{ inputs.compiler-family }}
290295
SRC_DIR: ${{ github.workspace }}/rawspeed
291296
BUILD_DIR: ${{ github.workspace }}/rawspeed-build
292297
INSTALL_PREFIX: ${{ github.workspace }}/rawspeed-install
@@ -295,6 +300,38 @@ jobs:
295300
run: |
296301
set -xe
297302
"${SRC_DIR}/.ci/ci-script.sh"
303+
if [ "$FLAVOR" = "ClangTidy" ] || [ "$FLAVOR" = "ClangStaticAnalysis" ] || [ "$FLAVOR" = "ClangCTUStaticAnalysis" ] || [ "$FLAVOR" = "CodeQLAnalysis" ]; then
304+
exit 0
305+
else
306+
MARKER="${GITHUB_WORKSPACE}/clang_report/.warnings"
307+
[ -f "$MARKER" ] && exit 1 || exit 0
308+
fi
309+
- name: Initialize CodeQL (to merge SARIF reports)
310+
id: codeql-init-dummy
311+
timeout-minutes: 1
312+
if: inputs.compiler-family == 'LLVM' && inputs.flavor != 'CodeQLAnalysis' && !cancelled() && steps.build.conclusion != 'skipped'
313+
uses: github/codeql-action/init@v3
314+
with:
315+
languages: cpp
316+
source-root: ${{ github.workspace }}/rawspeed
317+
- name: Merge clang SARIF reports
318+
if: inputs.compiler-family == 'LLVM' && !cancelled() && steps.build.conclusion != 'skipped'
319+
timeout-minutes: 1
320+
env:
321+
CODEQL_PATH: ${{ steps.codeql-init-dummy.conclusion != 'skipped' && steps.codeql-init-dummy.outputs.codeql-path || steps.codeql-init.outputs.codeql-path }}
322+
run: |
323+
set -xe
324+
INPUTS=$(for f in "${GITHUB_WORKSPACE}/clang_report/*.json"; do echo -n " --sarif $f"; done)
325+
echo ${INPUTS}
326+
"${CODEQL_PATH}" github merge-results ${INPUTS} --output="${GITHUB_WORKSPACE}/clang_report.json" --sarif-merge-runs-from-equal-category
327+
- name: Upload results of clang compile [SARIF]
328+
timeout-minutes: 1
329+
if: inputs.compiler-family == 'LLVM' && !cancelled() && steps.build.conclusion != 'skipped'
330+
uses: github/codeql-action/upload-sarif@v3
331+
with:
332+
sarif_file: "${{ github.workspace }}/clang_report.json"
333+
checkout_path: "${{ github.workspace }}/rawspeed"
334+
category: ${{ job.name }}
298335
- name: Test (unit tests)
299336
timeout-minutes: 1
300337
env:

0 commit comments

Comments
 (0)