@@ -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 ()
154170endfunction ()
155171
156172# Usage
0 commit comments