6

I am struggling with running clang-tidy for my project. I am trying to run clang-tidy for my project for send data to Codacy. I am doing it like this:

clang-tidy $PWD -header-filter=.*,-checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* | ./codacy-clang-tidy-1.1.1 | \
        curl -XPOST -L -H "project-token: $CODACY_PROJECT_TOKEN" \
            -H "Content-type: application/json" -d @- \
            "https://api.codacy.com/2.0/commit/$TRAVIS_COMMIT/issuesRemoteResults"

        curl -XPOST -L -H "project-token: $CODACY_PROJECT_TOKEN" \
            -H "Content-type: application/json" \
            "https://api.codacy.com/2.0/commit/$TRAVIS_COMMIT/resultsFinal"

But it is complaining that compilation data cannot be found:

Error while trying to load a compilation database:
Could not auto-detect compilation database for file "/home/travis/build/mVento3/Duckvil/build"
No compilation database found in /home/travis/build/mVento3/Duckvil or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory

I am sure that compile_commands.json is in build directory where I am trying to run clang-tidy.
Main CMakeLists.txt:

cmake_minimum_required(VERSION 3.17)

project(Duckvil)

find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)

if(NOT CLANG_TIDY_COMMAND)
    message(WARNING "Could not find clang-tidy!")
    set(CMAKE_CXX_CLANG_TIDY "" CACHE STRING "" FORCE)
else()
    message(WARNING "Found clang-tidy")
    set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
    set(CMAKE_CXX_CLANG_TIDY
        clang-tidy;
        -header-filter=.*;
        -checks=*;
        --dump-config > .clang-tidy;
    )
endif()

if(WIN32)
    add_definitions(-DDUCKVIL_PLATFORM_WINDOWS)
else()
    if(UNIX)
        add_definitions(-DDUCKVIL_PLATFORM_LINUX)

        SET(GCC_COVERAGE_COMPILE_FLAGS "-g -O0 -coverage -fprofile-arcs -ftest-coverage")
        SET(GCC_COVERAGE_LINK_FLAGS "-coverage -lgcov")

        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
        SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
    endif()
endif()

add_definitions(-DDUCKVIL_OUTPUT="${CMAKE_SOURCE_DIR}/bin")

add_subdirectory(source)
list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
ENABLE_TESTING()
add_subdirectory(test)

Do i need to specify some additional option, or I misunderstood something?

EDIT

At second thought, maybe I should not doing it in separate "go", but while generating CMake project?

EDIT2

I came up with this:

./codacy-clang-tidy-1.1.1 < compile_commands.json | \
        curl -XPOST -L -H "project-token: ${CODACY_PROJECT_TOKEN}" \
            -H "Content-type: application/json" -d @- \
            "https://api.codacy.com/2.0/commit/${TRAVIS_COMMIT}/issuesRemoteResults"

        curl -XPOST -L -H "project-token: ${CODACY_PROJECT_TOKEN}" \
            -H "Content-type: application/json" \
            "https://api.codacy.com/2.0/commit/${TRAVIS_COMMIT}/resultsFinal"

Now it is not complaining about database, seems it is sending the data to codacy, but I cannot see anything on codacy... I read through codacy-clang-tidy and it seems it is getting the data from stdin.

Vento
  • 155
  • 2
  • 8
  • 2
    `CMAKE_CXX_CLANG_TIDY` is a cmake variable that sets each target to run `clang-tidy` automatically against each built source -- why are you setting this to pipe to `.clang-tidy`? `--dump-configs` should be something done once by yourself ahead of time, but not as an automated command in the CMakelists – Human-Compiler Sep 17 '20 at 19:58
  • I thought I should dump it to ```.clang-tidy``` file and then the **codacy-clang-tidy** will read it – Vento Sep 17 '20 at 20:04
  • The `.clang-tidy` file is effectively the serialized form of the command-line arguments. Generally it's desirable to _store_ this file in your repo and tune it to your own settings (naming convention, desired checks, etc). Even if you want to generate this on-the-fly, you will probably want to do this _before_ you run CMake, so that the `CMAKE_CXX_CLANG_TIDY` can be used on each target (allowing CMake to build each target and run `clang-tidy` against it) – Human-Compiler Sep 17 '20 at 20:07
  • In general clang-tidy is working fine, it is generating warnings and additional info while building project, but I am not sure what should I pass into ```codacy-clang-tidy``` or what file does it needs, .clang-tidy or the compilation database. It is complaining that the compilation database cannot be found – Vento Sep 17 '20 at 20:13
  • Hey @Vento, Codacy dev here. Can you reach Codacy through support so they can check exactly what is wrong. You can do it through in app chat or send an email to "support at codacy dot com". – rtfpessoa Sep 18 '20 at 09:56

1 Answers1

7

Specify the location explicitly using -p like -p ${CMAKE_BUILD_DIR}:

-p <build-path> is used to read a compile command database.

        For example, it can be a CMake build directory in which a file named
        compile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
        CMake option to get this output). When no build path is specified,
        a search for compile_commands.json will be attempted through all
        parent paths of the first input file . See:
        https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an
        example of setting up Clang Tooling on a source tree.
jaques-sam
  • 2,578
  • 1
  • 26
  • 24