From 74a9498a6a892521b2c83c68b3aa506bea8c6f10 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 25 Oct 2024 10:44:31 -0400 Subject: [PATCH] Add tests to verify case insenstive overrides work --- testing/cpm/CMakeLists.txt | 6 +- ...faults-with-different-casing-warning.cmake | 68 +++++++++++++++++++ ...rride-defaults-with-different-casing.cmake | 67 ++++++++++++++++++ 3 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 testing/cpm/cpm_package_override-defaults-with-different-casing-warning.cmake create mode 100644 testing/cpm/cpm_package_override-defaults-with-different-casing.cmake diff --git a/testing/cpm/CMakeLists.txt b/testing/cpm/CMakeLists.txt index 00bd252e..bc1a4d36 100644 --- a/testing/cpm/CMakeLists.txt +++ b/testing/cpm/CMakeLists.txt @@ -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") diff --git a/testing/cpm/cpm_package_override-defaults-with-different-casing-warning.cmake b/testing/cpm/cpm_package_override-defaults-with-different-casing-warning.cmake new file mode 100644 index 00000000..52c8c1a5 --- /dev/null +++ b/testing/cpm/cpm_package_override-defaults-with-different-casing-warning.cmake @@ -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() diff --git a/testing/cpm/cpm_package_override-defaults-with-different-casing.cmake b/testing/cpm/cpm_package_override-defaults-with-different-casing.cmake new file mode 100644 index 00000000..ee7a453f --- /dev/null +++ b/testing/cpm/cpm_package_override-defaults-with-different-casing.cmake @@ -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()