-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow projects to override version.json information
Fixes #73 Introduces `OVERRIDE` argument to rapids_cpm_init() and the rapids_cpm_package_override command. Both of these allow consuming projects to inject new urls/repository/tag/etc for rapids-cmake cpm pre-configured packages
- Loading branch information
1 parent
7efb04f
commit cd7cee9
Showing
16 changed files
with
459 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.. cmake-module:: ../../rapids-cmake/cpm/package_override.cmake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
:orphan: | ||
|
||
.. _cpm_version_format: | ||
|
||
rapids-cmake package version format | ||
################################### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#============================================================================= | ||
# Copyright (c) 2021, 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_guard(GLOBAL) | ||
|
||
#[=======================================================================[.rst: | ||
rapids_cpm_package_override | ||
--------------------------- | ||
.. versionadded:: v21.10.00 | ||
Override `CPM` preset package information for the project. | ||
.. code-block:: cmake | ||
rapids_cpm_package_override(<json_file_path>) | ||
Allows projects to override the default values for any rapids-cmake | ||
pre-configured cpm package. | ||
The user provided json file must follow the `versions.json` format, | ||
which is :ref:`documented here<cpm_version_format>` and shown in the below | ||
example: | ||
.. literalinclude:: /packages/example.json | ||
:language: json | ||
If the override doesn't specify a value or package entry the default | ||
version will be used. | ||
#]=======================================================================] | ||
function(rapids_cpm_package_override filepath) | ||
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.rapids_cpm_package_override") | ||
|
||
file(READ "${filepath}" json_data) | ||
|
||
# Determine all the projects that exist in the json file | ||
string(JSON package_count LENGTH "${json_data}" packages) | ||
math(EXPR package_count "${package_count} - 1") | ||
|
||
# For each project cache the subset of the json for that project in a global property | ||
|
||
# cmake-lint: disable=E1120 | ||
foreach(index RANGE ${package_count}) | ||
string(JSON package_name MEMBER "${json_data}" packages ${index}) | ||
string(JSON data GET "${json_data}" packages "${package_name}") | ||
set_property(GLOBAL PROPERTY rapids_cpm_${package_name}_override_json "${data}") | ||
endforeach() | ||
|
||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#============================================================================= | ||
# Copyright (c) 2021, 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-testing-dir}/cpm/setup_cpm_cache.cmake") | ||
rapids_cpm_init(OVERRIDE ${CMAKE_CURRENT_LIST_DIR}/bad_path.cmake) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#============================================================================= | ||
# Copyright (c) 2021, 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-testing-dir}/cpm/setup_cpm_cache.cmake") | ||
|
||
|
||
rapids_cpm_init() | ||
|
||
# Load the default values for nvbench and GTest projects | ||
include("${rapids-cmake-dir}/cpm/detail/package_details.cmake") | ||
rapids_cpm_package_details(nvbench nvbench_version nvbench_repository nvbench_tag nvbench_shallow) | ||
rapids_cpm_package_details(GTest GTest_version GTest_repository GTest_tag GTest_shallow) | ||
|
||
|
||
# Need to write out an override file | ||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json | ||
[=[ | ||
{ | ||
"packages" : { | ||
"nvbench" : { | ||
"git_tag" : "my_tag" | ||
}, | ||
"GTest" : { | ||
"version" : "2.99" | ||
} | ||
} | ||
} | ||
]=]) | ||
|
||
rapids_cpm_init(OVERRIDE "${CMAKE_CURRENT_BINARY_DIR}/override.json") | ||
|
||
# Verify that the override works | ||
rapids_cpm_package_details(nvbench version repository tag shallow) | ||
if(NOT version STREQUAL nvbench_version) | ||
message(FATAL_ERROR "default version field was removed.") | ||
endif() | ||
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") | ||
endif() | ||
|
||
rapids_cpm_package_details(GTest version repository tag shallow) | ||
if(NOT version STREQUAL "2.99") | ||
message(FATAL_ERROR "custom version field was removed. ${version} was found instead") | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#============================================================================= | ||
# Copyright (c) 2021, 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-testing-dir}/cpm/setup_cpm_cache.cmake") | ||
|
||
# Need to write out an override file | ||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json | ||
[=[ | ||
{ | ||
"packages" : { | ||
"nvbench" : { | ||
"version" : "custom_version", | ||
"git_url" : "my_url", | ||
"git_tag" : "my_tag" | ||
} | ||
} | ||
} | ||
]=]) | ||
|
||
rapids_cpm_init(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(nvbench version repository tag shallow) | ||
|
||
if(NOT version STREQUAL "custom_version") | ||
message(FATAL_ERROR "custom version field was ignored. ${version} found instead of custom_version") | ||
endif() | ||
if(NOT repository STREQUAL "my_url") | ||
message(FATAL_ERROR "custom git_url field was ignored. ${repository} found instead of my_url") | ||
endif() | ||
if(NOT tag STREQUAL "my_tag") | ||
message(FATAL_ERROR "custom git_tag field was ignored. ${tag} found instead of my_tag") | ||
endif() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#============================================================================= | ||
# Copyright (c) 2021, 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() | ||
rapids_cpm_package_override(${CMAKE_CURRENT_LIST_DIR}/bad_path.cmake) |
Oops, something went wrong.