Skip to content

Commit 470cf00

Browse files
authored
Do not apply patches if sub non-git repo is located in a git repo. (#545)
follow up #539. Also add an option to control patch apply which is default on. Pass -DAPPLY_PATCHES=OFF will skip patch apply process.
1 parent e03e0e3 commit 470cf00

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

CMakeLists.txt

Lines changed: 17 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,19 @@ 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+
if(APPLY_PATCHES)
158+
message(STATUS "APPLY_PATCHES is enabled.")
159+
apply_patches(${LLVM_MONOREPO_DIR}
160+
"${LLVM_PATCHES_DIRS}"
161+
${LLVM_BASE_REVISION}
162+
${TARGET_BRANCH})
163+
apply_patches(${SPIRV_SOURCE_DIR}
164+
${CMAKE_CURRENT_SOURCE_DIR}/patches/spirv
165+
${SPIRV_BASE_REVISION}
166+
${TARGET_BRANCH})
167+
else()
168+
message(STATUS "APPLY_PATCHES is disabled, skip patch apply process.")
169+
endif()
165170
endif(NOT USE_PREBUILT_LLVM)
166171

167172
#

cmake/modules/CMakeFunctions.cmake

Lines changed: 9 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,19 +97,20 @@ 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} True PARENT_SCOPE)
110-
message(STATUS "[OPENCL-CLANG][Warning] ${repo_dir} is not a git repository, therefore, local patches are not applied")
111-
return()
112-
endif()
113114
if(patches_needed EQUAL 1) # The target branch doesn't exist
114115
list(SORT patches)
115116
is_valid_revision(${repo_dir} ${base_revision} exists_base_rev)
@@ -159,7 +160,7 @@ function(apply_patches repo_dir patches_dir base_revision target_branch ret)
159160
)
160161
endif()
161162
if (NOT (ret_check_out OR ret_apply_patch))
162-
set(${ret} True PARENT_SCOPE)
163+
message(STATUS "[OPENCL-CLANG] Applied patch successfully!")
163164
else()
164165
message(FATAL_ERROR "[OPENCL-CLANG] Failed to apply patch!")
165166
endif()

0 commit comments

Comments
 (0)