From 2b94de80f7157d14376092b30250b7ee81dca83d Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 17 Jan 2024 17:45:04 -0500 Subject: [PATCH] Always download repos when they are being patched (#525) This PR updates `rapids_cpm_find` to force downloading of a package whenever a nonempty patch command exists. Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Robert Maynard (https://github.com/robertmaynard) - Bradley Dice (https://github.com/bdice) URL: https://github.com/rapidsai/rapids-cmake/pull/525 --- rapids-cmake/cpm/cccl.cmake | 5 +- rapids-cmake/cpm/cuco.cmake | 5 +- .../cpm/detail/generate_patch_command.cmake | 2 +- rapids-cmake/cpm/find.cmake | 17 +++++- rapids-cmake/cpm/fmt.cmake | 5 +- rapids-cmake/cpm/gbench.cmake | 5 +- rapids-cmake/cpm/gtest.cmake | 5 +- rapids-cmake/cpm/libcudacxx.cmake | 5 +- rapids-cmake/cpm/nvbench.cmake | 5 +- rapids-cmake/cpm/nvcomp.cmake | 5 +- rapids-cmake/cpm/package_override.cmake | 4 +- rapids-cmake/cpm/rmm.cmake | 5 +- rapids-cmake/cpm/spdlog.cmake | 5 +- rapids-cmake/cpm/thrust.cmake | 5 +- testing/cpm/CMakeLists.txt | 1 + .../cpm/cpm_find-patch-command/CMakeLists.txt | 52 +++++++++++++++++++ 16 files changed, 93 insertions(+), 38 deletions(-) create mode 100644 testing/cpm/cpm_find-patch-command/CMakeLists.txt diff --git a/rapids-cmake/cpm/cccl.cmake b/rapids-cmake/cpm/cccl.cmake index a76e035b..401ad542 100644 --- a/rapids-cmake/cpm/cccl.cmake +++ b/rapids-cmake/cpm/cccl.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2023, NVIDIA CORPORATION. +# Copyright (c) 2023-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -87,8 +87,7 @@ function(rapids_cpm_cccl) CPM_ARGS FIND_PACKAGE_ARGUMENTS EXACT GIT_REPOSITORY ${repository} GIT_TAG ${tag} - GIT_SHALLOW ${shallow} - PATCH_COMMAND ${patch_command} + GIT_SHALLOW ${shallow} ${patch_command} EXCLUDE_FROM_ALL ${exclude} OPTIONS "CCCL_ENABLE_INSTALL_RULES ${to_install}") diff --git a/rapids-cmake/cpm/cuco.cmake b/rapids-cmake/cpm/cuco.cmake index da81bbb6..122c4cae 100644 --- a/rapids-cmake/cpm/cuco.cmake +++ b/rapids-cmake/cpm/cuco.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -80,8 +80,7 @@ function(rapids_cpm_cuco) CPM_ARGS GIT_REPOSITORY ${repository} GIT_TAG ${tag} - GIT_SHALLOW ${shallow} - PATCH_COMMAND ${patch_command} + GIT_SHALLOW ${shallow} ${patch_command} EXCLUDE_FROM_ALL ${to_exclude} OPTIONS "BUILD_TESTS OFF" "BUILD_BENCHMARKS OFF" "BUILD_EXAMPLES OFF" "INSTALL_CUCO ${to_install}") diff --git a/rapids-cmake/cpm/detail/generate_patch_command.cmake b/rapids-cmake/cpm/detail/generate_patch_command.cmake index 2319d523..88054184 100644 --- a/rapids-cmake/cpm/detail/generate_patch_command.cmake +++ b/rapids-cmake/cpm/detail/generate_patch_command.cmake @@ -103,7 +103,7 @@ function(rapids_cpm_generate_patch_command package_name version patch_command) string(TIMESTAMP current_year "%Y" UTC) configure_file(${rapids-cmake-dir}/cpm/patches/command_template.cmake.in "${patch_script}" @ONLY) - set(${patch_command} ${CMAKE_COMMAND} -P ${patch_script} PARENT_SCOPE) + set(${patch_command} PATCH_COMMAND ${CMAKE_COMMAND} -P ${patch_script} PARENT_SCOPE) else() # remove any old patch / log files that exist and are no longer needed due to a change in the # package version / version.json diff --git a/rapids-cmake/cpm/find.cmake b/rapids-cmake/cpm/find.cmake index 592c03fe..128cf221 100644 --- a/rapids-cmake/cpm/find.cmake +++ b/rapids-cmake/cpm/find.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2020-2023, NVIDIA CORPORATION. +# Copyright (c) 2020-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -80,6 +80,10 @@ consistency. List all targets used by your project in `GLOBAL_TARGET`. Required placeholder to be provided before any extra arguments that need to be passed down to :cmake:command:`CPMFindPackage`. + .. note:: + A ``PATCH_COMMAND`` will always trigger usage of :cmake:command:`CPMAddPackage` instead of :cmake:command:`CPMFindPackage`. *This is true even + if the patch command is empty.* + Result Variables ^^^^^^^^^^^^^^^^ :cmake:variable:`_SOURCE_DIR` is set to the path to the source directory of . @@ -152,6 +156,14 @@ function(rapids_cpm_find name version) message(FATAL_ERROR "rapids_cpm_find requires you to specify CPM_ARGS before any CPM arguments") endif() + set(has_patch FALSE) + foreach(unparsed_arg IN LISTS _RAPIDS_UNPARSED_ARGUMENTS) + if(unparsed_arg MATCHES "PATCH_COMMAND") + set(has_patch TRUE) + break() + endif() + endforeach() + set(package_needs_to_be_added TRUE) if(_RAPIDS_GLOBAL_TARGETS) foreach(target IN LISTS _RAPIDS_GLOBAL_TARGETS) @@ -170,7 +182,8 @@ function(rapids_cpm_find name version) endif() if(package_needs_to_be_added) - if(CPM_${name}_SOURCE) + # Any patch command triggers CPMAddPackage. + if(CPM_${name}_SOURCE OR has_patch) CPMAddPackage(NAME ${name} VERSION ${version} ${_RAPIDS_UNPARSED_ARGUMENTS}) else() CPMFindPackage(NAME ${name} VERSION ${version} ${_RAPIDS_UNPARSED_ARGUMENTS}) diff --git a/rapids-cmake/cpm/fmt.cmake b/rapids-cmake/cpm/fmt.cmake index c8be7ca3..2302d41d 100644 --- a/rapids-cmake/cpm/fmt.cmake +++ b/rapids-cmake/cpm/fmt.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2023, NVIDIA CORPORATION. +# Copyright (c) 2023-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -68,8 +68,7 @@ function(rapids_cpm_fmt) CPM_ARGS GIT_REPOSITORY ${repository} GIT_TAG ${tag} - GIT_SHALLOW ${shallow} - PATCH_COMMAND ${patch_command} + GIT_SHALLOW ${shallow} ${patch_command} EXCLUDE_FROM_ALL ${exclude} OPTIONS "FMT_INSTALL ${to_install}" "CMAKE_POSITION_INDEPENDENT_CODE ON") diff --git a/rapids-cmake/cpm/gbench.cmake b/rapids-cmake/cpm/gbench.cmake index 0ec2fa57..f17c06b6 100644 --- a/rapids-cmake/cpm/gbench.cmake +++ b/rapids-cmake/cpm/gbench.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2022-2023, NVIDIA CORPORATION. +# Copyright (c) 2022-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -77,8 +77,7 @@ function(rapids_cpm_gbench) CPM_ARGS GIT_REPOSITORY ${repository} GIT_TAG ${tag} - GIT_SHALLOW ${shallow} - PATCH_COMMAND ${patch_command} + GIT_SHALLOW ${shallow} ${patch_command} EXCLUDE_FROM_ALL ${exclude} OPTIONS "BENCHMARK_ENABLE_GTEST_TESTS OFF" "BENCHMARK_ENABLE_TESTING OFF" "BENCHMARK_ENABLE_INSTALL ${to_install}" diff --git a/rapids-cmake/cpm/gtest.cmake b/rapids-cmake/cpm/gtest.cmake index 9aef2801..dd07c4b7 100644 --- a/rapids-cmake/cpm/gtest.cmake +++ b/rapids-cmake/cpm/gtest.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# Copyright (c) 2021-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -68,8 +68,7 @@ function(rapids_cpm_gtest) CPM_ARGS FIND_PACKAGE_ARGUMENTS "EXACT" GIT_REPOSITORY ${repository} GIT_TAG ${tag} - GIT_SHALLOW ${shallow} - PATCH_COMMAND ${patch_command} + GIT_SHALLOW ${shallow} ${patch_command} EXCLUDE_FROM_ALL ${exclude} OPTIONS "INSTALL_GTEST ${to_install}" "CMAKE_POSITION_INDEPENDENT_CODE ON") diff --git a/rapids-cmake/cpm/libcudacxx.cmake b/rapids-cmake/cpm/libcudacxx.cmake index fc239872..0ec43bbb 100644 --- a/rapids-cmake/cpm/libcudacxx.cmake +++ b/rapids-cmake/cpm/libcudacxx.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# Copyright (c) 2021-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -88,8 +88,7 @@ function(rapids_cpm_libcudacxx) CPM_ARGS GIT_REPOSITORY ${repository} GIT_TAG ${tag} - GIT_SHALLOW ${shallow} - PATCH_COMMAND ${patch_command} + GIT_SHALLOW ${shallow} ${patch_command} EXCLUDE_FROM_ALL ${exclude} OPTIONS "libcudacxx_ENABLE_INSTALL_RULES ${to_install}") diff --git a/rapids-cmake/cpm/nvbench.cmake b/rapids-cmake/cpm/nvbench.cmake index aa3d7559..cc17ade6 100644 --- a/rapids-cmake/cpm/nvbench.cmake +++ b/rapids-cmake/cpm/nvbench.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# Copyright (c) 2021-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -94,8 +94,7 @@ function(rapids_cpm_nvbench) CPM_ARGS GIT_REPOSITORY ${repository} GIT_TAG ${tag} - GIT_SHALLOW ${shallow} - PATCH_COMMAND ${patch_command} + GIT_SHALLOW ${shallow} ${patch_command} EXCLUDE_FROM_ALL ${exclude} OPTIONS "NVBench_ENABLE_NVML ${nvbench_with_nvml}" "NVBench_ENABLE_CUPTI OFF" diff --git a/rapids-cmake/cpm/nvcomp.cmake b/rapids-cmake/cpm/nvcomp.cmake index e52cb6b2..25039ebd 100644 --- a/rapids-cmake/cpm/nvcomp.cmake +++ b/rapids-cmake/cpm/nvcomp.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# Copyright (c) 2021-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -144,8 +144,7 @@ function(rapids_cpm_nvcomp) GIT_REPOSITORY ${repository} GIT_TAG ${tag} GIT_SHALLOW ${shallow} - EXCLUDE_FROM_ALL ${to_exclude} - PATCH_COMMAND ${patch_command} + EXCLUDE_FROM_ALL ${to_exclude} ${patch_command} OPTIONS "BUILD_STATIC ON" "BUILD_TESTS OFF" "BUILD_BENCHMARKS OFF" "BUILD_EXAMPLES OFF") diff --git a/rapids-cmake/cpm/package_override.cmake b/rapids-cmake/cpm/package_override.cmake index 29732660..e804ffeb 100644 --- a/rapids-cmake/cpm/package_override.cmake +++ b/rapids-cmake/cpm/package_override.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# Copyright (c) 2021-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -99,7 +99,7 @@ function(rapids_cpm_package_override filepath) GIT_REPOSITORY ${repository} GIT_TAG ${tag} GIT_SHALLOW ${shallow} - PATCH_COMMAND ${patch_command} EXCLUDE_FROM_ALL ${exclude}) + ${patch_command} EXCLUDE_FROM_ALL ${exclude}) endif() endforeach() endif() diff --git a/rapids-cmake/cpm/rmm.cmake b/rapids-cmake/cpm/rmm.cmake index 772f3458..bb78d8bb 100644 --- a/rapids-cmake/cpm/rmm.cmake +++ b/rapids-cmake/cpm/rmm.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# Copyright (c) 2021-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -77,8 +77,7 @@ function(rapids_cpm_rmm) CPM_ARGS GIT_REPOSITORY ${repository} GIT_TAG ${tag} - GIT_SHALLOW ${shallow} - PATCH_COMMAND ${patch_command} + GIT_SHALLOW ${shallow} ${patch_command} EXCLUDE_FROM_ALL ${to_exclude} OPTIONS "BUILD_TESTS OFF" "BUILD_BENCHMARKS OFF") diff --git a/rapids-cmake/cpm/spdlog.cmake b/rapids-cmake/cpm/spdlog.cmake index e6662cba..704d870d 100644 --- a/rapids-cmake/cpm/spdlog.cmake +++ b/rapids-cmake/cpm/spdlog.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# Copyright (c) 2021-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -129,8 +129,7 @@ function(rapids_cpm_spdlog) CPM_ARGS GIT_REPOSITORY ${repository} GIT_TAG ${tag} - GIT_SHALLOW ${shallow} - PATCH_COMMAND ${patch_command} + GIT_SHALLOW ${shallow} ${patch_command} EXCLUDE_FROM_ALL ${exclude} OPTIONS "SPDLOG_INSTALL ${to_install}" "${spdlog_fmt_option}") diff --git a/rapids-cmake/cpm/thrust.cmake b/rapids-cmake/cpm/thrust.cmake index 04d453b1..f0d16e4c 100644 --- a/rapids-cmake/cpm/thrust.cmake +++ b/rapids-cmake/cpm/thrust.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# Copyright (c) 2021-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -84,8 +84,7 @@ function(rapids_cpm_thrust NAMESPACE namespaces_name) CPM_ARGS FIND_PACKAGE_ARGUMENTS EXACT GIT_REPOSITORY ${repository} GIT_TAG ${tag} - GIT_SHALLOW ${shallow} - PATCH_COMMAND ${patch_command} + GIT_SHALLOW ${shallow} ${patch_command} EXCLUDE_FROM_ALL ${exclude} OPTIONS "THRUST_ENABLE_INSTALL_RULES ${to_install}") diff --git a/testing/cpm/CMakeLists.txt b/testing/cpm/CMakeLists.txt index d03f144c..ec4c2e82 100644 --- a/testing/cpm/CMakeLists.txt +++ b/testing/cpm/CMakeLists.txt @@ -23,6 +23,7 @@ add_cmake_config_test( cpm_find-existing-target ) add_cmake_config_test( cpm_find-existing-target-to-export-sets ) add_cmake_config_test( cpm_find-gtest-no-gmock ) add_cmake_config_test( cpm_find-options-escaped ) +add_cmake_config_test( cpm_find-patch-command ) add_cmake_config_test( cpm_find-restore-cpm-vars ) add_cmake_config_test( cpm_find-version-explicit-install.cmake ) diff --git a/testing/cpm/cpm_find-patch-command/CMakeLists.txt b/testing/cpm/cpm_find-patch-command/CMakeLists.txt new file mode 100644 index 00000000..e5ff7119 --- /dev/null +++ b/testing/cpm/cpm_find-patch-command/CMakeLists.txt @@ -0,0 +1,52 @@ +#============================================================================= +# Copyright (c) 2024, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +cmake_minimum_required(VERSION 3.23.1) +project(rapids-cpm_find-patch-command-project LANGUAGES CXX) + +include("${rapids-cmake-dir}/cpm/detail/package_details.cmake") +rapids_cpm_package_details(CCCL version repository tag shallow exclude) + +set(deps_dir "${CMAKE_CURRENT_BINARY_DIR}/_cccl_dep") +if(NOT EXISTS "${deps_dir}") + file(MAKE_DIRECTORY "${deps_dir}") + find_package(Git) + execute_process( + COMMAND ${GIT_EXECUTABLE} clone --depth 1 --branch "${tag}" "${repository}" + WORKING_DIRECTORY "${deps_dir}") +endif() + +set(cccl_dir "${deps_dir}/cccl") +list(APPEND CMAKE_PREFIX_PATH "${cccl_dir}") +unset(CPM_SOURCE_CACHE) +unset(CPM_SOURCE_CACHE CACHE) + +include(${rapids-cmake-dir}/cpm/init.cmake) +include(${rapids-cmake-dir}/cpm/cccl.cmake) +rapids_cpm_init() +rapids_cpm_cccl() + +if(NOT "${CCCL_ADDED}") + message(FATAL_ERROR "The found repo was used rather than downloading and patching a new version") +endif() + +execute_process( + COMMAND ${GIT_EXECUTABLE} diff-files --quiet + RESULT_VARIABLE REPO_IS_DIRTY + WORKING_DIRECTORY "${CCCL_SOURCE_DIR}") + +if(NOT ${REPO_IS_DIRTY}) + message(FATAL_ERROR "The repo was downloaded to ${CCCL_SOURCE_DIR} but not patched.") +endif()