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