From 6c299000a7a411f10b92316af6e4fe8e5bf51766 Mon Sep 17 00:00:00 2001 From: Mike Chang Date: Wed, 8 Dec 2021 12:45:44 -0800 Subject: [PATCH] Notices automation install (#6228) This will generate the NOTICES.txt license file and SPDX-Licenses.json manifest file on every installer run. Signed-off-by: Mike Chang --- cmake/Packaging.cmake | 17 +++++++++ cmake/Packaging/LicenseScan.cmake.in | 38 +++++++++++++++++++ .../Linux/PackagingPostBuild_linux.cmake | 4 +- .../Windows/PackagingPostBuild_windows.cmake | 7 ++-- 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 cmake/Packaging/LicenseScan.cmake.in diff --git a/cmake/Packaging.cmake b/cmake/Packaging.cmake index 4ba4e750de..ecef5261b1 100644 --- a/cmake/Packaging.cmake +++ b/cmake/Packaging.cmake @@ -94,6 +94,23 @@ endif() # cpack generation. CPACK_BINARY_DIR persists across cpack invocations set(LY_CMAKE_PACKAGE_DOWNLOAD_PATH ${CPACK_BINARY_DIR}/${CPACK_CMAKE_PACKAGE_FILE}) +# Scan the source and 3p packages for licenses, then add the generated license results to the binary output folder. +# These results will be installed to the root of the install folder and copied to the S3 bucket specific to each platform +set(CPACK_3P_LICENSE_FILE "${CPACK_BINARY_DIR}/NOTICES.txt") +set(CPACK_3P_MANIFEST_FILE "${CPACK_BINARY_DIR}/SPDX-License.json") + +configure_file(${LY_ROOT_FOLDER}/cmake/Packaging/LicenseScan.cmake.in + ${CPACK_BINARY_DIR}/LicenseScan.cmake + @ONLY +) +ly_install(SCRIPT ${CPACK_BINARY_DIR}/LicenseScan.cmake + COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} +) +ly_install(FILES ${CPACK_3P_LICENSE_FILE} ${CPACK_3P_MANIFEST_FILE} + DESTINATION . + COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} +) + configure_file(${LY_ROOT_FOLDER}/cmake/Packaging/CMakeDownload.cmake.in ${CPACK_BINARY_DIR}/CMakeDownload.cmake @ONLY diff --git a/cmake/Packaging/LicenseScan.cmake.in b/cmake/Packaging/LicenseScan.cmake.in new file mode 100644 index 0000000000..314d5729c2 --- /dev/null +++ b/cmake/Packaging/LicenseScan.cmake.in @@ -0,0 +1,38 @@ +# +# Copyright (c) Contributors to the Open 3D Engine Project. +# For complete copyright and license terms please see the LICENSE at the root of this distribution. +# +# SPDX-License-Identifier: Apache-2.0 OR MIT +# +# + +set(LY_ROOT_FOLDER "@LY_ROOT_FOLDER@") +set(CMAKE_SCRIPT_MODE_FILE TRUE) + +# Scan the engine and 3rd Party folders for licenses +cmake_path(SET _license_script_path "@LY_ROOT_FOLDER@/scripts/license_scanner") +cmake_path(SET _license_script "${_license_script_path}/license_scanner.py") +cmake_path(SET _license_config "${_license_script_path}/scanner_config.json") + +set(_license_scan_path "@LY_ROOT_FOLDER@" "@LY_PACKAGE_UNPACK_LOCATION@") +set(_license_command + @LY_PYTHON_CMD@ -s + -u ${_license_script} + --config-file ${_license_config} + --license-file-path @CPACK_3P_LICENSE_FILE@ + --package-file-path @CPACK_3P_MANIFEST_FILE@ +) + +message("Scanning ${_license_scan_path} for package licenses") + +execute_process( + COMMAND ${_license_command} --scan-path ${_license_scan_path} + RESULT_VARIABLE _license_result + ERROR_VARIABLE _license_errors + OUTPUT_VARIABLE _license_output + ECHO_OUTPUT_VARIABLE +) + +if(NOT ${_license_result} EQUAL 0) + message(FATAL_ERROR "An error occurred during license scan. ${_license_errors}") +endif() diff --git a/cmake/Platform/Linux/PackagingPostBuild_linux.cmake b/cmake/Platform/Linux/PackagingPostBuild_linux.cmake index ebeefe3833..63c21a85eb 100644 --- a/cmake/Platform/Linux/PackagingPostBuild_linux.cmake +++ b/cmake/Platform/Linux/PackagingPostBuild_linux.cmake @@ -33,6 +33,8 @@ if(CPACK_UPLOAD_URL) "${CPACK_TOPLEVEL_DIRECTORY}/*.deb" "${CPACK_TOPLEVEL_DIRECTORY}/*.sha256" "${LY_ROOT_FOLDER}/scripts/signer/Platform/Linux/*.gpg" + "${CPACK_3P_LICENSE_FILE}" + "${CPACK_3P_MANIFEST_FILE}" ) file(COPY ${_artifacts} DESTINATION ${CPACK_UPLOAD_DIRECTORY} @@ -42,7 +44,7 @@ if(CPACK_UPLOAD_URL) ly_upload_to_url( ${CPACK_UPLOAD_URL} ${CPACK_UPLOAD_DIRECTORY} - ".*(.deb|.gpg|.sha256)$" + ".*(.deb|.gpg|.sha256|.txt|.json)$" ) # for auto tagged builds, we will also upload a second copy of just the boostrapper diff --git a/cmake/Platform/Windows/PackagingPostBuild_windows.cmake b/cmake/Platform/Windows/PackagingPostBuild_windows.cmake index 10f0f902a3..832e8675f2 100644 --- a/cmake/Platform/Windows/PackagingPostBuild_windows.cmake +++ b/cmake/Platform/Windows/PackagingPostBuild_windows.cmake @@ -102,6 +102,8 @@ file(GLOB _artifacts "${_cpack_wix_out_dir}/*.msi" "${_cpack_wix_out_dir}/*.cab" "${_cpack_wix_out_dir}/*.exe" + "${CPACK_3P_LICENSE_FILE}" + "${CPACK_3P_MANIFEST_FILE}" ) file(COPY ${_artifacts} DESTINATION ${CPACK_UPLOAD_DIRECTORY} @@ -109,11 +111,10 @@ file(COPY ${_artifacts} message(STATUS "Artifacts copied to ${CPACK_UPLOAD_DIRECTORY}") if(CPACK_UPLOAD_URL) - file(TO_NATIVE_PATH "${_cpack_wix_out_dir}" _cpack_wix_out_dir) ly_upload_to_url( ${CPACK_UPLOAD_URL} - ${_cpack_wix_out_dir} - ".*(cab|exe|msi)$" + ${CPACK_UPLOAD_DIRECTORY} + ".*(.cab|.exe|.msi|.txt|.json)$" ) # for auto tagged builds, we will also upload a second copy of just the boostrapper