diff --git a/rapids-cmake/cpm/detail/generate_patch_command.cmake b/rapids-cmake/cpm/detail/generate_patch_command.cmake index 88054184..aab17cac 100644 --- a/rapids-cmake/cpm/detail/generate_patch_command.cmake +++ b/rapids-cmake/cpm/detail/generate_patch_command.cmake @@ -72,30 +72,32 @@ function(rapids_cpm_generate_patch_command package_name version patch_command) message(WARNING "Unable to apply git patches to ${package_name}, git not found") return() endif() - - # Gather number of patches - string(JSON patch_count LENGTH "${json_data}") - math(EXPR patch_count "${patch_count} - 1") - # For each project cache the subset of the json set(patch_files_to_run) set(patch_issues_to_ref) - foreach(index RANGE ${patch_count}) - string(JSON patch_data GET "${json_data}" ${index}) - rapids_cpm_json_get_value(${patch_data} fixed_in) - if(NOT fixed_in OR version VERSION_LESS fixed_in) - rapids_cpm_json_get_value(${patch_data} file) - rapids_cpm_json_get_value(${patch_data} issue) - cmake_language(EVAL CODE "set(file ${file})") - cmake_path(IS_RELATIVE file is_relative) - if(is_relative) - set(file "${rapids-cmake-dir}/cpm/patches/${file}") + # Gather number of patches + string(JSON patch_count LENGTH "${json_data}") + if(patch_count GREATER_EQUAL 1) + math(EXPR patch_count "${patch_count} - 1") + foreach(index RANGE ${patch_count}) + string(JSON patch_data GET "${json_data}" ${index}) + rapids_cpm_json_get_value(${patch_data} fixed_in) + if(NOT fixed_in OR version VERSION_LESS fixed_in) + rapids_cpm_json_get_value(${patch_data} file) + rapids_cpm_json_get_value(${patch_data} issue) + if(file AND issue) + cmake_language(EVAL CODE "set(file ${file})") + cmake_path(IS_RELATIVE file is_relative) + if(is_relative) + set(file "${rapids-cmake-dir}/cpm/patches/${file}") + endif() + list(APPEND patch_files_to_run "${file}") + list(APPEND patch_issues_to_ref "${issue}") + endif() endif() - list(APPEND patch_files_to_run "${file}") - list(APPEND patch_issues_to_ref "${issue}") - endif() - endforeach() + endforeach() + endif() set(patch_script "${CMAKE_BINARY_DIR}/rapids-cmake/patches/${package_name}/patch.cmake") set(log_file "${CMAKE_BINARY_DIR}/rapids-cmake/patches/${package_name}/log") diff --git a/testing/cpm/CMakeLists.txt b/testing/cpm/CMakeLists.txt index 73fb8078..69cdaa44 100644 --- a/testing/cpm/CMakeLists.txt +++ b/testing/cpm/CMakeLists.txt @@ -41,6 +41,7 @@ add_cmake_config_test( cpm_init-override-simple.cmake ) add_cmake_config_test( cpm_package_override-bad-path.cmake SHOULD_FAIL "rapids_cpm_package_override can't load") add_cmake_config_test( cpm_package_override-before-init.cmake ) add_cmake_config_test( cpm_package_override-empty.cmake ) +add_cmake_config_test( cpm_package_override-empty-patches.cmake ) add_cmake_config_test( cpm_package_override-env-var-support.cmake ) add_cmake_config_test( cpm_package_override-multiple.cmake ) add_cmake_config_test( cpm_package_override-obey-cpm-source-var.cmake ) diff --git a/testing/cpm/cpm_package_override-empty-patches.cmake b/testing/cpm/cpm_package_override-empty-patches.cmake new file mode 100644 index 00000000..27d40680 --- /dev/null +++ b/testing/cpm/cpm_package_override-empty-patches.cmake @@ -0,0 +1,55 @@ +#============================================================================= +# 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. +#============================================================================= +include(${rapids-cmake-dir}/cpm/init.cmake) +include(${rapids-cmake-dir}/cpm/package_override.cmake) + +rapids_cpm_init() + +# Need to write out an override file +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json + [=[ +{ + "packages": { + "rmm": { + "patches": [ + { + } + ] + }, + "CCCL": { + "patches": [ ] + } + } +} + ]=]) + +rapids_cpm_package_override(${CMAKE_CURRENT_BINARY_DIR}/override.json) + +# Verify that the override works +include("${rapids-cmake-dir}/cpm/detail/package_details.cmake") +include("${rapids-cmake-dir}/cpm/detail/generate_patch_command.cmake") + +rapids_cpm_package_details(rmm version repository tag shallow exclude) +rapids_cpm_generate_patch_command(rmm ${version} patch_command) +if(patch_command) + message(FATAL_ERROR "no patch command expected for rmm") +endif() + +rapids_cpm_package_details(CCCL version repository tag shallow exclude) +rapids_cpm_generate_patch_command(CCCL ${version} patch_command) +if(patch_command) + message(FATAL_ERROR "no patch command expected for cccl") +endif()