Configuration stage patching - "ov_apply_patch()"#36898
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a reusable CMake helper (ov_apply_patch()) for applying local .patch files during the configure stage, intended to support upcoming dependency adjustments (notably Protobuf for MSVC C++20 as part of the ONNX update work).
Changes:
- Added
ov_apply_patch()CMake function to apply patches viagit applywith an idempotency sentinel. - Added the new
patches.cmakemodule to the developer scripts config so it’s available across the developer package CMake flow.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
cmake/developer_package/patches.cmake |
New ov_apply_patch() implementation (argument parsing, Git discovery fallback, sentinel-based idempotency, git apply invocation). |
cmake/developer_package/OpenVINODeveloperScriptsConfig.cmake |
Includes the new patches module so the helper is available during configuration. |
olpipi
left a comment
There was a problem hiding this comment.
This looks potentially unsafe, as applying patches during CMake configuration may modify CMake files mid-configure or leave the source and build-tree patch state out of sync.
If possible, please apply the patch outside of CMake instead.
- Generic "ov_apply_patch()" added for patching sources at configure time
7f19673 to
c69bcba
Compare
| # | ||
| # ov_apply_patch( | ||
| # PATCH <absolute-path-to-.patch-file> | ||
| # [WORKING_DIRECTORY <dir>] -- directory passed to 'git apply'; defaults to CMAKE_SOURCE_DIR | ||
| # ) | ||
| # | ||
| # Applies a local patch file via 'git apply' during the CMake configure phase. | ||
| # Idempotent: uses 'git apply --reverse --check' to detect whether the patch is | ||
| # already applied and skips the apply step if so. | ||
| # Relies on GIT_FOUND / GIT_EXECUTABLE, which are set by find_package(Git) in version.cmake. | ||
| # | ||
| function(ov_apply_patch) | ||
| cmake_parse_arguments(ARG "" "PATCH;WORKING_DIRECTORY" "" ${ARGN}) | ||
|
|
||
| if(NOT DEFINED ARG_PATCH OR ARG_PATCH STREQUAL "") | ||
| message(FATAL_ERROR "ov_apply_patch: PATCH argument is required") | ||
| endif() | ||
|
|
||
| if(NOT EXISTS "${ARG_PATCH}") | ||
| message(FATAL_ERROR "ov_apply_patch: patch file does not exist: ${ARG_PATCH}") | ||
| endif() |
| execute_process( | ||
| COMMAND "${GIT_EXECUTABLE}" -c core.autocrlf=false apply | ||
| --ignore-space-change | ||
| --ignore-whitespace | ||
| "${ARG_PATCH}" | ||
| WORKING_DIRECTORY "${ARG_WORKING_DIRECTORY}" | ||
| RESULT_VARIABLE _ov_patch_rc | ||
| ERROR_VARIABLE _ov_patch_err | ||
| OUTPUT_QUIET | ||
| ) | ||
|
|
||
| if(NOT _ov_patch_rc EQUAL 0) | ||
| message(FATAL_ERROR | ||
| "ov_apply_patch: failed to apply '${_patch_display}':\n${_ov_patch_err}") | ||
| endif() |
| # already applied and skips the apply step if so. | ||
| # Relies on GIT_FOUND / GIT_EXECUTABLE, which are set by find_package(Git) in version.cmake. | ||
| # | ||
| function(ov_apply_patch) |
There was a problem hiding this comment.
In general there is no need for such tool
The ONNX, proto should be pinned with correct version without any patch apply
Details:
Tickets:
AI Assistance: