我设法将 PC-Lint 设置为可在 Visual Studio 2019 中使用的 CMake 项目的自定义目标。
add_custom_target( PROJECT_LINT
COMMAND C:/pc_lint/Lint-nt +v -u project_opts.lnt ${PROJECT_SOURCE_FILES}
WORKING_DIRECTORY ${LINT_DIR}
)
这个目标可以用 Visual Studio 很好地构建,并且 PC-Lint 可以正常工作。PC_Lint 配置为使用选项将所有发现作为错误输出-"format=%(%f %l %)error %n: (%t -- %m)"
。问题是,在构建日志输出中,Visual Studio 会将项目补丁添加到打印错误的每一行,如下所示:
G:\ProjectPath\G : \ProjectPath\code\Common\MAIN.c 746 error 737: (Info -- Loss of sign in promotion from int to unsigned int)
Visual Studio 将能够解析此输出,因此错误显示在错误列表中,但它将文件解析为“ G ”,因为在解析上面的行时,这显然来自正则表达式。
从 PC-Lint 格式中删除文件-"format=%(%l %)error %n: (%t -- %m)"
会导致输出
G:\ProjectPath\EXEC 746 error 737: (Info -- Loss of sign in promotion from int to unsigned int)
现在当然VS将文件解析为“ EXEC ”。
似乎 Visual Studio 期望 PC-Lint 输出不带路径的文件名,但添加它会破坏它。我不明白为什么会发生这种情况,因为它没有在其他行中添加路径:
--- Module: G:\ProjectPath\code\Common\FILE1.c (C)
During Specific Walk:
File G:\ProjectPath\code\Common\FILE1.c line 5515: ReadCodeObservables4(59? | 0?, [1]?)
File G:\ProjectPath\code\Common\FILE1.c line 5938: HAL__ReadReg(59? | 0?, 176)
G:\ProjectPath\G : \ProjectPath\code\Common\HAL.h 2438 error 662: (Warning -- Possible creation of out-of-bounds pointer (15 beyond end of data) by operator '[' [Reference: file G:\ProjectPath\code\Common\HAL.h: line 2438; file G:\ProjectPath\code\Common\FILE1.c: lines 5471, 5515, 5938])
G:\ProjectPath\G : \ProjectPath\code\Common\HAL.h 2438 error 831: (Info -- Reference cited in prior message)
G:\ProjectPath\G : \ProjectPath\code\Common\FILE1.c 5471 error 831: (Info -- Reference cited in prior message)
G:\ProjectPath\G : \ProjectPath\code\Common\FILE1.c 5515 error 831: (Info -- Reference cited in prior message)
G:\ProjectPath\G : \ProjectPath\code\Common\FILE1.c 5938 error 831: (Info -- Reference cited in prior message)
这是我的配置,Ninja 和 Visual Studio 16 2019 生成器都提供相同的结果。请注意,我有一个没有继承环境的自定义编译器,但是对于这个 LINT 目标,编译器甚至没有被调用,所以我不明白为什么会出现问题。
{
"configurations": [
{
"name": "PROJECT",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [],
"buildRoot": "${projectDir}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"intelliSenseMode": "linux-gcc-arm"
}
]
}
我还尝试使用 Visual Studio 安装目录中的 cmake.exe 从命令行构建此目标,并且错误输出中没有附加额外的路径,因此这绝对是 Visual Studio 的问题。我在这里看到了一些关于“/FC”(诊断标志中源代码文件的完整路径)的报告,但对我来说,项目文件没有生成,所以我无法修改它们。我不知道为什么没有项目/解决方案文件,因为在过去的某个时候它们是自动生成的,但由于我真的不需要它们(也不想依赖它们),所以我从未调查过这个问题。