From 589895aaadcea4af211869606410adbb8beb0be7 Mon Sep 17 00:00:00 2001 From: "Yang, Haonan" Date: Wed, 3 Jul 2024 16:35:03 +0800 Subject: [PATCH] Do not apply patches if repo is a not a git repo. Also backports https://github.com/intel/opencl-clang/commit/fb755984fadb2d2e2787e5ea7916190bde05f5d6 --- cmake/modules/CMakeFunctions.cmake | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/cmake/modules/CMakeFunctions.cmake b/cmake/modules/CMakeFunctions.cmake index 097cba0..a771517 100644 --- a/cmake/modules/CMakeFunctions.cmake +++ b/cmake/modules/CMakeFunctions.cmake @@ -56,7 +56,6 @@ function(is_backport_patch_present patch_path repo_dir patch_in_branch) WORKING_DIRECTORY ${repo_dir} RESULT_VARIABLE patch_not_in_branches OUTPUT_QUIET - ERROR_QUIET ) if(patch_not_in_branches) set(patch_in_branch False PARENT_SCOPE) # The patch is not present in local branch @@ -73,7 +72,6 @@ function(is_valid_revision repo_dir revision return_val) COMMAND ${GIT_EXECUTABLE} log -1 ${revision} WORKING_DIRECTORY ${repo_dir} RESULT_VARIABLE output_var - ERROR_QUIET OUTPUT_QUIET ) if(${output_var} EQUAL 0) @@ -101,14 +99,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 EQUAL "128") + if(patches_needed EQUAL 128) message(STATUS "[OPENCL-CLANG] ${repo_dir} is not a git repository") return() - endif() - if(patches_needed EQUAL "1") # The target branch doesn't exist + elseif(patches_needed EQUAL 1) # The target branch doesn't exist list(SORT patches) is_valid_revision(${repo_dir} ${base_revision} exists_base_rev) @@ -118,7 +114,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}) @@ -141,19 +136,20 @@ function(apply_patches repo_dir patches_dir base_revision target_branch) COMMAND ${GIT_EXECUTABLE} am --3way --ignore-whitespace ${patch} WORKING_DIRECTORY ${repo_dir} OUTPUT_VARIABLE patching_log - ERROR_QUIET ) message(STATUS "[OPENCL-CLANG] Not present - ${patching_log}") endif() endforeach(patch) - elsef(patches_needed EQUAL "0") # The target branch already exists + elsef(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