Skip to content

Commit

Permalink
Generate template copyright year at build time. (#325) (#519)
Browse files Browse the repository at this point in the history
closes #325

Authors:
  - Kyle Edwards (https://github.com/KyleFromNVIDIA)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #519
  • Loading branch information
KyleFromNVIDIA authored Jan 12, 2024
1 parent d18367a commit 9798e7d
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 13 deletions.
3 changes: 2 additions & 1 deletion rapids-cmake/cpm/detail/generate_patch_command.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2022, NVIDIA CORPORATION.
# Copyright (c) 2022-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.
Expand Down Expand Up @@ -100,6 +100,7 @@ function(rapids_cpm_generate_patch_command package_name version patch_command)
set(patch_script "${CMAKE_BINARY_DIR}/rapids-cmake/patches/${package_name}/patch.cmake")
set(log_file "${CMAKE_BINARY_DIR}/rapids-cmake/patches/${package_name}/log")
if(patch_files_to_run)
string(TIMESTAMP current_year "%Y" UTC)
configure_file(${rapids-cmake-dir}/cpm/patches/command_template.cmake.in "${patch_script}"
@ONLY)
set(${patch_command} ${CMAKE_COMMAND} -P ${patch_script} PARENT_SCOPE)
Expand Down
2 changes: 1 addition & 1 deletion rapids-cmake/cpm/patches/command_template.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2022, NVIDIA CORPORATION.
# 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.
Expand Down
3 changes: 2 additions & 1 deletion rapids-cmake/export/cpm.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# 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.
Expand Down Expand Up @@ -74,6 +74,7 @@ function(rapids_export_cpm type name export_set)
endif()
endif()

string(TIMESTAMP current_year "%Y" UTC)
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/cpm.cmake.in"
"${CMAKE_BINARY_DIR}/rapids-cmake/${export_set}/${type}/cpm_${name}.cmake" @ONLY)

Expand Down
4 changes: 3 additions & 1 deletion rapids-cmake/export/export.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# 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.
Expand Down Expand Up @@ -282,6 +282,7 @@ if EXPORT_NAME isn't set for the export targets.")

set(scratch_dir "${PROJECT_BINARY_DIR}/rapids-cmake/${project_name}/export/${project_name}")

string(TIMESTAMP current_year "%Y" UTC)
configure_package_config_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/config.cmake.in"
"${scratch_dir}/${project_name}-config.cmake"
INSTALL_DESTINATION "${install_location}")
Expand Down Expand Up @@ -322,6 +323,7 @@ if EXPORT_NAME isn't set for the export targets.")

else()
set(install_location "${PROJECT_BINARY_DIR}")
string(TIMESTAMP current_year "%Y" UTC)
configure_package_config_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/config.cmake.in"
"${install_location}/${project_name}-config.cmake"
INSTALL_DESTINATION "${install_location}")
Expand Down
2 changes: 1 addition & 1 deletion rapids-cmake/export/template/config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
# 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.
Expand Down
2 changes: 1 addition & 1 deletion rapids-cmake/export/template/cpm.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
# 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.
Expand Down
2 changes: 1 addition & 1 deletion rapids-cmake/export/template/dependencies.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
# 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.
Expand Down
3 changes: 2 additions & 1 deletion rapids-cmake/export/write_dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# 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.
Expand Down Expand Up @@ -130,6 +130,7 @@ endif()\n")

string(APPEND _RAPIDS_EXPORT_CONTENTS "set(rapids_global_targets ${global_targets})\n")

string(TIMESTAMP current_year "%Y" UTC)
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/dependencies.cmake.in" "${file_path}"
@ONLY)
endfunction()
3 changes: 2 additions & 1 deletion rapids-cmake/find/generate_module.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# 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.
Expand Down Expand Up @@ -201,6 +201,7 @@ function(rapids_find_generate_module name)
endif()

# Need to generate the module
string(TIMESTAMP current_year "%Y" UTC)
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/find_module.cmake.in"
"${CMAKE_BINARY_DIR}/cmake/find_modules/Find${name}.cmake" @ONLY)

Expand Down
2 changes: 1 addition & 1 deletion rapids-cmake/find/template/find_module.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
# 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.
Expand Down
3 changes: 2 additions & 1 deletion testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# 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.
Expand Down Expand Up @@ -42,6 +42,7 @@ add_cmake_config_test( cpm_package_override-simple.cmake )
add_cmake_config_test( cpm_generate_patch_command-invalid.cmake )
add_cmake_config_test( cpm_generate_patch_command-override.cmake )
add_cmake_config_test( cpm_generate_patch_command-current_json_dir.cmake )
add_cmake_config_test( cpm_generate_patch_command-verify-copyright-header.cmake )

add_cmake_config_test( cpm_cccl-simple.cmake )
add_cmake_config_test( cpm_cccl-export.cmake )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#=============================================================================
# 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)
include(${rapids-cmake-testing-dir}/utils/check_copyright_header.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()

check_copyright_header("${CMAKE_BINARY_DIR}/rapids-cmake/patches/pkg_with_patch/patch.cmake")
3 changes: 2 additions & 1 deletion testing/export/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# 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.
Expand Down Expand Up @@ -44,6 +44,7 @@ add_cmake_config_test( export-verify-file-names.cmake )
add_cmake_config_test( export-verify-implicit-disabled-version.cmake )
add_cmake_config_test( export-verify-implicit-major-version-only-matching.cmake )
add_cmake_config_test( export-verify-version.cmake )
add_cmake_config_test( export-verify-copyright-header.cmake )

add_cmake_config_test( export_component-build )

Expand Down
46 changes: 46 additions & 0 deletions testing/export/export-verify-copyright-header.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#=============================================================================
# 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}/export/cpm.cmake)
include(${rapids-cmake-dir}/export/export.cmake)
include(${rapids-cmake-dir}/export/write_dependencies.cmake)
include(${rapids-cmake-testing-dir}/utils/check_copyright_header.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::
)

check_copyright_header("${CMAKE_BINARY_DIR}/fakeproject-config.cmake")
check_copyright_header("${CMAKE_BINARY_DIR}/rapids-cmake/fakeproject/export/fakeproject/fakeproject-config.cmake")
check_copyright_header("${CMAKE_BINARY_DIR}/rapids-cmake/FakEProJecT/build/cpm_RaFT.cmake")
check_copyright_header("${CMAKE_BINARY_DIR}/dependencies.cmake")
4 changes: 3 additions & 1 deletion testing/find/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# 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.
Expand Down Expand Up @@ -44,3 +44,5 @@ add_cmake_config_test( find_generate_module-header-only )
add_cmake_config_test( find_generate_module-code-blocks )
add_cmake_config_test( find_generate_module-back-initial-code-block-var.cmake SHOULD_FAIL "INITIAL_CODE_BLOCK variable `var_doesn't_exist` doesn't exist")
add_cmake_config_test( find_generate_module-back-final-code-block-var.cmake SHOULD_FAIL "FINAL_CODE_BLOCK variable `var_doesn't_exist` doesn't exist")

add_cmake_config_test( find_generate_module-verify-copyright-header.cmake )
24 changes: 24 additions & 0 deletions testing/find/find_generate_module-verify-copyright-header.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#=============================================================================
# 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)
include(${rapids-cmake-testing-dir}/utils/check_copyright_header.cmake)

rapids_find_generate_module( RapidsTest
HEADER_NAMES rapids-cmake-test-header_only.hpp
INSTALL_EXPORT_SET test_set
)

check_copyright_header("${CMAKE_BINARY_DIR}/cmake/find_modules/FindRapidsTest.cmake")
42 changes: 42 additions & 0 deletions testing/utils/check_copyright_header.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#=============================================================================
# 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_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()

0 comments on commit 9798e7d

Please sign in to comment.