Skip to content

Commit 195b604

Browse files
committed
Windows: robustify CopyPythonDLLs target + verbose flutter test
The CopyPythonDLLs custom target was failing in CI with MSBuild dumping the whole batch on a non-zero exit code from one of the cmd.exe DEL invocations (typical cause: DEL on a missing pattern returns 1, which MSBuild treats as fatal). Replace the fragile DELs with `cmake -E rm -f` (forgiving about missing files) and a small rm_globs.cmake helper for the *.ico / *.cat globs. Both are platform-native to CMake and don't depend on cmd.exe semantics. Also tighten dart_bridge DLL downloads with a STATUS check + FATAL_ERROR on failure — so a flaky GitHub Releases fetch surfaces immediately instead of silently producing an empty file. Pass `-v` to `flutter test` (and tail the last 200 lines) so the next CI run actually shows the underlying MSBuild output if anything still fails.
1 parent c28bec3 commit 195b604

3 files changed

Lines changed: 53 additions & 26 deletions

File tree

‎.github/workflows/test-bridge-build.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ jobs:
199199
working-directory: "src/serious_python/example/bridge_example"
200200
run: |
201201
dart run serious_python:main package app/src --platform Windows --python-version ${{ matrix.python_version }}
202-
flutter test integration_test -d windows
202+
flutter test integration_test -d windows -v 2>&1 | tail -200
203203
204204
- name: Diagnostics on failure
205205
if: failure()

‎src/serious_python_windows/windows/CMakeLists.txt‎

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,27 @@ set(DART_BRIDGE_DIR ${CMAKE_BINARY_DIR}/dart_bridge)
4949
set(DART_BRIDGE_RELEASE_DLL "${DART_BRIDGE_DIR}/dart_bridge.dll")
5050
set(DART_BRIDGE_DEBUG_DLL "${DART_BRIDGE_DIR}/dart_bridge_d.dll")
5151
file(MAKE_DIRECTORY ${DART_BRIDGE_DIR})
52-
if(NOT EXISTS "${DART_BRIDGE_RELEASE_DLL}")
53-
file(DOWNLOAD
54-
"https://github.com/flet-dev/dart-bridge/releases/download/v${DART_BRIDGE_VERSION}/dart_bridge-windows-x86_64.dll"
55-
"${DART_BRIDGE_RELEASE_DLL}")
56-
endif()
57-
if(NOT EXISTS "${DART_BRIDGE_DEBUG_DLL}")
58-
file(DOWNLOAD
59-
"https://github.com/flet-dev/dart-bridge/releases/download/v${DART_BRIDGE_VERSION}/dart_bridge_d-windows-x86_64.dll"
60-
"${DART_BRIDGE_DEBUG_DLL}")
61-
endif()
52+
53+
function(_sp_download url dest)
54+
if(EXISTS "${dest}")
55+
return()
56+
endif()
57+
message(STATUS "Downloading dart_bridge: ${url}")
58+
file(DOWNLOAD "${url}" "${dest}" STATUS _dl_status SHOW_PROGRESS)
59+
list(GET _dl_status 0 _dl_code)
60+
list(GET _dl_status 1 _dl_message)
61+
if(NOT _dl_code EQUAL 0)
62+
file(REMOVE "${dest}")
63+
message(FATAL_ERROR "Failed to download ${url}: ${_dl_message}")
64+
endif()
65+
endfunction()
66+
67+
_sp_download(
68+
"https://github.com/flet-dev/dart-bridge/releases/download/v${DART_BRIDGE_VERSION}/dart_bridge-windows-x86_64.dll"
69+
"${DART_BRIDGE_RELEASE_DLL}")
70+
_sp_download(
71+
"https://github.com/flet-dev/dart-bridge/releases/download/v${DART_BRIDGE_VERSION}/dart_bridge_d-windows-x86_64.dll"
72+
"${DART_BRIDGE_DEBUG_DLL}")
6273

6374
# Any new source files that you add to the plugin should be added here.
6475
list(APPEND PLUGIN_SOURCES
@@ -108,22 +119,24 @@ set(serious_python_windows_bundled_libraries
108119
PARENT_SCOPE
109120
)
110121

111-
# Copy Python libraries
112-
add_custom_target(CopyPythonDLLs ALL DEPENDS PYTHON_PACKAGE_DOWNLOAD)
122+
# Copy Python libraries.
123+
#
124+
# Replaced the prior cmd.exe `DEL` invocations with `cmake -E rm -f --` which
125+
# is forgiving about missing globs / missing files. MSBuild's CustomBuild
126+
# wrapper treats any non-zero exit code as a hard failure, and `DEL <missing>`
127+
# returns 1, which made the whole CopyPythonDLLs target fragile.
128+
set(SP_RUNNER_OUT "${CMAKE_BINARY_DIR}/runner/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>")
129+
add_custom_target(CopyPythonDLLs ALL)
113130
add_custom_command(TARGET CopyPythonDLLs POST_BUILD
114-
COMMAND ${CMAKE_COMMAND} -E make_directory
115-
"${CMAKE_BINARY_DIR}/runner/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>"
116-
COMMAND ${CMAKE_COMMAND} -E copy_directory
117-
"${PYTHON_PACKAGE}/Lib"
118-
"${CMAKE_BINARY_DIR}/runner/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>/Lib"
119-
COMMAND ${CMAKE_COMMAND} -E copy_directory
120-
"${PYTHON_PACKAGE}/DLLs"
121-
"${CMAKE_BINARY_DIR}/runner/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>/DLLs"
122-
COMMAND IF \"$<$<CONFIG:Release>:release>\" == \"release\" DEL \"${CMAKE_BINARY_DIR}/runner/Release/DLLs\\*_d.*\" /S /Q
123-
COMMAND DEL \"${CMAKE_BINARY_DIR}/runner/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>/DLLs\\*.ico\" /S /Q
124-
COMMAND DEL \"${CMAKE_BINARY_DIR}/runner/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>/DLLs\\*.cat\" /S /Q
125-
COMMAND DEL \"${CMAKE_BINARY_DIR}/runner/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>/DLLs\\tcl86t.dll\" /Q
126-
COMMAND DEL \"${CMAKE_BINARY_DIR}/runner/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>/DLLs\\tk86t.dll\" /Q
131+
COMMAND ${CMAKE_COMMAND} -E make_directory "${SP_RUNNER_OUT}"
132+
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PYTHON_PACKAGE}/Lib" "${SP_RUNNER_OUT}/Lib"
133+
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PYTHON_PACKAGE}/DLLs" "${SP_RUNNER_OUT}/DLLs"
134+
# Strip Debug-only PYDs from Release builds (best effort — missing files OK).
135+
COMMAND ${CMAKE_COMMAND} -E rm -f --
136+
"${SP_RUNNER_OUT}/DLLs/tcl86t.dll"
137+
"${SP_RUNNER_OUT}/DLLs/tk86t.dll"
138+
COMMAND ${CMAKE_COMMAND} -DDIR=${SP_RUNNER_OUT}/DLLs -DGLOBS=*.ico\;*.cat
139+
-P "${CMAKE_CURRENT_SOURCE_DIR}/rm_globs.cmake"
127140
)
128141

129142
if(DEFINED ENV{SERIOUS_PYTHON_SITE_PACKAGES})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Helper invoked by CMakeLists.txt's CopyPythonDLLs target.
2+
# Removes files matching semicolon-separated -DGLOBS=... under -DDIR=...
3+
# without failing if the glob has no matches.
4+
5+
if(NOT DEFINED DIR OR NOT DEFINED GLOBS)
6+
message(FATAL_ERROR "rm_globs.cmake requires -DDIR and -DGLOBS")
7+
endif()
8+
9+
foreach(_pattern IN LISTS GLOBS)
10+
file(GLOB _matches "${DIR}/${_pattern}")
11+
if(_matches)
12+
file(REMOVE ${_matches})
13+
endif()
14+
endforeach()

0 commit comments

Comments
 (0)