Skip to content

Commit 32b83ad

Browse files
authored
Enhance copy_onnx (#69058)
* fix * fix
1 parent a566f47 commit 32b83ad

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ repos:
141141
hooks:
142142
- id: cmakelint
143143
args: [--config=./tools/codestyle/.cmakelintrc]
144+
# Exclude some files has false positive warnings
145+
# Need to fix them in the future
146+
exclude: |
147+
(?x)^(
148+
cmake/external/onnxruntime.cmake
149+
)$
144150
# Others
145151
- repo: local
146152
hooks:

cmake/external/onnxruntime.cmake

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,37 @@ add_library(onnxruntime STATIC IMPORTED GLOBAL)
178178
set_property(TARGET onnxruntime PROPERTY IMPORTED_LOCATION ${ONNXRUNTIME_LIB})
179179
add_dependencies(onnxruntime ${ONNXRUNTIME_PROJECT})
180180

181+
if(WIN32)
182+
string(REGEX REPLACE "/" "\\\\" SOURCE_PATH "${ONNXRUNTIME_SHARED_LIB}")
183+
set(ONNX_COPY_PATH
184+
"${CMAKE_BINARY_DIR}/paddle/third_party/onnx_copy_retry.bat")
185+
file(
186+
WRITE ${CMAKE_BINARY_DIR}/paddle/third_party/onnx_copy_retry.bat
187+
""
188+
"set build_times=1\n"
189+
":retry\n"
190+
"ECHO copy_onnx run %build_times% time\n"
191+
"xcopy ${SOURCE_PATH} %1 /Y\n"
192+
"if %ERRORLEVEL% NEQ 0 (\n"
193+
" set /a build_times=%build_times%+1\n"
194+
" if %build_times% GEQ 10 (\n"
195+
" exit /b 1\n"
196+
" ) else (\n"
197+
" goto :retry\n"
198+
" )\n"
199+
")\n"
200+
"exit /b 0")
201+
endif()
202+
181203
function(copy_onnx TARGET_NAME)
182204
# If error of Exitcode0xc000007b happened when a .exe running, copy onnxruntime.dll
183205
# to the .exe folder.
184206
if(TARGET ${TARGET_NAME})
207+
string(REGEX REPLACE "/" "\\\\" DESTINATION_PATH
208+
"${CMAKE_CURRENT_BINARY_DIR}")
185209
add_custom_command(
186210
TARGET ${TARGET_NAME}
187211
POST_BUILD
188-
COMMAND ${CMAKE_COMMAND} -E copy ${ONNXRUNTIME_SHARED_LIB}
189-
${CMAKE_CURRENT_BINARY_DIR} DEPENDS onnxruntime)
212+
COMMAND ${ONNX_COPY_PATH} ${DESTINATION_PATH} DEPENDS onnxruntime)
190213
endif()
191214
endfunction()

0 commit comments

Comments
 (0)