-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
800ea16
commit 6fe543f
Showing
2 changed files
with
63 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# In variables: patch_file, with_reset | ||
|
||
function(patch) | ||
execute_process( | ||
COMMAND git apply ${patch_file} | ||
RESULT_VARIABLE ret | ||
ERROR_QUIET | ||
) | ||
set(ret ${ret} PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(check_patch) | ||
execute_process( | ||
COMMAND git apply --reverse --check ${patch_file} | ||
RESULT_VARIABLE ret | ||
ERROR_QUIET | ||
) | ||
set(ret ${ret} PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(patch_if_needed) | ||
patch() | ||
if(NOT ret EQUAL 0) | ||
check_patch() | ||
endif() | ||
set(ret ${ret} PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(patch_if_needed_with_reset) | ||
patch_if_needed() | ||
if(NOT ret EQUAL 0) | ||
message(STATUS "Failed to patch in current state, clearing changes to reapply") | ||
execute_process( | ||
COMMAND git status --porcelain | ||
RESULT_VARIABLE is_changed | ||
) | ||
if(NOT is_changed EQUAL 0) | ||
message(WARNING "Patch inapplyable in clean state") | ||
set(ret 1) | ||
else() | ||
execute_process(COMMAND git reset --hard) | ||
patch_if_needed() | ||
endif() | ||
endif() | ||
set(ret ${ret} PARENT_SCOPE) | ||
endfunction() | ||
|
||
message(STATUS "Trying to apply patch ${patch_file}") | ||
message(STATUS "${CMAKE_CURRENT_LIST_DIR}") | ||
if(with_reset) | ||
patch_if_needed_with_reset() | ||
else() | ||
patch_if_needed() | ||
endif() | ||
if(NOT ret EQUAL 0) | ||
message(FATAL_ERROR "Failed to apply patch ${patch_file}") | ||
else() | ||
message(STATUS "Successfully patched with ${patch_file}") | ||
endif() |