Skip to content

Configuration stage patching - "ov_apply_patch()"#36898

Open
bumbosiepsak wants to merge 1 commit into
openvinotoolkit:masterfrom
bumbosiepsak:CVS-187110-cmake-patching
Open

Configuration stage patching - "ov_apply_patch()"#36898
bumbosiepsak wants to merge 1 commit into
openvinotoolkit:masterfrom
bumbosiepsak:CVS-187110-cmake-patching

Conversation

@bumbosiepsak

Copy link
Copy Markdown
Contributor

Details:

  • Generic "ov_apply_patch()" added for patching sources at configure time
  • Part of the "ONNX update" story which requires patching dependant Protobuf for C++20 builds on MSVC
  • Delivered separately for the sake of easier and more targeted review

Tickets:

AI Assistance:

  • AI assistance used: yes

@bumbosiepsak bumbosiepsak requested a review from a team as a code owner July 15, 2026 10:09
@github-actions github-actions Bot added the category: build OpenVINO cmake script / infra label Jul 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via git apply with an idempotency sentinel.
  • Added the new patches.cmake module 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.

Comment thread cmake/developer_package/patches.cmake Outdated
Comment thread cmake/developer_package/patches.cmake Outdated
Comment thread cmake/developer_package/patches.cmake

@olpipi olpipi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment on lines +5 to +25
#
# 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()
Comment on lines +71 to +85
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general there is no need for such tool
The ONNX, proto should be pinned with correct version without any patch apply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: build OpenVINO cmake script / infra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants