3

我正在努力为我的项目运行 clang-tidy。我正在尝试为我的项目运行 clang-tidy 以将数据发送到 Codacy。我这样做是这样的:

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"

但它抱怨找不到编译数据:

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

我确信compile_commands.json位于我试图运行 clang-tidy的构建目录中。
主要 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)

我是否需要指定一些额外的选项,或者我误解了什么?

编辑

再想一想,也许我不应该在单独的“go”中进行,而是在生成 CMake 项目时?

编辑2

我想出了这个:

./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"

现在它没有抱怨数据库,似乎它正在将数据发送到 codacy,但我在 codacy 上看不到任何东西......我通读了codacy-clang-tidy,它似乎正在从标准输入获取数据。

4

0 回答 0