JacobDomagala / StaticAnalysis

GitHub action performs static analysis on C++/Python code, flags issues, and posts comments directly on PRs.
MIT License
31 stars 10 forks source link

Lots of erroneous cppcheck errors in output #120

Open eljonny opened 5 months ago

eljonny commented 5 months ago

I am seeing a ton of these messages in the output:

cppcheck: error: could not find any files matching the filter.

As in a run on my repo in the following screenshot: image

You can check out the corresponding workflow run here.

Here's my workflow YAML: TestCPP Static analysis - cppcheck/clang-tidy

Please see the following comment on the CPPCheck sourceforge: https://sourceforge.net/p/cppcheck/discussion/general/thread/e293714bf0/#9bb4

Is there something I'm doing wrong? Is this expected behavior? And is there a way to remove these from the output?

Thanks so much!

JacobDomagala commented 5 months ago
        for file in $files_to_check; do
            exclude_arg=""
            if [ -n "$INPUT_EXCLUDE_DIR" ]; then
                exclude_arg="-i$GITHUB_WORKSPACE/$INPUT_EXCLUDE_DIR"
            fi

            # Replace '/' with '_'
            file_name=$(echo "$file" | tr '/' '_')

            debug_print "Running cppcheck --project=compile_commands.json $CPPCHECK_ARGS --file-filter=$file --output-file=cppcheck_$file_name.txt $exclude_arg"
            eval cppcheck --project=compile_commands.json "$CPPCHECK_ARGS" --file-filter="$file" --output-file="cppcheck_$file_name.txt" "$exclude_arg" || true
        done

This is the snippet for running cppcheck. files_to_check contains both header and source files, so when cppcheck is being executed with file as header file, it will generate the error you encountered (since compile_commands.json only contains information about source files).

This probably can be "fixed" by filtering files_to_check for source files only.

eljonny commented 4 months ago

Cool! This is good to know regardless of if this results in any changes! Thank you Jacob!

eljonny commented 4 months ago

        for file in $files_to_check; do

            exclude_arg=""

            if [ -n "$INPUT_EXCLUDE_DIR" ]; then

                exclude_arg="-i$GITHUB_WORKSPACE/$INPUT_EXCLUDE_DIR"

            fi

            # Replace '/' with '_'

            file_name=$(echo "$file" | tr '/' '_')

            debug_print "Running cppcheck --project=compile_commands.json $CPPCHECK_ARGS --file-filter=$file --output-file=cppcheck_$file_name.txt $exclude_arg"

            eval cppcheck --project=compile_commands.json "$CPPCHECK_ARGS" --file-filter="$file" --output-file="cppcheck_$file_name.txt" "$exclude_arg" || true

        done

This is the snippet for running cppcheck. files_to_check contains both header and source files, so when cppcheck is being executed with file as header file, it will generate the error you encountered (since compile_commands.json only contains information about source files).

This probably can be "fixed" by filtering files_to_check for source files only.

Thinking about this a little more it makes a ton of sense, I have a few boost projects in my repo that have tons of header files. I'll see if there's a way with cppcheck to just ignore .hpp files that I can add to the cppcheck_args variable. Thanks again for this! I got the PR comment functionality working and it is awesome. Great work man!