2

我尝试clang-tidy在 Windows 上使用 - 到目前为止还没有成功。

作为先决条件,我已经安装了LLVM 3.9.1

我的普通编译器是MSVC 2015,我的构建系统是QBS 1.7.2。使用我已经生成的 QBS compile_commands.json。当然,该文件包含 MSVC 2015cl.exe标志/参数。以下是显示一个文件条目的摘录:

{
    "arguments": [
        "C:/Programs/MVS14/VC/bin/amd64/cl.exe",
        "/nologo",
        "/c",
        "/EHsc",
        "/Zi",
        "/MDd",
        "/IC:\\some_ci_job_folder\\src\\some_component\\include",
        "/IC:\\some_ci_job_folder\\src\\some_needed_component\\include",
        "/IC:\\Programs\\Qt\\Online\\5.6\\msvc2015_64\\include",
        "/IC:\\Programs\\Qt\\Online\\5.6\\msvc2015_64\\include\\QtCore",
        "/IC:\\Programs\\Qt\\Online\\5.6\\msvc2015_64\\mkspecs\\win32-msvc2015",
        "/IC:\\some_ci_job_folder\\target\\build\\win64-vc14-qt56x-debug\\some_component.win64-vc14-qt56x.ce20db24\\qt.headers",
        "/D_MBCS",
        "/DWIN32",
        "/DQT_CORE_LIB",
        "/DNOMINMAX",
        "/DQT_DISABLE_DEPRECATED_BEFORE=0x000000",
        "/DVERSION_ID=\"MAJOR_UNDEF.MINOR_UNDEF-REVISION_UNDEF\"",
        "/DVERSION_MAJOR=0",
        "/DVERSION_MINOR=0",
        "/DVERSION_REVISION=0",
        "/DUSES_QT",
        "/D_DEBUG",
        "/D__mswin__",
        "/DUSE_RVALUE_REFS=1",
        "/D_CRT_SECURE_NO_DEPRECATE",
        "/D_SCL_SECURE_NO_WARNINGS",
        "/DWINVER=0x0502",
        "/D_WIN32_WINNT=0x0502",
        "/D_WIN32_WINDOWS=0x0502",
        "/TP",
        "/FS",
        "/Zm200",
        "/W4",
        "/FS",
        "/GR",
        "/wd4018",
        "/wd4063",
        "/wd4100",
        "/wd4121",
        "/wd4127",
        "/wd4150",
        "/wd4189",
        "/wd4238",
        "/wd4239",
        "/wd4244",
        "/wd4245",
        "/wd4267",
        "/wd4290",
        "/wd4389",
        "/wd4510",
        "/wd4512",
        "/wd4610",
        "/wd4718",
        "/wd4481",
        "/FoC:\\some_ci_job_folder\\target\\build\\win64-vc14-qt56x-debug\\some_component.win64-vc14-qt56x.ce20db24\\.obj\\f27fede2220bcd32\\foo.cpp.obj",
        "/FdC:\\some_ci_job_folder\\target\\build\\win64-vc14-qt56x-debug\\some_component.win64-vc14-qt56x.ce20db24\\.obj\\f27fede2220bcd32\\",
        "C:\\some_ci_job_folder\\src\\some_component\\src\\foo.cpp"
    ],
    "directory": "C:/some_ci_job_folder/target/build/win64-vc14-qt56x-debug/some_component.win64-vc14-qt56x.ce20db24/.obj",
    "file": "C:/some_ci_job_folder/src/some_component/src/foo.cpp"
},

切换到作业/项目文件夹C:/some_ci_job_folder/并运行

clang-tidy -p target\build\win64-vc14-qt56x-debug src\some_component\src\foo.cpp 1>clang-tidy.txt 2>&1

给我以下警告和一个错误:

... warnings and 1 error generated.
Error while processing C:\some_ci_job_folder\src\some_component\src\foo.cpp.
warning: /DNOMINMAX: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /DQT_CORE_LIB: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
... more warnings about defines ...
warning: /D_WIN32_WINDOWS=0x0502: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /D_WIN32_WINNT=0x0502: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /D__mswin__: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /EHsc: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /FS: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /FdC:\some_ci_job_folder\target\build\win64-vc14-qt56x-debug\some_component.win64-vc14-qt56x.ce20db24\.obj\f27fede2220bcd32\: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /FoC:\some_ci_job_folder\target\build\win64-vc14-qt56x-debug\some_component.win64-vc14-qt56x.ce20db24\.obj\f27fede2220bcd32\foo.cpp.obj: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /GR: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /IC:\Programs\Qt\Online\5.6\msvc2015_64\include: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /IC:\Programs\Qt\Online\5.6\msvc2015_64\include\QtCore: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /IC:\Programs\Qt\Online\5.6\msvc2015_64\mkspecs\win32-msvc2015: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /IC:\some_ci_job_folder\src\shared\some_needed_component\include: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /IC:\some_ci_job_folder\src\shared\some_component\include: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /IC:\some_ci_job_folder\target\build\win64-vc14-qt56x-debug\some_component.win64-vc14-qt56x.ce20db24\qt.headers: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /MDd: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /TP: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /W4: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /Zi: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /Zm200: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /c: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /nologo: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: /wd4189: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
... more warnings ...
warning: /wd4718: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
C:\some_ci_job_folder\src\some_component\src/foo.h:71:10: error: 'some_needed_component/bar.h' file not found [clang-diagnostic-error]
#include "some_needed_component/bar.h"
         ^

知道为什么clang-tidy不能cl正确解释选项(默认情况下)吗?

好的,在谷歌搜索后,我发现添加--driver-mode=cl可能会有所改善。但

clang-tidy -p target\build\win64-vc14-qt56x-debug src\some_component\src\foo.cpp -- --driver-mode=cl 1>clang-tidy.txt 2>&1

仍然给我

1 warning and 1 error generated.
Error while processing C:\some_ci_job_folder\src\some_component\src\foo.cpp.
warning: unknown argument ignored in clang-cl: '-resource-dir=C:\Programs\LLVM-3.9.1\bin\..\lib\clang\3.9.1' [clang-diagnostic-unknown-argument]
C:\some_ci_job_folder\src\some_component\src/foo.h:71:10: error: 'some_needed_component/bar.h' file not found [clang-diagnostic-error]
#include "some_needed_component/bar.h"
         ^

所以它不再抱怨包含路径参数,但据我所知,这些参数只是被忽略了吗?

顺便说一句:我clang-tidyDeveloper Command Prompt for VS2015. 到目前为止,我不确定这是否需要?

任何想法...如何解决问题,如何调试包含路径参数的评估,...?

4

2 回答 2

8

我是一名 Cppcheck 开发人员。

clang-tidy 已集成在 Cppcheck GUI 中。

您可以使用 Cppcheck GUI 在编译数据库或 Visual Studio 解决方案上运行 clang-tidy。Cppcheck GUI 使用它自己的编译数据库解析器,它的工作方式可能与 clang-tidy 内置解析器不同。

它是一个免费的开源 (GPL) 工具。可以在这里下载:http: //cppcheck.sf.net

以下是一些截图:http ://cppcheck.sf.net/clangtidy/index.html

随意尝试,不要犹豫,告诉我是否有任何我们可以解决的问题。

于 2017-10-11T10:22:14.083 回答
2

您可以使用 VS2015/VS2017 的 Clang 电动工具扩展,而不是直接调用 clang-tidy。直接在 IDE 中工作,您可以选择要激活的检查,它甚至可以应用自动代码修复来进行现代化检查。

于 2018-07-13T08:42:01.783 回答