From aed9a75b05ee51276d92f23367a5147d9ff607e4 Mon Sep 17 00:00:00 2001 From: HongyuJia Date: Wed, 26 Apr 2023 10:47:36 +0800 Subject: [PATCH] [Fix Patch Error] Fix patch error in cmake (#53321) --- cmake/external/eigen.cmake | 5 +++-- cmake/external/gloo.cmake | 11 +++++++---- cmake/external/gtest.cmake | 6 ++++-- cmake/external/pybind11.cmake | 9 +++++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/cmake/external/eigen.cmake b/cmake/external/eigen.cmake index eda9ae8c4a2..8ae880773a4 100644 --- a/cmake/external/eigen.cmake +++ b/cmake/external/eigen.cmake @@ -51,9 +51,10 @@ if(CMAKE_COMPILER_IS_GNUCC) if(GCC_VERSION GREATER_EQUAL "12.0") file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/eigen/Complex.h.patch complex_header) + # See: [Why calling some `git` commands before `patch`?] set(EIGEN_PATCH_COMMAND - patch -Nd ${EIGEN_SOURCE_DIR}/Eigen/src/Core/arch/SSE/ < - ${complex_header}) + git checkout -- . && git checkout ${EIGEN_TAG} && patch -Nd + ${EIGEN_SOURCE_DIR}/Eigen/src/Core/arch/SSE/ < ${complex_header}) endif() endif() diff --git a/cmake/external/gloo.cmake b/cmake/external/gloo.cmake index 63212c974e2..ebdcabd770c 100755 --- a/cmake/external/gloo.cmake +++ b/cmake/external/gloo.cmake @@ -37,8 +37,9 @@ if(WITH_GPU) VERSION_GREATER 12.0) file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/gloo/device.cc.patch native_dst) - set(GLOO_PATCH_COMMAND patch -d ${GLOO_SOURCE_DIR}/gloo/transport/tcp < - ${native_dst}) + set(GLOO_PATCH_COMMAND + git checkout -- . && git checkout ${GLOO_TAG} &&patch -Nd + ${GLOO_SOURCE_DIR}/gloo/transport/tcp < ${native_dst}) endif() endif() @@ -54,9 +55,11 @@ if(CMAKE_COMPILER_IS_GNUCC) native_dst) file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/gloo/types.h.patch types_header) + # See: [Why calling some `git` commands before `patch`?] set(GLOO_PATCH_COMMAND - patch -Nd ${GLOO_SOURCE_DIR}/gloo/transport/tcp < ${native_dst} && - patch -Nd ${GLOO_SOURCE_DIR}/gloo/ < ${types_header}) + git checkout -- . && git checkout ${GLOO_TAG} && patch -Nd + ${GLOO_SOURCE_DIR}/gloo/transport/tcp < ${native_dst} && patch -Nd + ${GLOO_SOURCE_DIR}/gloo/ < ${types_header}) endif() endif() include_directories(${GLOO_INCLUDE_DIR}) diff --git a/cmake/external/gtest.cmake b/cmake/external/gtest.cmake index 315f6b5b752..777d37a023f 100644 --- a/cmake/external/gtest.cmake +++ b/cmake/external/gtest.cmake @@ -66,8 +66,10 @@ endif() if(NOT WIN32 AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 12.0) file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/gtest/gtest-death-test.cc.patch native_src) - set(GTEST_PATCH_COMMAND patch -Nd ${GTEST_SOURCE_DIR}/googletest/src < - ${native_src}) + # See: [Why calling some `git` commands before `patch`?] + set(GTEST_PATCH_COMMAND + git checkout -- . && git checkout ${GTEST_TAG} && patch -Nd + ${GTEST_SOURCE_DIR}/googletest/src < ${native_src}) endif() if(WIN32) ExternalProject_Add( diff --git a/cmake/external/pybind11.cmake b/cmake/external/pybind11.cmake index db53e3511be..c2782af255c 100644 --- a/cmake/external/pybind11.cmake +++ b/cmake/external/pybind11.cmake @@ -25,8 +25,13 @@ set(PYBIND_PATCH_COMMAND "") if(NOT WIN32) file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/pybind/cast.h.patch native_dst) - set(PYBIND_PATCH_COMMAND patch -d ${PYBIND_INCLUDE_DIR}/pybind11 < - ${native_dst}) + # Note: [Why calling some `git` commands before `patch`?] + # Paddle's CI uses cache to accelarate the make process. However, error might raise when patch codes in two scenarios: + # 1. Patch to the wrong version: the tag version of CI's cache falls behind PYBIND_TAG, use `git checkout ${PYBIND_TAG}` to solve this. + # 2. Patch twice: the tag version of cache == PYBIND_TAG, but patch has already applied to cache. + set(PYBIND_PATCH_COMMAND + git checkout -- . && git checkout ${PYBIND_TAG} && patch -Nd + ${PYBIND_INCLUDE_DIR}/pybind11 < ${native_dst}) endif() ExternalProject_Add( -- GitLab