Skip to content

Commit

Permalink
Add tests to verify case insenstive overrides work
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard committed Oct 25, 2024
1 parent 4bb794f commit 74a9498
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 2 deletions.
6 changes: 4 additions & 2 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ add_cmake_config_test( cpm_init-bad-override-cmake-var.cmake SHOULD_FAIL "rapids
add_cmake_config_test( cpm_init-custom-default-simple.cmake)
add_cmake_config_test( cpm_init-custom-default-multiple.cmake)
add_cmake_config_test( cpm_init-custom-default-via-cmake-var.cmake)
add_cmake_config_test( cpm_init-override-simple.cmake)
add_cmake_config_test( cpm_init-override-multiple.cmake)
add_cmake_config_test( cpm_init-override-simple.cmake)
add_cmake_config_test( cpm_init-override-via-cmake-var.cmake)


add_cmake_config_test( cpm_package_override-add-new-project.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-defaults-with-different-casing.cmake )
add_cmake_config_test( cpm_package_override-defaults-with-different-casing-warning.cmake)
add_cmake_config_test( cpm_package_override-empty-patches.cmake )
add_cmake_config_test( cpm_package_override-empty.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-no-version-value.cmake SHOULD_FAIL "rapids_cmake can't parse")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#=============================================================================
# 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.
#=============================================================================
# rapids-cmake will output as `AUTHOR_WARNING` so we need to hijack
# message to verify we see output we expect
set(rmm_string "RAPIDS-CMake is assuming the override rMm is meant for the rmm package")
set(gtest_string "RAPIDS-CMake is assuming the override gtest is meant for the GTest package")

function(message mode content )
if(mode STREQUAL "AUTHOR_WARNING")
if(content MATCHES "${rmm_string}")
message(STATUS "==rmm warned==")
set_property(GLOBAL PROPERTY rapids_cmake_rmm_warned TRUE)
elseif(content MATCHES "${gtest_string}")
message(STATUS "==gtest warned==")
set_property(GLOBAL PROPERTY rapids_cmake_gtest_warned TRUE)
endif()
else()
_message(${ARGV})
endif()
endfunction()

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": {
"git_url": "new_rmm_url",
"git_shallow": "OFF",
"exclude_from_all": "ON"
},
"gtest": {
"version": "3.00.A1"
}
}
}
]=])

rapids_cpm_package_override(${CMAKE_CURRENT_BINARY_DIR}/override.json)
include("${rapids-cmake-dir}/cpm/detail/package_details.cmake")

# Verify that we got our warnings
get_property(rmm_warned GLOBAL PROPERTY rapids_cmake_rmm_warned)
get_property(gtest_warned GLOBAL PROPERTY rapids_cmake_gtest_warned)
if(NOT rmm_warned)
message(FATAL_ERROR "Failed to warn about improper rmm casing")
endif()
if(NOT gtest_warned)
message(FATAL_ERROR "Failed to warn about improper gtest casing")
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#=============================================================================
# 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": {
"git_url": "new_rmm_url",
"git_shallow": "OFF",
"exclude_from_all": "ON"
},
"gtest": {
"version": "3.00.A1"
}
}
}
]=])

rapids_cpm_package_override(${CMAKE_CURRENT_BINARY_DIR}/override.json)

rapids_cpm_package_details(GTest version repository tag shallow exclude)
if(NOT version STREQUAL "3.00.A1")
message(FATAL_ERROR "custom version field was removed. ${version} was found instead")
endif()
if(NOT tag MATCHES "3.00.A1")
message(FATAL_ERROR "custom version field not used when computing git_tag value. ${tag} was found instead")
endif()
if(NOT exclude MATCHES "OFF")
message(FATAL_ERROR "default value of exclude not found. ${exclude} was found instead")
endif()
if(CPM_DOWNLOAD_ALL)
message(FATAL_ERROR "CPM_DOWNLOAD_ALL should be false by default when an override exists that doesn't modify url or tag")
endif()

rapids_cpm_package_details(rmm version repository tag shallow exclude)
if(NOT repository MATCHES "new_rmm_url")
message(FATAL_ERROR "custom url field was not used. ${repository} was found instead")
endif()
if(NOT shallow MATCHES "OFF")
message(FATAL_ERROR "override should not change git_shallow value. ${shallow} was found instead")
endif()
if(NOT exclude MATCHES "ON")
message(FATAL_ERROR "override should have changed exclude value. ${exclude} was found instead")
endif()
if(NOT CPM_DOWNLOAD_ALL)
message(FATAL_ERROR "CPM_DOWNLOAD_ALL should be set to true when an override exists with a custom repository")
endif()

0 comments on commit 74a9498

Please sign in to comment.