Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpm: Rework always_download rules to be smarter #348

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/packages/rapids_cpm_versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ as needed.
An optional boolean value that represents if CPM should just download the
package ( `CPM_DOWNLOAD_ALL` ) instead of first searching for it on the machine.

If no such field exists the default is `false` for default packages, and `true` for any package that has an override.
The default value for this field is `false` unless all of the following criteria is met.
- The projects exists in both the default and override files
- The `git_url` or `git_tag` have been overridden

``patches``
An optional list of dictionary sets of git patches to apply to the project
Expand Down
19 changes: 14 additions & 5 deletions rapids-cmake/cpm/detail/package_details.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,17 +59,26 @@ 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)

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)
set(git_details_overridden TRUE)
if(no_url_override AND no_tag_override)
set(git_details_overridden FALSE)
endif()
endif()

# Parse optional fields, set the variable to the 'default' value first
set(git_shallow ON)
rapids_cpm_json_get_value(git_shallow)

set(exclude_from_all OFF)
rapids_cpm_json_get_value(exclude_from_all)

if(override_json_data)
# The default value for always download is defined by having an override for this package. When
# we have an override we presume the user doesn't want to use an existing local installed
# version
set(always_download OFF)
if(override_json_data AND json_data AND git_details_overridden)
# `always_download` default value requires the package to exist in both the default and override
# and that the git url / git tag have been modified.
set(always_download ON)
endif()
rapids_cpm_json_get_value(always_download)
Expand Down
22 changes: 18 additions & 4 deletions testing/cpm/cpm_init-override-multiple.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,9 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json
"git_tag" : "my_tag",
"always_download" : false
},
"rmm" : {
"git_tag" : "my_tag"
},
"GTest" : {
"version" : "2.99"
}
Expand All @@ -50,11 +53,22 @@ if(NOT repository STREQUAL nvbench_repository)
message(FATAL_ERROR "default repository field was removed.")
endif()
if(NOT tag STREQUAL "my_tag")
message(FATAL_ERROR "custom git_tag field was ignored. ${tag} found instead of my_url")
message(FATAL_ERROR "custom git_tag field was ignored. ${tag} found instead of my_tag")
endif()
if(CPM_DOWNLOAD_ALL)
message(FATAL_ERROR "CPM_DOWNLOAD_ALL should be false since the nvbench override explicitly sets it to 'false'")
endif()
unset(CPM_DOWNLOAD_ALL)

# Verify that the override works
rapids_cpm_package_details(rmm version repository tag shallow exclude)
if(NOT tag STREQUAL "my_tag")
message(FATAL_ERROR "custom git_tag field was ignored. ${tag} found instead of my_tag")
endif()
if(NOT CPM_DOWNLOAD_ALL)
message(FATAL_ERROR "CPM_DOWNLOAD_ALL should be true since a custom git tag was used for rmm")
endif()
unset(CPM_DOWNLOAD_ALL)

rapids_cpm_package_details(GTest version repository tag shallow exclude)
if(NOT version STREQUAL "2.99")
Expand All @@ -63,6 +77,6 @@ endif()
if(NOT tag MATCHES "2.99")
message(FATAL_ERROR "custom version field not used when computing git_tag value. ${tag} was found instead")
endif()
if(NOT CPM_DOWNLOAD_ALL)
message(FATAL_ERROR "CPM_DOWNLOAD_ALL should be enabled by default when an override exists")
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()
14 changes: 7 additions & 7 deletions testing/cpm/cpm_package_override-simple.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -24,7 +24,7 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json
{
"packages" : {
"rmm" : {
"git_tag" : "new_rmm_tag",
"git_url" : "new_rmm_url",
"git_shallow" : "OFF",
"exclude_from_all" : "ON"
},
Expand All @@ -50,13 +50,13 @@ endif()
if(NOT exclude MATCHES "OFF")
message(FATAL_ERROR "default value of exclude not found. ${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")
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 tag MATCHES "new_rmm_tag")
message(FATAL_ERROR "custom version field not used when computing git_tag value. ${tag} was found instead")
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")
Expand All @@ -65,5 +65,5 @@ 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")
message(FATAL_ERROR "CPM_DOWNLOAD_ALL should be set to true when an override exists with a custom repository")
endif()