Skip to content

Commit dbf6f64

Browse files
committed
Do not apply patches if repo is a not a git repo.
Also backports fb75598
1 parent 2c7782a commit dbf6f64

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

cmake/modules/CMakeFunctions.cmake

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ function(is_backport_patch_present patch_path repo_dir patch_in_branch)
5757
WORKING_DIRECTORY ${repo_dir}
5858
RESULT_VARIABLE patch_not_in_branches
5959
OUTPUT_QUIET
60-
ERROR_QUIET
6160
)
6261
if(patch_not_in_branches)
6362
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)
7473
COMMAND ${GIT_EXECUTABLE} log -1 ${revision}
7574
WORKING_DIRECTORY ${repo_dir}
7675
RESULT_VARIABLE output_var
77-
ERROR_QUIET
7876
OUTPUT_QUIET
7977
)
8078
if(${output_var} EQUAL 0)
@@ -102,10 +100,12 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
102100
COMMAND ${GIT_EXECUTABLE} rev-parse --verify --no-revs -q ${target_branch}
103101
WORKING_DIRECTORY ${repo_dir}
104102
RESULT_VARIABLE patches_needed
105-
ERROR_QUIET
106103
OUTPUT_QUIET
107104
)
108-
if(patches_needed) # The target branch doesn't exist
105+
if(patches_needed EQUAL 128) # not a git repo
106+
message(STATUS "[OPENCL-CLANG] ${repo_dir} is not a git repository")
107+
return()
108+
elseif(patches_needed EQUAL 1) # The target branch doesn't exist
109109
list(SORT patches)
110110
is_valid_revision(${repo_dir} ${base_revision} exists_base_rev)
111111

@@ -115,7 +115,6 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
115115
WORKING_DIRECTORY ${repo_dir}
116116
OUTPUT_VARIABLE repo_head
117117
OUTPUT_STRIP_TRAILING_WHITESPACE
118-
ERROR_QUIET
119118
)
120119
message(STATUS "[OPENCL-CLANG] ref ${base_revision} not exists in repository, using current HEAD:${repo_head}")
121120
set(base_revision ${repo_head})
@@ -135,22 +134,23 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
135134
message(STATUS "[OPENCL-CLANG] Patch ${patch} is already in local branch - ignore patching")
136135
else()
137136
execute_process( # Apply the patch
138-
COMMAND ${GIT_EXECUTABLE} am --3way --ignore-whitespace ${patch}
137+
COMMAND ${GIT_EXECUTABLE} am --3way --ignore-whitespace -C0 ${patch}
139138
WORKING_DIRECTORY ${repo_dir}
140139
OUTPUT_VARIABLE patching_log
141-
ERROR_QUIET
142140
)
143141
message(STATUS "[OPENCL-CLANG] Not present - ${patching_log}")
144142
endif()
145143
endforeach(patch)
146-
else() # The target branch already exists
144+
elseif(patches_needed EQUAL 0) # The target branch already exists
147145
execute_process( # Check it out
148146
COMMAND ${GIT_EXECUTABLE} checkout ${target_branch}
149147
WORKING_DIRECTORY ${repo_dir}
150-
ERROR_QUIET
151148
OUTPUT_QUIET
152149
)
153150
endif()
151+
if (ret_check_out OR ret_apply_patch)
152+
message(FATAL_ERROR "[OPENCL-CLANG] Failed to apply patch!")
153+
endif()
154154
endfunction()
155155

156156
# Usage

0 commit comments

Comments
 (0)