Skip to content

Commit 5824297

Browse files
authored
[Backport] Do not apply patches if sub non-git repo is located in a git repo. (#540)
[Backport] Do not apply patches if repo is a not a git repo. #539 [Backport] Do not apply patches if sub non-git repo is located in a git repo. #545 Also add an option to control patch apply which is default on. Pass -DAPPLY_PATCHES=OFF will skip patch apply process.
1 parent af6278e commit 5824297

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

CMakeLists.txt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ if(LLVM_USE_HOST_TOOLS AND OPENCL_CLANG_BUILD_EXTERNAL)
4040
llvm_create_cross_target(${PROJECT_NAME} NATIVE "" Release)
4141
endif()
4242

43+
option(LLVMSPIRV_INCLUDED_IN_LLVM
44+
"Set to ON if libLLVMSPIRVLib is linked into libLLVM" ON)
45+
option(APPLY_PATCHES "Apply local patches" ON)
46+
4347
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
4448
set(USE_PREBUILT_LLVM ON)
4549

@@ -61,8 +65,6 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
6165
set(CMAKE_CXX_STANDARD 14)
6266
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6367

64-
option(LLVMSPIRV_INCLUDED_IN_LLVM
65-
"Set to ON if libLLVMSPIRVLib is linked into libLLVM" ON)
6668
if(LLVMSPIRV_INCLUDED_IN_LLVM)
6769
message(STATUS "[OPENCL-CLANG] Assuming that libLLVMSPIRVLib is linked into libLLVM")
6870
else(LLVMSPIRV_INCLUDED_IN_LLVM)
@@ -152,16 +154,20 @@ if(NOT USE_PREBUILT_LLVM)
152154
get_filename_component(LLVM_MONOREPO_DIR ${LLVM_SOURCE_DIR} DIRECTORY)
153155
set(LLVM_PATCHES_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm
154156
${CMAKE_CURRENT_SOURCE_DIR}/patches/clang)
155-
apply_patches(${LLVM_MONOREPO_DIR}
156-
"${LLVM_PATCHES_DIRS}"
157-
${LLVM_BASE_REVISION}
158-
${TARGET_BRANCH}
159-
ret)
160-
apply_patches(${SPIRV_SOURCE_DIR}
161-
${CMAKE_CURRENT_SOURCE_DIR}/patches/spirv
162-
${SPIRV_BASE_REVISION}
163-
${TARGET_BRANCH}
164-
ret)
157+
158+
if(APPLY_PATCHES)
159+
message(STATUS "APPLY_PATCHES is enabled.")
160+
apply_patches(${LLVM_MONOREPO_DIR}
161+
"${LLVM_PATCHES_DIRS}"
162+
${LLVM_BASE_REVISION}
163+
${TARGET_BRANCH})
164+
apply_patches(${SPIRV_SOURCE_DIR}
165+
${CMAKE_CURRENT_SOURCE_DIR}/patches/spirv
166+
${SPIRV_BASE_REVISION}
167+
${TARGET_BRANCH})
168+
else()
169+
message(STATUS "APPLY_PATCHES is disabled, skip patch apply process.")
170+
endif()
165171
endif(NOT USE_PREBUILT_LLVM)
166172

167173
#

cmake/modules/CMakeFunctions.cmake

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ endfunction()
8787
# Then all patches from the `patches_dir` are committed to the `target_branch`.
8888
# Does nothing if the `target_branch` is already checked out in the `repo_dir`.
8989
#
90-
function(apply_patches repo_dir patches_dir base_revision target_branch ret)
90+
function(apply_patches repo_dir patches_dir base_revision target_branch)
9191
foreach(patches_dir ${patches_dir})
9292
file(GLOB patches_in_dir ${patches_dir}/*.patch)
9393
list(APPEND patches ${patches_in_dir})
@@ -97,17 +97,21 @@ function(apply_patches repo_dir patches_dir base_revision target_branch ret)
9797
return()
9898
endif()
9999

100-
message(STATUS "[OPENCL-CLANG] Patching repository ${repo_dir}")
100+
# Check if it's a git repo
101+
if(EXISTS "${repo_dir}/.git")
102+
message(STATUS "[OPENCL-CLANG] Patching repository ${repo_dir}")
103+
else()
104+
message(STATUS "[OPENCL-CLANG][Warning] ${repo_dir} is not a git repository, therefore, local patches are not applied")
105+
return()
106+
endif()
101107
# Check if the target branch already exists
102108
execute_process(
103109
COMMAND ${GIT_EXECUTABLE} rev-parse --verify --no-revs -q ${target_branch}
104110
WORKING_DIRECTORY ${repo_dir}
105111
RESULT_VARIABLE patches_needed
106112
OUTPUT_QUIET
107113
)
108-
if(patches_needed EQUAL 128) # not a git repo
109-
set(ret_not_git_repo 1)
110-
elseif(patches_needed) # The target branch doesn't exist
114+
if(patches_needed EQUAL 1) # The target branch doesn't exist
111115
list(SORT patches)
112116
is_valid_revision(${repo_dir} ${base_revision} exists_base_rev)
113117

@@ -147,16 +151,16 @@ function(apply_patches repo_dir patches_dir base_revision target_branch ret)
147151
endif()
148152
endif()
149153
endforeach(patch)
150-
else() # The target branch already exists
154+
elseif(patches_needed EQUAL 0) # The target branch already exists
151155
execute_process( # Check it out
152156
COMMAND ${GIT_EXECUTABLE} checkout ${target_branch}
153157
WORKING_DIRECTORY ${repo_dir}
154158
OUTPUT_QUIET
155159
RESULT_VARIABLE ret_check_out
156160
)
157161
endif()
158-
if (NOT (ret_not_git_repo OR ret_check_out OR ret_apply_patch))
159-
set(${ret} True PARENT_SCOPE)
162+
if (NOT (ret_check_out OR ret_apply_patch))
163+
message(STATUS "[OPENCL-CLANG] Applied patch successfully!")
160164
else()
161165
message(FATAL_ERROR "[OPENCL-CLANG] Failed to apply patch!")
162166
endif()

0 commit comments

Comments
 (0)