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

[BUG] Patch commands fail trying to re-apply the same patch twice #618

Open
Jazzinghen opened this issue Nov 18, 2024 · 5 comments
Open

Comments

@Jazzinghen
Copy link

Due to a dependency with improper CMakeLists.txt I tried to use the PATCHES field, however the second time I run the configuration CMake fails during FetchContent_MakeAvailable for that package with this output:

[cmake] -- CPM: Adding package sqlite_protobuf@0 (082596c282cab90f50b6d6dee5f9be22fd503dbe)
[cmake] [ 11%] Performing update step for 'sqlite_protobuf-populate'
[cmake] -- Already at requested ref: 082596c282cab90f50b6d6dee5f9be22fd503dbe
[cmake] [ 22%] Performing patch step for 'sqlite_protobuf-populate'
[cmake] patching file CMakeLists.txt
[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 CMakeLists.txt.rej
[cmake] patching file src/CMakeLists.txt
[cmake] Reversed (or previously applied) patch detected!  Assume -R? [n] 
[cmake] Apply anyway? [n] 
[cmake] Skipping patch.
[cmake] 2 out of 2 hunks ignored -- saving rejects to file src/CMakeLists.txt.rej
[cmake] make[2]: *** [CMakeFiles/sqlite_protobuf-populate.dir/build.make:118: sqlite_protobuf-populate-prefix/src/sqlite_protobuf-populate-stamp/sqlite_protobuf-populate-patch] Error 1
[cmake] make[1]: *** [CMakeFiles/Makefile2:87: CMakeFiles/sqlite_protobuf-populate.dir/all] Error 2
[cmake] make: *** [Makefile:91: all] Error 2
[cmake] 
[cmake] CMake Error at /usr/share/cmake/Modules/FetchContent.cmake:1918 (message):
[cmake]   Build step for sqlite_protobuf failed: 2
[cmake] Call Stack (most recent call first):
[cmake]   /usr/share/cmake/Modules/FetchContent.cmake:1609 (__FetchContent_populateSubbuild)
[cmake]   /usr/share/cmake/Modules/FetchContent.cmake:2145:EVAL:2 (__FetchContent_doPopulation)
[cmake]   /usr/share/cmake/Modules/FetchContent.cmake:2145 (cmake_language)
[cmake]   /usr/share/cmake/Modules/FetchContent.cmake:2384 (__FetchContent_Populate)
[cmake]   build/cmake/CPM_0.40.2.cmake:1114 (FetchContent_MakeAvailable)
[cmake]   build/cmake/CPM_0.40.2.cmake:895 (cpm_fetch_package)
[cmake]   src/wrapper/CMakeLists.txt:3 (cpmaddpackage)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!

This is the relevant piece of my CMakeLists.txt:

cpmaddpackage(
  NAME
  sqlite_protobuf
  GITHUB_REPOSITORY
  rgov/sqlite_protobuf
  GIT_TAG
  082596c282cab90f50b6d6dee5f9be22fd503dbe
  PATCHES
  "${PROJECT_SOURCE_DIR}/cmake/sqlite_protobuf_fix.patch")
@soulfresh
Copy link

I'm seeing the same issue. If I choose "no" at the patch reverse step, the build fails because the patch fails to apply. If I choose "yes", then the patch is reversed and the library is no longer patched the way I need. It might be good to set a cache variable tracking each patch that has been applied and then skipping that patch on subsequent passes.

@soulfresh
Copy link

For anyone else who finds this, here's my workaround:

if (NOT TRACKTION_ENGINE_PATCHED) 
  set(TRACKTION_ENGINE_PATCHED TRUE CACHE INTERNAL "Whether to apply patches to Tracktion Engine")
  CPMAddPackage(
    NAME TracktionEngine
    GITHUB_REPOSITORY Tracktion/tracktion_engine
    VERSION 3.0
    SOURCE_DIR ${DEPS_DIR}/tracktion_engine
    # Prevent Tracktion Engine from compiling its examples.
    PATCHES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/tracktion_engine.patch"
  )
else()
  CPMAddPackage(
    NAME TracktionEngine
    GITHUB_REPOSITORY Tracktion/tracktion_engine
    VERSION 3.0
    SOURCE_DIR ${DEPS_DIR}/tracktion_engine
  )
endif()

@apirogov
Copy link

Have the same issue. Hope this gets fixed soon!

@apirogov
Copy link

The workaround works only when no CPM caching is used. Otherwise probably it needs to do something more reliable, like checking whether it was just freshly downloaded or not.

@soulfresh
Copy link

Hmmm...it seems to work for me with CPM caching on (unless I'm misunderstanding what CPM caching does). In my project, I've set set(CPM_SOURCE_CACHE "${CMAKE_CURRENT_SOURCE_DIR}/deps"). On the first run, it downloads the package, applies my patch and sets my custom CMake cache variable. On subsequent runs, CPM doesn't re-download the package or apply the patch and my app builds as expected. Its possible for my custom CMake cache variable to get out of sync with the file system if the dependency cache is deleted but that CMake variable is not removed. I use a clean script to ensure both get removed.

My work around is definitely less than ideal but should work; though I may be misunderstanding something.

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