Ven*_*nto 9 c++ continuous-integration cmake codacy clang-tidy
我正在努力为我的项目运行 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"
Run Code Online (Sandbox Code Playgroud)
但报错找不到编译数据:
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
Run Code Online (Sandbox Code Playgroud)
我确信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)
Run Code Online (Sandbox Code Playgroud)
我是否需要指定一些额外的选项,或者我误解了什么?
编辑
再想一想,也许我不应该在单独的“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"
Run Code Online (Sandbox Code Playgroud)
现在它没有抱怨数据库,似乎正在将数据发送到 codacy,但我在 codacy 上看不到任何内容...我通读了codacy-clang-tidy,似乎它正在从标准输入获取数据。
Dru*_*umM 10
-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.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12567 次 |
| 最近记录: |