@@ -56,7 +56,6 @@ function(is_backport_patch_present patch_path repo_dir patch_in_branch)
56
56
WORKING_DIRECTORY ${repo_dir}
57
57
RESULT_VARIABLE patch_not_in_branches
58
58
OUTPUT_QUIET
59
- ERROR_QUIET
60
59
)
61
60
if (patch_not_in_branches)
62
61
set (patch_in_branch False PARENT_SCOPE) # The patch is not present in local branch
@@ -73,7 +72,6 @@ function(is_valid_revision repo_dir revision return_val)
73
72
COMMAND ${GIT_EXECUTABLE} log -1 ${revision}
74
73
WORKING_DIRECTORY ${repo_dir}
75
74
RESULT_VARIABLE output_var
76
- ERROR_QUIET
77
75
OUTPUT_QUIET
78
76
)
79
77
if (${output_var} EQUAL 0)
@@ -95,16 +93,21 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
95
93
return ()
96
94
endif ()
97
95
98
- message (STATUS "[OPENCL-CLANG] Patching repository ${repo_dir} " )
96
+ # Check if it's a git repo
97
+ if (EXISTS "${repo_dir} /.git" )
98
+ message (STATUS "[OPENCL-CLANG] Patching repository ${repo_dir} " )
99
+ else ()
100
+ message (STATUS "[OPENCL-CLANG][Warning] ${repo_dir} is not a git repository, therefore, local patches are not applied" )
101
+ return ()
102
+ endif ()
99
103
# Check if the target branch already exists
100
104
execute_process (
101
105
COMMAND ${GIT_EXECUTABLE} rev-parse --verify --no -revs -q ${target_branch}
102
106
WORKING_DIRECTORY ${repo_dir}
103
107
RESULT_VARIABLE patches_needed
104
- ERROR_QUIET
105
108
OUTPUT_QUIET
106
109
)
107
- if (patches_needed) # The target branch doesn't exist
110
+ if (patches_needed EQUAL 1 ) # The target branch doesn't exist
108
111
list (SORT patches)
109
112
is_valid_revision(${repo_dir} ${base_revision} exists_base_rev)
110
113
@@ -114,7 +117,6 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
114
117
WORKING_DIRECTORY ${repo_dir}
115
118
OUTPUT_VARIABLE repo_head
116
119
OUTPUT_STRIP_TRAILING_WHITESPACE
117
- ERROR_QUIET
118
120
)
119
121
message (STATUS "[OPENCL-CLANG] ref ${base_revision} not exists in repository, using current HEAD:${repo_head} " )
120
122
set (base_revision ${repo_head} )
@@ -134,22 +136,25 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
134
136
message (STATUS "[OPENCL-CLANG] Patch ${patch} is already in local branch - ignore patching" )
135
137
else ()
136
138
execute_process ( # Apply the patch
137
- COMMAND ${GIT_EXECUTABLE} am --3way --ignore -whitespace ${patch}
139
+ COMMAND ${GIT_EXECUTABLE} am --3way --ignore -whitespace -C0 ${patch}
138
140
WORKING_DIRECTORY ${repo_dir}
139
141
OUTPUT_VARIABLE patching_log
140
- ERROR_QUIET
141
142
)
142
143
message (STATUS "[OPENCL-CLANG] Not present - ${patching_log} " )
143
144
endif ()
144
145
endforeach (patch)
145
- else ( ) # The target branch already exists
146
+ elseif (patches_needed EQUAL 0 ) # The target branch already exists
146
147
execute_process ( # Check it out
147
148
COMMAND ${GIT_EXECUTABLE} checkout ${target_branch}
148
149
WORKING_DIRECTORY ${repo_dir}
149
- ERROR_QUIET
150
150
OUTPUT_QUIET
151
151
)
152
152
endif ()
153
+ if (NOT (ret_check_out OR ret_apply_patch))
154
+ message (STATUS "[OPENCL-CLANG] Applied patch successfully!" )
155
+ else ()
156
+ message (FATAL_ERROR "[OPENCL-CLANG] Failed to apply patch!" )
157
+ endif ()
153
158
endfunction ()
154
159
155
160
# Usage
0 commit comments