]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/tools/vcpkg/scripts/cmake/z_vcpkg_apply_patches.cmake
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / tools / vcpkg / scripts / cmake / z_vcpkg_apply_patches.cmake
1 #[===[.md:
2 # z_vcpkg_apply_patches
3
4 **Only for internal use in vcpkg helpers. Behavior and arguments will change without notice.**
5
6 Apply a set of patches to a source tree.
7
8 ```cmake
9 z_vcpkg_apply_patches(
10 SOURCE_PATH <path-to-source>
11 [QUIET]
12 PATCHES <patch>...
13 )
14 ```
15
16 The `<path-to-source>` should be set to `${SOURCE_PATH}` by convention,
17 and is the path to apply the patches in.
18
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`.
25
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.
29 #]===]
30
31 function(z_vcpkg_apply_patches)
32 cmake_parse_arguments(PARSE_ARGV 0 "arg" "QUIET" "SOURCE_PATH" "PATCHES")
33
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}")
37 else()
38 unset(git_config_nosystem_backup)
39 endif()
40
41 set(ENV{GIT_CONFIG_NOSYSTEM} 1)
42 set(patchnum 0)
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"
50 ERROR_VARIABLE error
51 WORKING_DIRECTORY "${arg_SOURCE_PATH}"
52 RESULT_VARIABLE error_code
53 )
54 file(WRITE "${CURRENT_BUILDTREES_DIR}/${logname}-err.log" "${error}")
55
56 if(error_code AND NOT arg_QUIET)
57 message(FATAL_ERROR "Applying patch failed: ${error}")
58 endif()
59
60 math(EXPR patchnum "${patchnum} + 1")
61 endforeach()
62 if(DEFINED git_config_nosystem_backup)
63 set(ENV{GIT_CONFIG_NOSYSTEM} "${git_config_nosystem_backup}")
64 else()
65 unset(ENV{GIT_CONFIG_NOSYSTEM})
66 endif()
67 endfunction()