Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not apply patches if sub non-git repo is located in a git repo. #545

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ if(LLVM_USE_HOST_TOOLS AND OPENCL_CLANG_BUILD_EXTERNAL)
llvm_create_cross_target(${PROJECT_NAME} NATIVE "" Release)
endif()

option(LLVMSPIRV_INCLUDED_IN_LLVM
"Set to ON if libLLVMSPIRVLib is linked into libLLVM" ON)
option(APPLY_PATCHES "option to apply patches" ON)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Apply local patches"


if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(USE_PREBUILT_LLVM ON)

Expand All @@ -61,8 +65,6 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(LLVMSPIRV_INCLUDED_IN_LLVM
"Set to ON if libLLVMSPIRVLib is linked into libLLVM" ON)
if(LLVMSPIRV_INCLUDED_IN_LLVM)
message(STATUS "[OPENCL-CLANG] Assuming that libLLVMSPIRVLib is linked into libLLVM")
else(LLVMSPIRV_INCLUDED_IN_LLVM)
Expand Down Expand Up @@ -152,16 +154,19 @@ if(NOT USE_PREBUILT_LLVM)
get_filename_component(LLVM_MONOREPO_DIR ${LLVM_SOURCE_DIR} DIRECTORY)
set(LLVM_PATCHES_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm
${CMAKE_CURRENT_SOURCE_DIR}/patches/clang)
apply_patches(${LLVM_MONOREPO_DIR}
"${LLVM_PATCHES_DIRS}"
${LLVM_BASE_REVISION}
${TARGET_BRANCH}
ret)
apply_patches(${SPIRV_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/patches/spirv
${SPIRV_BASE_REVISION}
${TARGET_BRANCH}
ret)
if(APPLY_PATCHES)
message(STATUS "APPLY_PATCHES is enabled.")
apply_patches(${LLVM_MONOREPO_DIR}
"${LLVM_PATCHES_DIRS}"
${LLVM_BASE_REVISION}
${TARGET_BRANCH})
apply_patches(${SPIRV_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/patches/spirv
${SPIRV_BASE_REVISION}
${TARGET_BRANCH})
else()
message(STATUS "APPLY_PATCHES is disabled, skip patch apply process.")
endif()
endif(NOT USE_PREBUILT_LLVM)

#
Expand Down
17 changes: 9 additions & 8 deletions cmake/modules/CMakeFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ endfunction()
# Then all patches from the `patches_dir` are committed to the `target_branch`.
# Does nothing if the `target_branch` is already checked out in the `repo_dir`.
#
function(apply_patches repo_dir patches_dir base_revision target_branch ret)
function(apply_patches repo_dir patches_dir base_revision target_branch)
foreach(patches_dir ${patches_dir})
file(GLOB patches_in_dir ${patches_dir}/*.patch)
list(APPEND patches ${patches_in_dir})
Expand All @@ -97,19 +97,20 @@ function(apply_patches repo_dir patches_dir base_revision target_branch ret)
return()
endif()

message(STATUS "[OPENCL-CLANG] Patching repository ${repo_dir}")
# Check if it's a git repo
if(EXISTS "${repo_dir}/.git")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@haonanya haonanya Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems git rev-parse --is-inside-work-tree can't work. I copy opencl-clang source code to /export/users/haonanya/ocl-clang/llvm/projects/, and git rev-parse --is-inside-work-tree return true.

[haonanya@shliclel4059 opencl-clang]$ git rev-parse --is-inside-work-tree
true
[haonanya@shliclel4059 opencl-clang]$ pwd
/export/users/haonanya/ocl-clang/llvm/projects/opencl-clang

So when llvm is as a sub-dir in a repo, the command can't detect it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

message(STATUS "[OPENCL-CLANG] Patching repository ${repo_dir}")
else()
message(STATUS "[OPENCL-CLANG][Warning] ${repo_dir} is not a git repository, therefore, local patches are not applied")
return()
endif()
# Check if the target branch already exists
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --verify --no-revs -q ${target_branch}
WORKING_DIRECTORY ${repo_dir}
RESULT_VARIABLE patches_needed
OUTPUT_QUIET
)
if(patches_needed EQUAL 128) # not a git repo
set(${ret} True PARENT_SCOPE)
message(STATUS "[OPENCL-CLANG][Warning] ${repo_dir} is not a git repository, therefore, local patches are not applied")
return()
endif()
if(patches_needed EQUAL 1) # The target branch doesn't exist
list(SORT patches)
is_valid_revision(${repo_dir} ${base_revision} exists_base_rev)
Expand Down Expand Up @@ -159,7 +160,7 @@ function(apply_patches repo_dir patches_dir base_revision target_branch ret)
)
endif()
if (NOT (ret_check_out OR ret_apply_patch))
set(${ret} True PARENT_SCOPE)
message(STATUS "[OPENCL-CLANG] Applied patch successfully!")
else()
message(FATAL_ERROR "[OPENCL-CLANG] Failed to apply patch!")
endif()
Expand Down
Loading