2 # z_vcpkg_apply_patches
4 **Only for internal use in vcpkg helpers. Behavior and arguments will change without notice.**
6 Apply a set of patches to a source tree.
10 SOURCE_PATH <path-to-source>
16 The `<path-to-source>` should be set to `${SOURCE_PATH}` by convention,
17 and is the path to apply the patches in.
19 `z_vcpkg_apply_patches` will take the list of `<patch>`es,
20 which are by default relative to the port directory,
21 and apply them in order using `git apply`.
22 Generally, these `<patch>`es take the form of `some.patch`
23 to select patches in the port directory.
24 One may also download patches and use `${VCPKG_DOWNLOADS}/path/to/some.patch`.
26 If `QUIET` is not passed, it is a fatal error for a patch to fail to apply;
27 otherwise, if `QUIET` is passed, no message is printed.
28 This should only be used for edge cases, such as patches that are known to fail even on a clean source tree.
31 function(z_vcpkg_apply_patches)
32 cmake_parse_arguments(PARSE_ARGV 0 "arg" "QUIET" "SOURCE_PATH" "PATCHES")
34 find_program(GIT NAMES git git.cmd REQUIRED)
35 if(DEFINED ENV{GIT_CONFIG_NOSYSTEM})
36 set(git_config_nosystem_backuP "$ENV{GIT_CONFIG_NOSYSTEM}")
38 unset(git_config_nosystem_backup)
41 set(ENV{GIT_CONFIG_NOSYSTEM} 1)
43 foreach(patch IN LISTS arg_PATCHES)
44 get_filename_component(absolute_patch "${patch}" ABSOLUTE BASE_DIR "${CURRENT_PORT_DIR}")
45 message(STATUS "Applying patch ${patch}")
46 set(logname patch-${TARGET_TRIPLET}-${patchnum})
47 vcpkg_execute_in_download_mode(
48 COMMAND "${GIT}" -c core.longpaths=true -c core.autocrlf=false --work-tree=. --git-dir=.git apply "${absolute_patch}" --ignore-whitespace --whitespace=nowarn --verbose
49 OUTPUT_FILE "${CURRENT_BUILDTREES_DIR}/${logname}-out.log"
51 WORKING_DIRECTORY "${arg_SOURCE_PATH}"
52 RESULT_VARIABLE error_code
54 file(WRITE "${CURRENT_BUILDTREES_DIR}/${logname}-err.log" "${error}")
56 if(error_code AND NOT arg_QUIET)
57 message(FATAL_ERROR "Applying patch failed: ${error}")
60 math(EXPR patchnum "${patchnum} + 1")
62 if(DEFINED git_config_nosystem_backup)
63 set(ENV{GIT_CONFIG_NOSYSTEM} "${git_config_nosystem_backup}")
65 unset(ENV{GIT_CONFIG_NOSYSTEM})