Skip to content

Commit 439a5c4

Browse files
authored
Improve patching mechanism (#307)
* Improve patching mechanism This backports patches from other branches 1. Check if apply_patches is successful, #175 2. Apply llvm/clang patches together, #179 3. Exit CMake processing when apply_patches failed, #304 Signed-off-by: haonanya <[email protected]> * Skip the rest when apply patch failed Signed-off-by: haonanya <[email protected]>
1 parent cf2f848 commit 439a5c4

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

cmake/modules/CMakeFunctions.cmake

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ endfunction()
8989
# Then all patches from the `patches_dir` are committed to the `target_branch`.
9090
# Does nothing if the `target_branch` is already checked out in the `repo_dir`.
9191
#
92-
function(apply_patches repo_dir patches_dir base_revision target_branch)
93-
file(GLOB patches ${patches_dir}/*.patch)
92+
function(apply_patches repo_dir patches_dir base_revision target_branch ret)
93+
set(patches "")
94+
foreach(patches_dir ${patches_dir})
95+
file(GLOB patches_in_dir ${patches_dir}/*.patch)
96+
list(APPEND patches ${patches_in_dir})
97+
endforeach()
9498
if(NOT patches)
9599
message(STATUS "[OPENCL-CLANG] No patches in ${patches_dir}")
96100
return()
@@ -105,7 +109,9 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
105109
ERROR_QUIET
106110
OUTPUT_QUIET
107111
)
108-
if(patches_needed) # The target branch doesn't exist
112+
if(patches_needed EQUAL 128) # not a git repo
113+
set(ret_not_git_repo 1)
114+
elseif(patches_needed) # The target branch doesn't exist
109115
list(SORT patches)
110116
is_valid_revision(${repo_dir} ${base_revision} exists_base_rev)
111117

@@ -139,8 +145,12 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
139145
WORKING_DIRECTORY ${repo_dir}
140146
OUTPUT_VARIABLE patching_log
141147
ERROR_QUIET
148+
RESULT_VARIABLE ret_apply_patch
142149
)
143150
message(STATUS "[OPENCL-CLANG] Not present - ${patching_log}")
151+
if (ret_apply_patch)
152+
break()
153+
endif()
144154
endif()
145155
endforeach(patch)
146156
else() # The target branch already exists
@@ -149,8 +159,14 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
149159
WORKING_DIRECTORY ${repo_dir}
150160
ERROR_QUIET
151161
OUTPUT_QUIET
162+
RESULT_VARIABLE ret_check_out
152163
)
153164
endif()
165+
if (NOT (ret_not_git_repo OR ret_check_out OR ret_apply_patch))
166+
set(${ret} True PARENT_SCOPE)
167+
else()
168+
message(FATAL_ERROR "[OPENCL-CLANG] Failed to apply patch!")
169+
endif()
154170
endfunction()
155171

156172
# Usage

0 commit comments

Comments
 (0)