Skip to content

Commit

Permalink
rapids-cmake support empty patches array in json
Browse files Browse the repository at this point in the history
This allows overrides to explicitly opt-out of the patches
that rapids-cmake lists in the built-in versions.json
  • Loading branch information
robertmaynard committed Mar 12, 2024
1 parent 0bb862c commit bbbe45c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 19 deletions.
40 changes: 21 additions & 19 deletions rapids-cmake/cpm/detail/generate_patch_command.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
55 changes: 55 additions & 0 deletions testing/cpm/cpm_package_override-empty-patches.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit bbbe45c

Please sign in to comment.