Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clazy action #16

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions .github/actions/clazy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: 'Clazy action'
description: 'GitHub Action for use clazy-standalone in Qt Projects'
inputs:
version:
description: 'Clazy version'
required: true
default: '1.11'
extensions:
description: Extensions.
required: false
default: "cpp,cxx,cc,h,hpp"
checks:
description: |
Comma-separated list of clazy checks. Default is level1.
required: false
default: "level1"
warnings_as_errors:
description: |
comma-separated list of checks that will be promoted to errors.
required: false
default: ""
extra-arg:
description: |
Additional argument to append to the compiler command line.
required: false
default: ""
extra-arg-before:
description: |
Additional argument to prepend to the compiler command line.
required: false
default: ""
install-stable:
description: |
The stable version is being downloaded without compilation.
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.
required: false
default: false
qt4-compat:
description: |
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
required: false
default: false
database:
description: |-
Is used to read a compile command database.
default: ""
only-diff:
description: |-
Is used to check only modified and appended files.
default: ""
outputs:
warnings-count:
description: 'Total warnings count'
errors-count:
description: 'Total warnings count'

runs:
using: 'composite'
steps:

- name: Cache files
uses: actions/cache@v4
id: cache-clazy-standalone
with:
path: ~/.local/clazy/
key: ${{ runner.os }}-clazy-${{ inputs.version }}-${{ github.event.pull_request.number }}

- name: Install dependencies
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
libclang-dev \
llvm-dev

- name: Install clazy
if: ${{ inputs.install-stable }} == 'true'
shell: bash
run: |
sudo apt-get update
sudo apt-get install clazy

- name: Build clazy
shell: bash
if: ${{ steps.cache-clazy-standalone.outputs.cache-hit != 'true' && inputs.install-stable != 'true' }}
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
ninja-build \
cmake

wget -O ./clazy.tar.gz https://github.com/KDE/clazy/archive/refs/tags/v${{ inputs.version }}.tar.gz
tar -xzvf clazy.tar.gz && rm -rf clazy.tar.gz
cd ./clazy-${{ inputs.version }} && cmake -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=~/.local/clazy/lib -DCMAKE_INSTALL_PREFIX=~/.local/clazy -DCMAKE_BUILD_TYPE=Release -G Ninja \
&& cmake --build . \
&& 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' }}
uses: actions/cache@v4
with:
path: ~/.local/clazy
key: ${{ runner.os }}-clazy-${{ inputs.version }}-${{ github.event.pull_request.number }}

- name: Start clazy
id: clazy-check
shell: bash
env:
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 }}
HEADER_FILTER: ${{ inputs.header-filter }}
IGNORE_DIRS: ${{ inputs.ignore-dirs}}
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 }}
ONLY_DIFF: ${{ inputs.only-diff }}
run: |
PATH=~/.local/clazy/bin:$PATH "$GITHUB_ACTION_PATH/clazy.sh"
148 changes: 148 additions & 0 deletions .github/actions/clazy/clazy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/bin/bash
set -x

options=()
extra_args=()
extra_args_before=()
files=()

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

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

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

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

if [ "$SUPPORTED_CHECKS_JSON" == "true" ]; then
options+=( "--supported-checks-json" )
fi

if [ "$VISIT_IMPLICIT_CODE" == "true" ]; then
options+=( "--visit-implicit-code" )
fi

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]+): (.+): (.+) \[(.*)\]$'

if [[ -n "$ONLY_DIFF" ]]; then
for file in $(git diff --name-only HEAD^1 HEAD); do
file_extension="${file##*.}"
if echo "$EXTENSIONS" | grep -q "$file_extension"; then
files+=("$(realpath "$file")")
fi
done
else
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

fi

output=$(clazy-standalone --checks="$CHECKS" -p="$DATABASE" \
--header-filter="$HEADER_FILTER" --ignore-dirs="$IGNORE_DIRS" \
"${options[@]}" "${extra_args[@]}" "${extra_args_before[@]}" "${files[@]}" 2>&1)

warnings_file=$(mktemp)
errors_file=$(mktemp)

trap 'rm -f "$warnings_file" "$errors_file"' EXIT

echo 0 > "$warnings_file"
echo 0 > "$errors_file"

declare -A warnings_seen

echo "$output" | grep -E "$pattern" | while IFS= read -r line; do
if [[ $line =~ $pattern ]]; then
relative_path="${BASH_REMATCH[1]}"
line_number="${BASH_REMATCH[2]}"
column_number="${BASH_REMATCH[3]}"
warning_type="${BASH_REMATCH[4]}"
warning_message="${BASH_REMATCH[5]}"
warning_code="${BASH_REMATCH[6]}"

if [[ "$relative_path" == /* ]]; then
absolute_path=$relative_path
else
absolute_path=$(realpath "$DATABASE/$relative_path")
fi

warning_key="${absolute_path}:${line_number}:${column_number}:${warning_code}"

if [[ -n "${warnings_seen[$warning_key]}" ]]; then
continue
fi

warnings_seen["$warning_key"]=1

if [ "$IGNORE_HEADERS" != "true" ]; then
if [[ "$warning_type" == "warning" ]]; then
echo "warning file=$absolute_path,line=$line_number,col=$column_number,$warning_message [$warning_code]"
current_warnings=$(<"$warnings_file")
((current_warnings++))
echo "$current_warnings" > "$warnings_file"
fi

if [[ "$warning_type" == "error" ]]; then
echo "error file=$absolute_path,line=$line_number,col=$column_number,$warning_message [$warning_code]"
current_errors=$(<"$errors_file")
((current_errors++))
echo "$current_errors" > "$errors_file"
fi

elif [[ "${files[@]}" =~ "$absolute_path" ]]; then

if [[ "$warning_type" == "warning" ]]; then
echo "warning file=$absolute_path,line=$line_number,col=$column_number,$warning_message [$warning_code]"
current_warnings=$(<"$warnings_file")
((current_warnings++))
echo "$current_warnings" > "$warnings_file"
fi

if [[ "$warning_type" == "error" ]]; then
echo "error file=$absolute_path,line=$line_number,col=$column_number,$warning_message [$warning_code]"
current_errors=$(<"$errors_file")
((current_errors++))
echo "$current_errors" > "$errors_file"
fi
fi

if [[ "${files[@]}" =~ "$absolute_path" ]]; then
if [[ "$warning_type" == "warning" ]]; then
echo "::warning file=$absolute_path,line=$line_number,col=$column_number::$warning_message [$warning_code]"
fi

if [[ "$warning_type" == "error" ]]; then
echo "::error file=$absolute_path,line=$line_number,col=$column_number::$warning_message [$warning_code]"
fi
fi
fi
done

warnings_count=$(<"$warnings_file")
errors_count=$(<"$errors_file")

echo "errors-count=$errors_count" >> $GITHUB_STATE
echo "warnings-count=$warnings_count" >> $GITHUB_STATE

if [ "$IGNORE_HEADERS" == "true" ] && [ -n "$DATABASE" ]; then
mv $DATABASE/compile_commands_backup.json $DATABASE/compile_commands.json
fi

rm -f "$warnings_file" "$errors_file"
73 changes: 73 additions & 0 deletions .github/workflows/clazy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: 🧪Clazy checks

on:
push:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Get deps
run: |
sudo apt-get install \
cmake \
ninja-build \
clang \
qtbase5-dev \
qt5keychain-dev \
qtscript5-dev \
qtwebengine5-dev

- name: Build
run: |
mkdir -p build
cd build
cmake -GNinja \
-Do2_BUILD_EXAMPLES:BOOL=ON \
-Do2_WITH_TESTS=ON \
-Do2_SHOW_TRACE:BOOL=ON \
-Do2_WITH_DROPBOX:BOOL=ON \
-Do2_WITH_FACEBOOK:BOOL=ON \
-Do2_WITH_FLICKR:BOOL=ON \
-Do2_WITH_GOOGLE:BOOL=ON \
-Do2_WITH_HUBIC:BOOL=ON \
-Do2_WITH_KEYCHAIN:BOOL=ON \
-Do2_WITH_MSGRAPH:BOOL=ON \
-Do2_WITH_OAUTH1:BOOL=ON \
-Do2_WITH_QT5:BOOL=ON \
-Do2_WITH_SKYDRIVE:BOOL=ON \
-Do2_WITH_SMUGMUG:BOOL=ON \
-Do2_WITH_SPOTIFY:BOOL=ON \
-Do2_WITH_SURVEYMONKEY:BOOL=ON \
-Do2_WITH_TWITTER:BOOL=ON \
-Do2_WITH_UBER:BOOL=ON \
-Do2_WITH_VIMEO:BOOL=ON \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_CXX_FLAGS="-Wno-macro-redefined"
..
ninja
cd ..

- name: Clazy action
id: clazy
uses: ./.github/actions/clazy
with:
checks: 'level0,level1,old-style-connect,no-overloaded-signal'
install-stable: true
database: build

- name: Dump results
run: |
echo "Warnings count: ${{ steps.clazy.outputs.warnings-count }}"
echo "Errors count: ${{ steps.clazy.outputs.errors-count }}"

- name: Fail if warnings or errors exist
if: ${{ fromJSON(steps.clazy.outputs.warnings-count) > 0 || fromJSON(steps.clazy.outputs.errors-count) > 0 }}
run: exit 1
6 changes: 3 additions & 3 deletions examples/facebookexternalinterceptordemo/webenginepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ QWebEnginePage *WebEnginePage::createWindow(WebWindowType type)
case QWebEnginePage::WebDialog:
{
WebWindow *webViewDialog = new WebWindow(QSize(600, 500), QUrl(), mRedirectURLString, false);
QObject::connect(webViewDialog, SIGNAL(callbackCalled(const QString &)), this, SLOT(onAuthWindowCallbackCalled(const QString &)));
QObject::connect(webViewDialog, SIGNAL(windowClosed()), this, SLOT(onCreatedWindowClosed()));
QObject::connect(webViewDialog->GetWebEnginePage(), SIGNAL(windowCloseRequested()), this, SLOT(onWindowCloseRequested()));
connect(webViewDialog, &WebWindow::callbackCalled, this, &WebEnginePage::onAuthWindowCallbackCalled);
connect(webViewDialog, &WebWindow::windowClosed, this, &WebEnginePage::onCreatedWindowClosed);
connect(webViewDialog->GetWebEnginePage(), &QWebEnginePage::windowCloseRequested, this, &WebEnginePage::onWindowCloseRequested);
mCreatedWindows.push_back(webViewDialog);
webViewDialog->open();
return webViewDialog->GetWebEnginePage();
Expand Down
Loading
Loading