Visual Studio CMake 构建日志添加项目路径并中断错误解析

问题描述

我设法将 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”(诊断标志中的源代码文件的完整路径)here 的报告,但对我来说,项目文件没有生成,所以我无法修改它们。我不知道为什么没有项目/解决方文件,因为在过去的某个时候它们是自动生成的,但是由于我真的不需要它们(并且不想依赖它们),我从未调查过这个问题。

解决方法

通过进一步调查,我能够通过为 PC-Lint 使用不同的输出格式来解决问题:

-"format=%(%F(%l):%) error %n: %t -- %m"