Skip to content

Commit

Permalink
use run-clang-tidy to run clazy on a reasonable set of paths
Browse files Browse the repository at this point in the history
  • Loading branch information
cebtenzzre committed Oct 21, 2024
1 parent e36b4c9 commit 009a637
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 71 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# clazy-standalone-action
# clazy-action

A GitHub Action to run clazy.
53 changes: 19 additions & 34 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name: 'Clazy action'
description: 'GitHub Action for use clazy-standalone in Qt Projects'
description: 'GitHub Action for use clazy in Qt Projects'
inputs:
version:
description: 'Clazy version'
required: true
default: '1.11'
extensions:
description: Extensions.
required: false
default: "cpp,cxx,cc,h,hpp"
path-regex:
description: |
Regular expression matching the names of the source files to output diagnostics from.
required: false
default: ''
checks:
description: |
Comma-separated list of clazy checks. Default is level1.
Expand All @@ -35,23 +36,12 @@ inputs:
In this case, the version field is ignored.
required: false
default: false
ignore-headers:
description: |
Ignore thirdparty headers.
required: false
default: true
header-filter:
description: |
Regular expression matching the names of the headers to output diagnostics from.
Diagnostics from the main file of each translation unit are always displayed.
required: false
default: ''
ignore-dirs:
description: |
Regular expression matching the names of the
directories for which diagnostics should never be emitted. Useful for ignoring 3rdparty code.
required: false
default: ''
only-qt:
description: |
Won't emit warnings for non-Qt files, or in other words, if -DQT_CORE_LIB is missing.
Expand All @@ -62,11 +52,6 @@ inputs:
Turns off checks not compatible with Qt 4
required: false
default: false
supported-checks-json:
description: |
Dump meta information about supported checks in JSON format.
required: false
default: false
visit-implicit-code:
description: |
For visiting implicit code like compiler generated constructors. None of the built-in checks benefit from this, but can be useful for custom checks
Expand All @@ -88,7 +73,7 @@ runs:

- name: Cache files
uses: actions/cache@v4
id: cache-clazy-standalone
id: cache-clazy
with:
path: ~/.local/clazy/
key: ${{ runner.os }}-clazy-${{ inputs.version }}-${{ github.event.pull_request.number }}
Expand All @@ -97,9 +82,13 @@ runs:
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
libclang-dev \
llvm-dev
sudo apt-get install -y --no-install-recommends clang-tidy expect
- name: Install build dependencies
shell: bash
if: ${{ inputs.install-stable != 'true' }}
run: |
sudo apt-get install -y --no-install-recommends libclang-dev llvm-dev
- name: Install clazy
if: ${{ inputs.install-stable }} == 'true'
Expand All @@ -110,7 +99,7 @@ runs:
- name: Build clazy
shell: bash
if: ${{ steps.cache-clazy-standalone.outputs.cache-hit != 'true' && inputs.install-stable != 'true' }}
if: ${{ steps.cache-clazy.outputs.cache-hit != 'true' && inputs.install-stable != 'true' }}
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
Expand All @@ -124,7 +113,7 @@ runs:
&& cmake --build . --target install && cd .. && rm -rf ./clazy-${{ inputs.version }}
- name: Save clazy
if: ${{ steps.cache-clazy-standalone.outputs.cache-hit != 'true' && inputs.install-stable != 'true' }}
if: ${{ steps.cache-clazy.outputs.cache-hit != 'true' && inputs.install-stable != 'true' }}
uses: actions/cache@v4
with:
path: ~/.local/clazy
Expand All @@ -137,17 +126,13 @@ runs:
CHECKS: ${{ inputs.checks }}
EXTRA_ARG: ${{ inputs.extra-arg }}
EXTRA_ARG_BEFORE: ${{ inputs.extra-arg-before }}
DATABASE: "${{ inputs.database }}"
EXTENSIONS: ${{inputs.extensions }}
EXTRA_OPTIONS: ${{ inputs.extra-options }}
DATABASE: ${{ inputs.database }}
HEADER_FILTER: ${{ inputs.header-filter }}
IGNORE_DIRS: ${{ inputs.ignore-dirs}}
PATH_REGEX: ${{ inputs.path-regex }}
ONLY_QT: ${{ inputs.only-qt }}
QT4_COMPAT: ${{ inputs.qt4-compat }}
SUPPORTED_CHECKS_JSON: ${{ inputs.supported-checks-json }}
VISIT_IMPLICIT_CODE: ${{ inputs.visit-implicit-code }}
CLAZY_CHECKS_AS_ERRORS: ${{ inputs.warnings_as_errors }}
IGNORE_HEADERS : ${{ inputs.ignore-headers }}
WARNINGS_AS_ERRORS: ${{ inputs.warnings_as_errors }}
run: |
PATH=~/.local/clazy/bin:$PATH "$GITHUB_ACTION_PATH/clazy.sh"
Expand Down
2 changes: 2 additions & 0 deletions clazy-unbuffer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
exec unbuffer clazy-standalone $CLAZY_OPTIONS "$@"
60 changes: 24 additions & 36 deletions clazy.sh
Original file line number Diff line number Diff line change
@@ -1,50 +1,36 @@
#!/bin/bash

options=()
extra_args=()
extra_args_before=()
clazy_options=()

for pair in $EXTRA_ARG; do
extra_args+=( "--extra-arg=$pair" )
for arg in $EXTRA_ARG; do
clazy_options+=( "-extra-arg=$arg" )
done

for pair in $EXTRA_ARG_BEFORE; do
extra_args_before+=( "--extra-arg-before=$pair" )
for arg in $EXTRA_ARG_BEFORE; do
clazy_options+=( "-extra-arg-before=$arg" )
done

if [ "$ONLY_QT" == "true" ]; then
options+=( "--only-qt" )
if [[ $ONLY_QT == "true" ]]; then
clazy_options+=( "--only-qt" )
fi

if [ "$QT4_COMPAT" == "true" ]; then
options+=( "--qt4-compat" )
if [[ $QT4_COMPAT == "true" ]]; then
clazy_options+=( "--qt4-compat" )
fi

if [ "$SUPPORTED_CHECKS_JSON" == "true" ]; then
options+=( "--supported-checks-json" )
if [[ $VISIT_IMPLICIT_CODE == "true" ]]; then
clazy_options+=( "--visit-implicit-code" )
fi

if [ "$VISIT_IMPLICIT_CODE" == "true" ]; then
options+=( "--visit-implicit-code" )
fi
args=(
-clang-tidy-binary "$GITHUB_ACTION_PATH/clazy-unbuffer.sh"
-checks="$CHECKS"
-warnings-as-errors="$WARNINGS_AS_ERRORS"
-p="$DATABASE"
-header-filter="$HEADER_FILTER"
--
"$PATH_REGEX"
)

if [ "$IGNORE_HEADERS" == "true" ] && [ -n "$DATABASE" ]; then
cp $DATABASE/compile_commands.json $DATABASE/compile_commands_backup.json
sed -i 's/-I\([^ ]*\)/-isystem\1/g' $DATABASE/compile_commands.json
fi

pattern='^(.*?):([0-9]+):([0-9]+): (.+): (.+) \[(.*)\]$'

IFS=',' read -r -a extensions <<< "$EXTENSIONS"
for ext in "${extensions[@]}"; do
while IFS= read -r -d '' file; do
files+=($(realpath "$file"))
done < <(find . -name "*.$ext" -print0)
done

output=$(clazy-standalone --checks="$CHECKS" -p="$DATABASE" \
--header-filter="$HEADER_FILTER" --ignore-dirs="$IGNORE_DIRS" \
"${options[@]}" "${extra_args[@]}" "${extra_args_before[@]}" "${files[@]}" 2>&1)
exec 5>&1
output=$(CLAZY_OPTIONS=${clazy_options[*]} run-clang-tidy "${args[@]}" 2>&1 | tee /dev/fd/5)

warnings_file=$(mktemp)
errors_file=$(mktemp)
Expand All @@ -56,6 +42,8 @@ echo 0 > "$errors_file"

declare -A warnings_seen

pattern='^(.*?):([0-9]+):([0-9]+): (.+): (.+) \[(.*)\]$'

echo "$output" | grep -E "$pattern" | while IFS= read -r line; do
if [[ $line =~ $pattern ]]; then
relative_path="${BASH_REMATCH[1]}"
Expand Down

0 comments on commit 009a637

Please sign in to comment.