Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with CPM PATCHES "Reversed (or previously applied) patch detected!" #596

Closed
javari99 opened this issue Sep 4, 2024 · 12 comments
Closed

Comments

@javari99
Copy link

javari99 commented Sep 4, 2024

Hello,

I am encountering a problem while trying to add cmocka to my cmake project using CPM. Due to internal conflicts between my toolchain file and the cmocka generation process, I have to patch some of their cmake files. To do so, I am using the PATCHES keyword and passing a list of patch files. The first configure runs perfect but subsequent reconfigurations fail with the following error:

[cmake] [ 11%] Performing update step for 'cmocka-populate'
[cmake] -- Already at requested tag: cmocka-1.1.5
[cmake] [ 22%] Performing patch step for 'cmocka-populate'
[cmake] patching file ConfigureChecks.cmake
[cmake] Reversed (or previously applied) patch detected!  Assume -R? [n] 
[cmake] Apply anyway? [n] 
[cmake] Skipping patch.
[cmake] 1 out of 1 hunk ignored -- saving rejects to file ConfigureChecks.cmake.rej
[cmake] gmake[2]: *** [CMakeFiles/cmocka-populate.dir/build.make:118: cmocka-populate-prefix/src/cmocka-populate-stamp/cmocka-populate-patch] Error 1
[cmake] gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/cmocka-populate.dir/all] Error 2
[cmake] gmake: *** [Makefile:91: all] Error 2
[cmake] 
[cmake] CMake Error at /usr/share/cmake-3.30/Modules/FetchContent.cmake:1918 (message):
[cmake]   Build step for cmocka failed: 2
[cmake] Call Stack (most recent call first):
[cmake]   /usr/share/cmake-3.30/Modules/FetchContent.cmake:1609 (__FetchContent_populateSubbuild)
[cmake]   /usr/share/cmake-3.30/Modules/FetchContent.cmake:2145:EVAL:2 (__FetchContent_doPopulation)
[cmake]   /usr/share/cmake-3.30/Modules/FetchContent.cmake:2145 (cmake_language)
[cmake]   /usr/share/cmake-3.30/Modules/FetchContent.cmake:1978:EVAL:1 (__FetchContent_Populate)
[cmake]   /usr/share/cmake-3.30/Modules/FetchContent.cmake:1978 (cmake_language)
[cmake]   cmake/CPM.cmake:1074 (FetchContent_Populate)
[cmake]   cmake/CPM.cmake:868 (cpm_fetch_package)
[cmake]   test/cmake/FetchCMocka.cmake:21 (CPMAddPackage)
[cmake]   test/CMakeLists.txt:4 (include)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!

It seems that the failure is due to an attempt to reapply the patches when reconfiguring. This causes the problem to stop the reconfigure process because the patch command returns an error.

If so, I believe the PATCHES keyword should check whether the patches have already been applied. git apply can check it using

git apply --check

--check
Instead of applying the patch, see if the patch is applicable to the current working tree and/or the index file and detects errors. Turns off "apply". -- git manual

Otherwise is there any workaround to ensure patches are only applied if they have not been applied already?

Thank you for your help!

@ScottBailey
Copy link
Contributor

This is a duplicate of #577. Maybe go up vote it and close this?

The work around for this is to set CPM_SOURCE_CACHE in your environment.

# ~/.bashrc

# This is the cache location for CPM and allows for much faster builds from a clean state. 
export CPM_SOURCE_CACHE=$HOME/.cache/CPM

@javari99
Copy link
Author

javari99 commented Sep 5, 2024

I did not see that issue, thank you!

@javari99 javari99 closed this as completed Sep 5, 2024
@carlocorradini
Copy link
Contributor

Therefore, the only solution is to set CPM_SOURCE_CACHE, otherwise if CMake is configured a second time we get the error above right?

@carlocorradini
Copy link
Contributor

Maybe we can add this to the README? 😅

@ScottBailey
Copy link
Contributor

Maybe, but maybe we should just fix the problem itself?

@carlocorradini
Copy link
Contributor

I agree with you.
CPM should automatically fix the problem (for example, apply the patch only if the files are different); otherwise, there would always be a (hidden) problem.
Specifying CPM_SOURCE_CACHE should, in my opinion, just be a temporary fix.

@ScottBailey
Copy link
Contributor

I think #559 may go along way to getting this to work...

@carlocorradini
Copy link
Contributor

I think this issue should be reopened

@javari99
Copy link
Author

I am doing something similar to #559 on my side as a workaround

set(PATCHES_LIST "")
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/patches_applied") 
      set(PATCHES_LIST "${CMAKE_CURRENT_LIST_DIR}/library_patch.patch")
      file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/patches_applied")
endif()

...

CPMAddPackage(
    GIT_REPOSITORY ""
    PATCHES ${PATCHES_LIST}
 )

I agree with @carlocorradini this should be documented behavior on the Readme or CPM should support it directly

@ScottBailey
Copy link
Contributor

I think this issue should be reopened

This was closed as a duplicate of #577.

@carlocorradini
Copy link
Contributor

Is there a possibility to check if the patch has already been applied?
If it's true, skip, otherwise apply.
Do you know something?

@ScottBailey
Copy link
Contributor

ScottBailey commented Sep 14, 2024

Is there a possibility to check if the patch has already been applied? If it's true, skip, otherwise apply. Do you know something?

See #559 and #577

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants