Skip to content

Commit

Permalink
Always download repos when they are being patched (rapidsai#525)
Browse files Browse the repository at this point in the history
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: rapidsai#525
  • Loading branch information
vyasr authored and PointKernel committed Jan 23, 2024
1 parent 5b8fa5f commit bfe5368
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 38 deletions.
5 changes: 2 additions & 3 deletions rapids-cmake/cpm/cccl.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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}")

Expand Down
5 changes: 2 additions & 3 deletions rapids-cmake/cpm/cuco.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion rapids-cmake/cpm/detail/generate_patch_command.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions rapids-cmake/cpm/find.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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:`<PackageName>_SOURCE_DIR` is set to the path to the source directory of <PackageName>.
Expand Down Expand Up @@ -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)
Expand All @@ -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})
Expand Down
5 changes: 2 additions & 3 deletions rapids-cmake/cpm/fmt.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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")

Expand Down
5 changes: 2 additions & 3 deletions rapids-cmake/cpm/gbench.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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}"
Expand Down
5 changes: 2 additions & 3 deletions rapids-cmake/cpm/gtest.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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")

Expand Down
5 changes: 2 additions & 3 deletions rapids-cmake/cpm/libcudacxx.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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}")

Expand Down
5 changes: 2 additions & 3 deletions rapids-cmake/cpm/nvbench.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions rapids-cmake/cpm/nvcomp.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions rapids-cmake/cpm/package_override.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions rapids-cmake/cpm/rmm.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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")

Expand Down
5 changes: 2 additions & 3 deletions rapids-cmake/cpm/spdlog.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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}")

Expand Down
5 changes: 2 additions & 3 deletions rapids-cmake/cpm/thrust.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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}")

Expand Down
1 change: 1 addition & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down
52 changes: 52 additions & 0 deletions testing/cpm/cpm_find-patch-command/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit bfe5368

Please sign in to comment.