Skip to content

Commit

Permalink
rapids_cpm_package_details now validates required entries exist
Browse files Browse the repository at this point in the history
rapids-cmake now provides proper error message reports when
the required json entry fields don't exist in either the root
`versions.json` or the package override.
  • Loading branch information
robertmaynard committed Mar 12, 2024
1 parent 0bb862c commit e5cb4b2
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rapids-cmake/cpm/detail/package_details.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ function(rapids_cpm_package_details package_name version_var url_var tag_var sha
rapids_cpm_json_get_value(git_url)
rapids_cpm_json_get_value(git_tag)

# Only do validation if we have an entry
if(json_data OR override_json_data)
# Validate that we have the required fields
foreach(var IN ITEMS version git_url git_tag)
if(NOT ${var})
message(FATAL_ERROR "rapids_cmake can't parse '${package_name}' json entry, it is missing a `${var}` entry"
)
endif()
endforeach()
endif()

if(override_json_data)
string(JSON value ERROR_VARIABLE no_url_override GET "${override_json_data}" git_url)
string(JSON value ERROR_VARIABLE no_tag_override GET "${override_json_data}" git_tag)
Expand Down
1 change: 1 addition & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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-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")
add_cmake_config_test( cpm_package_override-obey-cpm-source-var.cmake )
add_cmake_config_test( cpm_package_override-patches.cmake )
add_cmake_config_test( cpm_package_override-simple.cmake )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json
"packages": {
"pkg_with_patch": {
"version": "10.2",
"git_url": "a_url",
"git_tag": "a_tag",
"git_shallow": "OFF",
"exclude_from_all": "ON",
Expand Down
2 changes: 2 additions & 0 deletions testing/cpm/cpm_generate_patch_command-override.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json
"packages": {
"pkg_with_patch": {
"version": "10.2",
"git_url": "a_url",
"git_tag": "a_tag",
"git_shallow": "OFF",
"exclude_from_all": "ON",
Expand All @@ -43,6 +44,7 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json
},
"pkg_patch_not_applied": {
"version": "10.2",
"git_url": "a_url",
"git_tag": "a_tag",
"git_shallow": "OFF",
"exclude_from_all": "ON",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json
"packages": {
"pkg_with_patch": {
"version": "10.2",
"git_url" : "a_url",
"git_tag": "a_tag",
"git_shallow": "OFF",
"exclude_from_all": "ON",
Expand Down
39 changes: 39 additions & 0 deletions testing/cpm/cpm_package_override-no-version-value.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#=============================================================================
# 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.
# 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": {
"fake_package_no_version": {
"git_url": "fake_url",
"git_tag": "a"
}
}
}
]=])

rapids_cpm_package_override(${CMAKE_CURRENT_BINARY_DIR}/override.json)

# Verify that the override works
include("${rapids-cmake-dir}/cpm/detail/package_details.cmake")

rapids_cpm_package_details(fake_package_no_version version repository tag shallow exclude)
2 changes: 2 additions & 0 deletions testing/cpm/cpm_proprietary-url-ctk-version-find-ctk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json
"packages": {
"test_binary": {
"version": "2.6.1",
"git_url": "a_url",
"git_tag": "a_tag",
"proprietary_binary": {
"x86_64-linux": "https://fake.url.com/${version}/${cuda-toolkit-version}/x86_64_${cuda-toolkit-version-major}.tgz",
"aarch64-linux": "https://fake.url.com/${version}/${cuda-toolkit-version}/aarch64_${cuda-toolkit-version-major}.tgz",
Expand Down
2 changes: 2 additions & 0 deletions testing/cpm/cpm_proprietary-url-ctk-version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json
"packages": {
"test_binary": {
"version": "2.6.1",
"git_url": "a_url",
"git_tag": "a_tag",
"proprietary_binary": {
"x86_64-linux": "https://fake.url.com/${version}/${cuda-toolkit-version}/x86_64_${cuda-toolkit-version-major}.tgz",
"aarch64-linux": "https://fake.url.com/${version}/${cuda-toolkit-version}/aarch64_${cuda-toolkit-version-major}.tgz",
Expand Down
2 changes: 2 additions & 0 deletions testing/cpm/cpm_proprietary-url-no-ctk-parsing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json
"packages": {
"test_binary": {
"version": "2.6.1",
"git_url": "empty",
"git_tag": "empty",
"proprietary_binary": {
"x86_64-linux": "https://fake.url.com/x86_${version}.tgz",
"aarch64-linux": "https://fake.url.com/aarch_${version}.tgz",
Expand Down

0 comments on commit e5cb4b2

Please sign in to comment.