Skip to content

Commit

Permalink
Do not apply patches if repo is a not a git repo.
Browse files Browse the repository at this point in the history
Also backports fb75598
  • Loading branch information
haonanya1 committed Jul 3, 2024
1 parent 2c7782a commit b30da55
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cmake/modules/CMakeFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
COMMAND ${GIT_EXECUTABLE} rev-parse --verify --no-revs -q ${target_branch}
WORKING_DIRECTORY ${repo_dir}
RESULT_VARIABLE patches_needed
ERROR_QUIET
OUTPUT_QUIET
)
if(patches_needed) # The target branch doesn't exist
if(patches_needed EQUAL 128) # not a git repo
message(STATUS "[OPENCL-CLANG] ${repo_dir} is not a git repository")
return()
elseif(patches_needed EQUAL 1) # The target branch doesn't exist
list(SORT patches)
is_valid_revision(${repo_dir} ${base_revision} exists_base_rev)

Expand All @@ -115,7 +117,6 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
WORKING_DIRECTORY ${repo_dir}
OUTPUT_VARIABLE repo_head
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
message(STATUS "[OPENCL-CLANG] ref ${base_revision} not exists in repository, using current HEAD:${repo_head}")
set(base_revision ${repo_head})
Expand All @@ -135,22 +136,23 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
message(STATUS "[OPENCL-CLANG] Patch ${patch} is already in local branch - ignore patching")
else()
execute_process( # Apply the patch
COMMAND ${GIT_EXECUTABLE} am --3way --ignore-whitespace ${patch}
COMMAND ${GIT_EXECUTABLE} am --3way --ignore-whitespace -C0 ${patch}
WORKING_DIRECTORY ${repo_dir}
OUTPUT_VARIABLE patching_log
ERROR_QUIET
)
message(STATUS "[OPENCL-CLANG] Not present - ${patching_log}")
endif()
endforeach(patch)
else() # The target branch already exists
elseif(patches_needed EQUAL 0) # The target branch already exists
execute_process( # Check it out
COMMAND ${GIT_EXECUTABLE} checkout ${target_branch}
WORKING_DIRECTORY ${repo_dir}
ERROR_QUIET
OUTPUT_QUIET
)
endif()
if (ret_check_out OR ret_apply_patch)
message(FATAL_ERROR "[OPENCL-CLANG] Failed to apply patch!")
endif()
endfunction()

# Usage
Expand Down

0 comments on commit b30da55

Please sign in to comment.