3

我正在使用 CMake 3.6 生成 ninja 1.6.0 配置,使用 clang-tidy(LLVM 版本 3.9.1)编译和静态分析我的代码:

# file copied from http://www.labri.fr/perso/fleury/posts/programming/using-clang-tidy-and-clang-format.html

# Additional targets to perform clang-format/clang-tidy
# Get all project files
file(GLOB_RECURSE
     ALL_CXX_SOURCE_FILES
     *.[chi]pp *.[chi]xx *.cc *.hh *.ii *.[CHI]
     )

# Adding clang-tidy target if executable is found
find_program(CLANG_TIDY "clang-tidy")
if(CLANG_TIDY)
  add_custom_target(
    clang-tidy
    COMMAND clang-tidy
    ${ALL_CXX_SOURCE_FILES}
    --
    -std=c++11
    ${INCLUDE_DIRECTORIES}
    )
endif()

.clang-tidy 文件:

---
Checks:          '-*,readability-*'
AnalyzeTemporaryDtors: false
WarningsAsErrors: '*'
HeaderFilterRegex: 'src/'
User:            mgalos
CheckOptions:
  - key:             readability-identifier-naming.AbstractClassCase
    value:           CamelCase
...

构建.bat:

cmake -H. -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_INSTALL_PREFIX=_build/_release -DCMAKE_BUILD_TYPE=GENERIC_RELEASE -DBoost_COMPILER=-vc100

我得到的输出是:

96 warnings treated as errors ninja: build stopped: subcommand failed.

%errorlevel%0,虽然 ninja 明确表示子命令失败。这个变量很重要,因为它由构建服务器评估并将构建标记为失败。

我该怎么做才能%errorlevel%正确设置为!= 0?

4

2 回答 2

3

看起来这是一个已知问题

您可以采取的缓解措施是将所有输出从管道cmake传输到文件并扫描该输出以查找指示错误的字符串的出现,这似乎是build stopped: subcommand failed您的情况。如果存在,只需使用任意非零退出代码退出。

@ECHO OFF
cmake -H. -B_build -GNinja (...) > log.txt 2>&1
FOR /F %%G IN ('FINDSTR /C:"build stopped: subcommand failed" log.txt') DO EXIT /B 255
于 2017-02-10T09:08:28.377 回答
0

谢谢您的支持。正如建议的那样,我最终做了一个:

ninja clang-tidy | tee clang-tidy.log
grep 'error.*generated' clang-tidy.log | cut -d" " -f4 | gawk "{if($1 != \"0\")  {print \"-1\"; exit -1}}" > clang-tidy_result.log
set /p ErrorLevel=<clang-tidy_result.log
于 2017-02-10T10:06:14.317 回答