Skip to content

Improve patching mechanism #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions cmake/modules/CMakeFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ endfunction()
# Then all patches from the `patches_dir` are committed to the `target_branch`.
# Does nothing if the `target_branch` is already checked out in the `repo_dir`.
#
function(apply_patches repo_dir patches_dir base_revision target_branch)
file(GLOB patches ${patches_dir}/*.patch)
function(apply_patches repo_dir patches_dir base_revision target_branch ret)
set(patches "")
foreach(patches_dir ${patches_dir})
file(GLOB patches_in_dir ${patches_dir}/*.patch)
list(APPEND patches ${patches_in_dir})
endforeach()
if(NOT patches)
message(STATUS "[OPENCL-CLANG] No patches in ${patches_dir}")
return()
Expand All @@ -105,7 +109,9 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
ERROR_QUIET
OUTPUT_QUIET
)
if(patches_needed) # The target branch doesn't exist
if(patches_needed EQUAL 128) # not a git repo
set(ret_not_git_repo 1)
elseif(patches_needed) # The target branch doesn't exist
list(SORT patches)
is_valid_revision(${repo_dir} ${base_revision} exists_base_rev)

Expand Down Expand Up @@ -139,8 +145,12 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
WORKING_DIRECTORY ${repo_dir}
OUTPUT_VARIABLE patching_log
ERROR_QUIET
RESULT_VARIABLE ret_apply_patch
)
message(STATUS "[OPENCL-CLANG] Not present - ${patching_log}")
if (ret_apply_patch)
break()
endif()
endif()
endforeach(patch)
else() # The target branch already exists
Expand All @@ -149,8 +159,14 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
WORKING_DIRECTORY ${repo_dir}
ERROR_QUIET
OUTPUT_QUIET
RESULT_VARIABLE ret_check_out
)
endif()
if (NOT (ret_not_git_repo OR ret_check_out OR ret_apply_patch))
set(${ret} True PARENT_SCOPE)
else()
message(FATAL_ERROR "[OPENCL-CLANG] Failed to apply patch!")
endif()
endfunction()

# Usage
Expand Down