forked from rapidsai/rapids-cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate template copyright year at build time. (rapidsai#325)
Rather than hard-coding the copyright year in each template file, get the current year at build time and write it in the template.
- Loading branch information
1 parent
66816a1
commit 98b4c20
Showing
18 changed files
with
216 additions
and
13 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
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
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
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
52 changes: 52 additions & 0 deletions
52
testing/cpm/cpm_generate_patch_command-verify-copyright-header.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,52 @@ | ||
#============================================================================= | ||
# 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) | ||
include(${rapids-cmake-dir}/cpm/detail/generate_patch_command.cmake) | ||
|
||
rapids_cpm_init() | ||
|
||
# Need to write out an override file | ||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json | ||
[=[ | ||
{ | ||
"packages" : { | ||
"pkg_with_patch" : { | ||
"version" : "10.2", | ||
"git_tag" : "a_tag", | ||
"git_shallow" : "OFF", | ||
"exclude_from_all" : "ON", | ||
"patches" : [ | ||
{ | ||
"file" : "e/example.diff", | ||
"issue" : "explain", | ||
"fixed_in" : "" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
]=]) | ||
rapids_cpm_package_override(${CMAKE_CURRENT_BINARY_DIR}/override.json) | ||
|
||
rapids_cpm_generate_patch_command(pkg_with_patch 10.2 patch_command) | ||
if(NOT patch_command) | ||
message(FATAL_ERROR "rapids_cpm_package_override specified a patch step for `pkg_with_patch`") | ||
endif() | ||
|
||
add_custom_target(verify_copyright_headers ALL | ||
COMMAND ${CMAKE_COMMAND} "-Dfile=${CMAKE_BINARY_DIR}/rapids-cmake/patches/pkg_with_patch/patch.cmake" -P "${rapids-cmake-testing-dir}/utils/check_copyright_header_script.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
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-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}/export/cpm.cmake) | ||
include(${rapids-cmake-dir}/export/export.cmake) | ||
include(${rapids-cmake-dir}/export/write_dependencies.cmake) | ||
|
||
cmake_minimum_required(VERSION 3.23.1) | ||
project(FakEProJecT LANGUAGES CXX VERSION 3.1.4) | ||
|
||
add_library(fakeLib INTERFACE) | ||
install(TARGETS fakeLib EXPORT fake_set) | ||
|
||
rapids_export_cpm(BUILD RaFT FakEProJecT | ||
CPM_ARGS | ||
FAKE_PACKAGE_ARGS TRUE | ||
) | ||
|
||
rapids_export_write_dependencies(BUILD FakEProJecT dependencies.cmake) | ||
|
||
rapids_export(BUILD FakEProJecT | ||
EXPORT_SET fake_set | ||
NAMESPACE test:: | ||
) | ||
rapids_export(INSTALL FakEProJecT | ||
EXPORT_SET fake_set | ||
NAMESPACE test:: | ||
) | ||
|
||
add_custom_target(verify_copyright_headers ALL | ||
COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_BINARY_DIR}/install" | ||
COMMAND ${CMAKE_COMMAND} --install "${CMAKE_BINARY_DIR}" --prefix "${CMAKE_BINARY_DIR}/install" | ||
COMMAND ${CMAKE_COMMAND} "-Dfile=${CMAKE_BINARY_DIR}/fakeproject-config.cmake" -P "${rapids-cmake-testing-dir}/utils/check_copyright_header_script.cmake" | ||
COMMAND ${CMAKE_COMMAND} "-Dfile=${CMAKE_BINARY_DIR}/install/lib/cmake/fakeproject/fakeproject-config.cmake" -P "${rapids-cmake-testing-dir}/utils/check_copyright_header_script.cmake" | ||
COMMAND ${CMAKE_COMMAND} "-Dfile=${CMAKE_BINARY_DIR}/rapids-cmake/FakEProJecT/build/cpm_RaFT.cmake" -P "${rapids-cmake-testing-dir}/utils/check_copyright_header_script.cmake" | ||
COMMAND ${CMAKE_COMMAND} "-Dfile=${CMAKE_BINARY_DIR}/dependencies.cmake" -P "${rapids-cmake-testing-dir}/utils/check_copyright_header_script.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
25 changes: 25 additions & 0 deletions
25
testing/find/find_generate_module-verify-copyright-header.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,25 @@ | ||
#============================================================================= | ||
# 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}/find/generate_module.cmake) | ||
|
||
rapids_find_generate_module( RapidsTest | ||
HEADER_NAMES rapids-cmake-test-header_only.hpp | ||
INSTALL_EXPORT_SET test_set | ||
) | ||
|
||
add_custom_target(verify_copyright_headers ALL | ||
COMMAND ${CMAKE_COMMAND} "-Dfile=${CMAKE_BINARY_DIR}/cmake/find_modules/FindRapidsTest.cmake" -P "${rapids-cmake-testing-dir}/utils/check_copyright_header_script.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,42 @@ | ||
#============================================================================= | ||
# 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_guard(GLOBAL) | ||
|
||
function(check_copyright_header file) | ||
string(TIMESTAMP current_year "%Y" UTC) | ||
string(CONFIGURE [=[#============================================================================= | ||
# Copyright (c) @current_year@, 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. | ||
#============================================================================= | ||
]=] expected_header @ONLY) | ||
string(LENGTH "${expected_header}" expected_header_length) | ||
|
||
file(READ "${file}" actual_header LIMIT "${expected_header_length}") | ||
if(NOT actual_header STREQUAL expected_header) | ||
message(FATAL_ERROR "File ${file} did not have expected copyright header") | ||
endif() | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#============================================================================= | ||
# 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. | ||
#============================================================================= | ||
|
||
#============================================================================= | ||
# This file is intended to be run as a standalone script, like so: | ||
# | ||
# $ cmake -Dfile=<file-to-check> \ | ||
# -P ${rapids-cmake-testing-dir}/utils/check_copyright_header_script.cmake | ||
#============================================================================= | ||
include("${CMAKE_CURRENT_LIST_DIR}/check_copyright_header.cmake") | ||
|
||
check_copyright_header("${file}") |