背景
上一篇mpr的推到GitHub上,本来以为不会有啥问题,结果ci打包的失败了。这一篇是解决问题的。
正文
git ci 失败
从流程来看,是Windows build就失败了。
追踪日志,结论是生成test的超时了。。但是如果直接补超时时间不一定能解决问题,还是得在Windows下编译才能知道是不是超时导致的

window cmake 插件编译
因为上面的bug是在Windows下编译出现的,先解决Windows下编译的。 之前因为都是wsl下,然后Windows下只用了脚本编译,这一次使用了vscode的插件cmake编译
一开始尝试环境变量,结果没生效,可能是到vscode的cmake这一次继承的环境变量有问题(用的系统变量设置的,重启也无效,从控制台输出环境变量是正常),最终直接在CMakePresets.json写死了,如下所示
bash
{
"name": "win-vcpkg-debug",
"displayName": "Windows vcpkg",
"description": "Debug build on Windows (x64-windows)",
"binaryDir": "${sourceDir}/build",
"generator": "",
"toolchainFile": "D:/vcpkg/scripts/buildsystems/vcpkg.cmake",
"environment": {
"VCPKG_ROOT": "D:/vcpkg"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CXX_FLAGS": "",
"VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/triplets",
"VCPKG_TARGET_TRIPLET": "x64-windows",
"AUTO_TESTING": "ON",
"DEPLOY_QT_PLUGINS": "ON"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},

Windows 编译触发
编译过程中会跳出如下窗口

有这弹框,基本上补超时时间是没用了
执行单个的测试来重现
bash
D:/xcyxiner/DicomViewer/build/Debug/ViewMode_test.exe --gtest_list_tests

从结果来看,设置超时应该是没用了,缺少类库
给AI输入
从结果来看,是因为你开了无头模式,但是在Windows下,没有找到对应的插件导致的

AI 给的修复意见

拷贝插件并测试

修复过程 CMakeLists.txt 补拷贝方法,生成测试文件前调用
bash
# ---- Windows: 自动部署 Qt 插件 ----
# 用整目录拷贝代替逐个 DLL 点名:platforms 里的 offscreen/minimal 等
# 无头插件是测试 (gtest_discover_tests) 在构建期就要加载的,漏拷会导致
# 发现阶段超时;imageformats/styles/generic 供运行时按需加载。
option(DEPLOY_QT_PLUGINS "Auto-copy Qt plugins after build" OFF)
if(WIN32 AND MSVC AND DEPLOY_QT_PLUGINS)
set(_qt_vcpkg_root
"${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}")
# Debug 走 debug 树(DLL 带 d 后缀),其余配置走 release 树
set(_qt_plugin_tree
"$<IF:$<CONFIG:Debug>,debug/,>")
function(_deploy_qt_plugins target)
foreach(_plugin_cat platforms imageformats styles generic)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${_qt_vcpkg_root}/${_qt_plugin_tree}Qt6/plugins/${_plugin_cat}"
"$<TARGET_FILE_DIR:${target}>/${_plugin_cat}"
COMMENT "Deploying Qt ${_plugin_cat} plugins ($<CONFIG>)"
)
endforeach()
endfunction()
_deploy_qt_plugins(DicomViewer_exe)
endif()

重新编译并跑所有的测试

git commit
