From 952901f55b7ebade4c38abc524344330ffb0efa6 Mon Sep 17 00:00:00 2001 From: scottr Date: Tue, 25 May 2021 11:33:59 -0700 Subject: [PATCH 1/5] [cpack_installer] adding setup script to install cmake, python, and registering the engine --- .../CMake/cmake-3.19.1-win64-x64.zip | 3 + scripts/setup.bat | 93 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 Tools/Redistributables/CMake/cmake-3.19.1-win64-x64.zip create mode 100644 scripts/setup.bat diff --git a/Tools/Redistributables/CMake/cmake-3.19.1-win64-x64.zip b/Tools/Redistributables/CMake/cmake-3.19.1-win64-x64.zip new file mode 100644 index 0000000000..fc3a243f06 --- /dev/null +++ b/Tools/Redistributables/CMake/cmake-3.19.1-win64-x64.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e95d70549f306adb46e0f131dcecdbcbc6412d3a1e073c2c0078812391bf21d3 +size 36098689 diff --git a/scripts/setup.bat b/scripts/setup.bat new file mode 100644 index 0000000000..34251ad861 --- /dev/null +++ b/scripts/setup.bat @@ -0,0 +1,93 @@ +@echo off +rem +rem All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +rem its licensors. +rem +rem For complete copyright and license terms please see the LICENSE at the root of this +rem distribution (the "License"). All use of this software is governed by the License, +rem or, if provided, by the license below or the license accompanying this file. Do not +rem remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +rem + +pushd %~dp0% + +pushd %~dp0.. +set ENGINE_ROOT=%CD% +popd + +set cmake_version=3.19.1 + +if not "%1"=="" ( + set LY_3RDPARTY_PATH=%1 +) +if "%LY_3RDPARTY_PATH%"=="" goto no_3rd_party + +if not exist %LY_3RDPARTY_PATH% mkdir %LY_3RDPARTY_PATH% +goto install_cmake + +:no_3rd_party +echo A path to where the 3rd party folder is required for setup. +echo Either supply one through the LY_3RDPARTY_PATH environment +echo variable or as an argument to this script +goto fail + + +:install_cmake +set cmake_install_path=%LY_3RDPARTY_PATH%\CMake\%cmake_version%\Windows +set cmake_archive_name=cmake-%cmake_version%-win64-x64 +set cmake_archive_path="%ENGINE_ROOT%\Tools\Redistributables\CMake\%cmake_archive_name%.zip" +if exist "%cmake_install_path%\bin\cmake.exe" goto install_python + +echo Installing CMake %cmake_version% to %cmake_install_path% +if not exist %cmake_install_path% mkdir %cmake_install_path% +powershell.exe -nologo -noprofile -command^ + "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%cmake_archive_path%', '%cmake_install_path%'); }" +if ERRORLEVEL 1 goto cmake_failed + +set cmake_extracted_path=%cmake_install_path%\%cmake_archive_name% +for /d %%a in ("%cmake_extracted_path%\*") do move "%%a" "%cmake_install_path%\" +rmdir %cmake_extracted_path% + +goto success + +if ERRORLEVEL 1 goto cmake_failed +set LY_CMAKE_PATH="%cmake_install_path%\bin" +goto install_python + +:cmake_failed +echo Failed to extract cmake to path %cmake_install_path% +goto fail + + +:install_python +echo Installing python... +call %ENGINE_ROOT%\python\get_python.bat +if ERRORLEVEL 1 goto python_failed +goto register_engine + +:python_failed +echo Failed to acquire python +goto fail + + +:register_engine +echo Registering engine... +call %ENGINE_ROOT%\scripts\o3de.bat register --this-engine +if ERRORLEVEL 1 goto registration_failed +goto success + +:registration_failed +echo Failed to register the engine +goto fail + + +:fail +echo O3DE setup failed +popd +exit /b 1 + +:success +echo O3DE setup complete +popd +exit /b %ERRORLEVEL% From 2ba645c2649914750156b577f3cd5fd2d30119d5 Mon Sep 17 00:00:00 2001 From: scottr Date: Wed, 26 May 2021 16:13:14 -0700 Subject: [PATCH 2/5] [cpack_installer] post install hooks to install cmake and python --- cmake/LYWrappers.cmake | 3 +- cmake/Platform/Common/Install_common.cmake | 2 +- .../Windows/Packaging/PostInstallSetup.wxs | 67 +++++++++++++ .../Windows/Packaging/Template.wxs.in | 19 +++- .../Platform/Windows/Packaging_windows.cmake | 5 + scripts/setup.bat | 93 ------------------- 6 files changed, 92 insertions(+), 97 deletions(-) create mode 100644 cmake/Platform/Windows/Packaging/PostInstallSetup.wxs delete mode 100644 scripts/setup.bat diff --git a/cmake/LYWrappers.cmake b/cmake/LYWrappers.cmake index f6a36afc89..2f8349c840 100644 --- a/cmake/LYWrappers.cmake +++ b/cmake/LYWrappers.cmake @@ -334,7 +334,8 @@ function(ly_add_target) if(NOT ly_add_target_IMPORTED) if(NOT ly_add_target_INSTALL_COMPONENT) - set(ly_add_target_INSTALL_COMPONENT ${LY_DEFAULT_INSTALL_COMPONENT}) + #set(ly_add_target_INSTALL_COMPONENT ${LY_DEFAULT_INSTALL_COMPONENT}) + set(ly_add_target_INSTALL_COMPONENT ${ly_add_target_NAMESPACE}) endif() ly_install_target( diff --git a/cmake/Platform/Common/Install_common.cmake b/cmake/Platform/Common/Install_common.cmake index 8fe2fe2c1c..46d23f7b91 100644 --- a/cmake/Platform/Common/Install_common.cmake +++ b/cmake/Platform/Common/Install_common.cmake @@ -286,7 +286,7 @@ endfunction() function(ly_setup_others) # List of directories we want to install relative to engine root - set(DIRECTORIES_TO_INSTALL Tools/LyTestTools Tools/RemoteConsole) + set(DIRECTORIES_TO_INSTALL Tools/LyTestTools Tools/RemoteConsole Tools/Redistributables/CMake) foreach(dir ${DIRECTORIES_TO_INSTALL}) get_filename_component(install_path ${dir} DIRECTORY) diff --git a/cmake/Platform/Windows/Packaging/PostInstallSetup.wxs b/cmake/Platform/Windows/Packaging/PostInstallSetup.wxs new file mode 100644 index 0000000000..ebcaa9502f --- /dev/null +++ b/cmake/Platform/Windows/Packaging/PostInstallSetup.wxs @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cmake/Platform/Windows/Packaging/Template.wxs.in b/cmake/Platform/Windows/Packaging/Template.wxs.in index 2900b96f41..e14e064fbc 100644 --- a/cmake/Platform/Windows/Packaging/Template.wxs.in +++ b/cmake/Platform/Windows/Packaging/Template.wxs.in @@ -17,8 +17,7 @@ - @@ -41,8 +40,24 @@ + + + + + + + NOT Installed Or REINSTALL + + + NOT Installed Or REINSTALL + + + NOT Installed Or REINSTALL + + + diff --git a/cmake/Platform/Windows/Packaging_windows.cmake b/cmake/Platform/Windows/Packaging_windows.cmake index ce73e9a07b..b7db250fda 100644 --- a/cmake/Platform/Windows/Packaging_windows.cmake +++ b/cmake/Platform/Windows/Packaging_windows.cmake @@ -83,9 +83,14 @@ set(CPACK_WIX_PRODUCT_ICON ${CPACK_SOURCE_DIR}/Platform/Windows/Packaging/produc set(CPACK_WIX_TEMPLATE "${CPACK_SOURCE_DIR}/Platform/Windows/Packaging/Template.wxs.in") set(CPACK_WIX_EXTRA_SOURCES + "${CPACK_SOURCE_DIR}/Platform/Windows/Packaging/PostInstallSetup.wxs" "${CPACK_SOURCE_DIR}/Platform/Windows/Packaging/Shortcuts.wxs" ) +set(CPACK_WIX_EXTENSIONS + WixUtilExtension +) + set(_embed_artifacts "yes") if(LY_INSTALLER_DOWNLOAD_URL) diff --git a/scripts/setup.bat b/scripts/setup.bat deleted file mode 100644 index 34251ad861..0000000000 --- a/scripts/setup.bat +++ /dev/null @@ -1,93 +0,0 @@ -@echo off -rem -rem All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -rem its licensors. -rem -rem For complete copyright and license terms please see the LICENSE at the root of this -rem distribution (the "License"). All use of this software is governed by the License, -rem or, if provided, by the license below or the license accompanying this file. Do not -rem remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -rem - -pushd %~dp0% - -pushd %~dp0.. -set ENGINE_ROOT=%CD% -popd - -set cmake_version=3.19.1 - -if not "%1"=="" ( - set LY_3RDPARTY_PATH=%1 -) -if "%LY_3RDPARTY_PATH%"=="" goto no_3rd_party - -if not exist %LY_3RDPARTY_PATH% mkdir %LY_3RDPARTY_PATH% -goto install_cmake - -:no_3rd_party -echo A path to where the 3rd party folder is required for setup. -echo Either supply one through the LY_3RDPARTY_PATH environment -echo variable or as an argument to this script -goto fail - - -:install_cmake -set cmake_install_path=%LY_3RDPARTY_PATH%\CMake\%cmake_version%\Windows -set cmake_archive_name=cmake-%cmake_version%-win64-x64 -set cmake_archive_path="%ENGINE_ROOT%\Tools\Redistributables\CMake\%cmake_archive_name%.zip" -if exist "%cmake_install_path%\bin\cmake.exe" goto install_python - -echo Installing CMake %cmake_version% to %cmake_install_path% -if not exist %cmake_install_path% mkdir %cmake_install_path% -powershell.exe -nologo -noprofile -command^ - "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%cmake_archive_path%', '%cmake_install_path%'); }" -if ERRORLEVEL 1 goto cmake_failed - -set cmake_extracted_path=%cmake_install_path%\%cmake_archive_name% -for /d %%a in ("%cmake_extracted_path%\*") do move "%%a" "%cmake_install_path%\" -rmdir %cmake_extracted_path% - -goto success - -if ERRORLEVEL 1 goto cmake_failed -set LY_CMAKE_PATH="%cmake_install_path%\bin" -goto install_python - -:cmake_failed -echo Failed to extract cmake to path %cmake_install_path% -goto fail - - -:install_python -echo Installing python... -call %ENGINE_ROOT%\python\get_python.bat -if ERRORLEVEL 1 goto python_failed -goto register_engine - -:python_failed -echo Failed to acquire python -goto fail - - -:register_engine -echo Registering engine... -call %ENGINE_ROOT%\scripts\o3de.bat register --this-engine -if ERRORLEVEL 1 goto registration_failed -goto success - -:registration_failed -echo Failed to register the engine -goto fail - - -:fail -echo O3DE setup failed -popd -exit /b 1 - -:success -echo O3DE setup complete -popd -exit /b %ERRORLEVEL% From cccb68fa38e479b1d0aa851718620384ff483ff2 Mon Sep 17 00:00:00 2001 From: scottr Date: Wed, 26 May 2021 16:21:04 -0700 Subject: [PATCH 3/5] [cpack_installer] revert accidental debug change committed --- cmake/LYWrappers.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/LYWrappers.cmake b/cmake/LYWrappers.cmake index f7290009de..8aba6ccb99 100644 --- a/cmake/LYWrappers.cmake +++ b/cmake/LYWrappers.cmake @@ -339,8 +339,7 @@ function(ly_add_target) if(NOT ly_add_target_IMPORTED) if(NOT ly_add_target_INSTALL_COMPONENT) - #set(ly_add_target_INSTALL_COMPONENT ${LY_DEFAULT_INSTALL_COMPONENT}) - set(ly_add_target_INSTALL_COMPONENT ${ly_add_target_NAMESPACE}) + set(ly_add_target_INSTALL_COMPONENT ${LY_DEFAULT_INSTALL_COMPONENT}) endif() ly_install_target( From 883ddf667e70fe61491dcc2a7162e59bc5d46166 Mon Sep 17 00:00:00 2001 From: scottr Date: Wed, 26 May 2021 20:19:42 -0700 Subject: [PATCH 4/5] [cpack_installer] removed static cmake package in favor of using file(DOWNLOAD ...) --- .../CMake/cmake-3.19.1-win64-x64.zip | 3 -- cmake/Packaging.cmake | 37 +++++++++++++++++++ cmake/Platform/Common/Install_common.cmake | 2 +- .../Windows/Packaging/PostInstallSetup.wxs | 6 +-- .../Platform/Windows/Packaging_windows.cmake | 5 +++ 5 files changed, 45 insertions(+), 8 deletions(-) delete mode 100644 Tools/Redistributables/CMake/cmake-3.19.1-win64-x64.zip diff --git a/Tools/Redistributables/CMake/cmake-3.19.1-win64-x64.zip b/Tools/Redistributables/CMake/cmake-3.19.1-win64-x64.zip deleted file mode 100644 index fc3a243f06..0000000000 --- a/Tools/Redistributables/CMake/cmake-3.19.1-win64-x64.zip +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e95d70549f306adb46e0f131dcecdbcbc6412d3a1e073c2c0078812391bf21d3 -size 36098689 diff --git a/cmake/Packaging.cmake b/cmake/Packaging.cmake index fbeffa94eb..7766d7d0ee 100644 --- a/cmake/Packaging.cmake +++ b/cmake/Packaging.cmake @@ -17,6 +17,8 @@ endif() set(LY_INSTALLER_DOWNLOAD_URL "" CACHE STRING "URL embedded into the installer to download additional artifacts") set(LY_INSTALLER_LICENSE_URL "" CACHE STRING "Optionally embed a link to the license instead of raw text") +set(CPACK_DESIRED_CMAKE_VERSION 3.20.2) + # set all common cpack variable overrides first so they can be accessible via configure_file # when the platform specific settings are applied below. additionally, any variable with # the "CPACK_" prefix will automatically be cached for use in any phase of cpack namely @@ -38,6 +40,7 @@ set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_VENDOR}/${CPACK_PACKAGE_VER # neither of the SOURCE_DIR variables equate to anything during execution of pre/post build scripts set(CPACK_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR}/_CPack) # to match other CPack out dirs # attempt to apply platform specific settings ly_get_absolute_pal_filename(pal_dir ${CPACK_SOURCE_DIR}/Platform/${PAL_HOST_PLATFORM_NAME}) @@ -48,6 +51,40 @@ if(NOT CPACK_GENERATOR) return() endif() +# pull down the desired copy of CMake so it can be included in the package +if(NOT (CPACK_CMAKE_PACKAGE_FILE AND CPACK_CMAKE_PACKAGE_HASH)) + message(FATAL_ERROR + "Packaging is missing one or more following properties required to include CMake: " + " CPACK_CMAKE_PACKAGE_FILE, CPACK_CMAKE_PACKAGE_HASH") +endif() + +set(_cmake_package_dest ${CPACK_BINARY_DIR}/${CPACK_CMAKE_PACKAGE_FILE}) + +string(REPLACE "." ";" _version_componets "${CPACK_DESIRED_CMAKE_VERSION}") +list(GET _version_componets 0 _major_version) +list(GET _version_componets 1 _minor_version) + +set(_url_version_tag "v${_major_version}.${_minor_version}") + +message(STATUS "Ensuring CMake ${CPACK_DESIRED_CMAKE_VERSION} is avaiable for packaging...") +file(DOWNLOAD + https://cmake.org/files/${_url_version_tag}/${CPACK_CMAKE_PACKAGE_FILE} + ${_cmake_package_dest} +) + +file(SHA256 ${_cmake_package_dest} _package_hash) +if (NOT "${_package_hash}" STREQUAL "${CPACK_CMAKE_PACKAGE_HASH}") + file(REMOVE ${_cmake_package_dest}) + message(FATAL_ERROR "Donwload package of CMake does not match expected hash value. " + "Please double check the properies CPACK_CMAKE_PACKAGE_FILE and CPACK_CMAKE_PACKAGE_HASH " + "before trying again.") +endif() + +install(FILES ${_cmake_package_dest} + DESTINATION ./Tools/Redistributables/CMake + COMPONENT ${LY_DEFAULT_INSTALL_COMPONENT} +) + # IMPORTANT: required to be included AFTER setting all property overrides include(CPack REQUIRED) diff --git a/cmake/Platform/Common/Install_common.cmake b/cmake/Platform/Common/Install_common.cmake index 46d23f7b91..8fe2fe2c1c 100644 --- a/cmake/Platform/Common/Install_common.cmake +++ b/cmake/Platform/Common/Install_common.cmake @@ -286,7 +286,7 @@ endfunction() function(ly_setup_others) # List of directories we want to install relative to engine root - set(DIRECTORIES_TO_INSTALL Tools/LyTestTools Tools/RemoteConsole Tools/Redistributables/CMake) + set(DIRECTORIES_TO_INSTALL Tools/LyTestTools Tools/RemoteConsole) foreach(dir ${DIRECTORIES_TO_INSTALL}) get_filename_component(install_path ${dir} DIRECTORY) diff --git a/cmake/Platform/Windows/Packaging/PostInstallSetup.wxs b/cmake/Platform/Windows/Packaging/PostInstallSetup.wxs index ebcaa9502f..d4f6c181dd 100644 --- a/cmake/Platform/Windows/Packaging/PostInstallSetup.wxs +++ b/cmake/Platform/Windows/Packaging/PostInstallSetup.wxs @@ -43,16 +43,14 @@ - - diff --git a/cmake/Platform/Windows/Packaging_windows.cmake b/cmake/Platform/Windows/Packaging_windows.cmake index b7db250fda..db9c7fc906 100644 --- a/cmake/Platform/Windows/Packaging_windows.cmake +++ b/cmake/Platform/Windows/Packaging_windows.cmake @@ -28,6 +28,10 @@ endif() set(CPACK_GENERATOR "WIX") +set(_cmake_package_name "cmake-${CPACK_DESIRED_CMAKE_VERSION}-windows-x86_64") +set(CPACK_CMAKE_PACKAGE_FILE "${_cmake_package_name}.zip") +set(CPACK_CMAKE_PACKAGE_HASH "15a49e2ab81c1822d75b1b1a92f7863f58e31f6d6aac1c4103eef2b071be3112") + # CPack will generate the WiX product/upgrade GUIDs further down the chain if they weren't supplied # however, they are unique for each run. instead, let's do the auto generation here and add it to # the cache for run persistence and have the ability to detect if they are still being used. @@ -106,4 +110,5 @@ endif() set(CPACK_WIX_CANDLE_EXTRA_FLAGS -dCPACK_EMBED_ARTIFACTS=${_embed_artifacts} + -dCPACK_CMAKE_PACKAGE_NAME=${_cmake_package_name} ) From 301bfe34861c0837defdccdc4d04b5b6f741ead2 Mon Sep 17 00:00:00 2001 From: scottr Date: Wed, 26 May 2021 22:03:46 -0700 Subject: [PATCH 5/5] [cpack_installer] replaced raw file(DOWNLOAD ...) for download_file() utility --- cmake/Packaging.cmake | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/cmake/Packaging.cmake b/cmake/Packaging.cmake index 7766d7d0ee..84bad13687 100644 --- a/cmake/Packaging.cmake +++ b/cmake/Packaging.cmake @@ -65,19 +65,32 @@ list(GET _version_componets 0 _major_version) list(GET _version_componets 1 _minor_version) set(_url_version_tag "v${_major_version}.${_minor_version}") +set(_package_url "https://cmake.org/files/${_url_version_tag}/${CPACK_CMAKE_PACKAGE_FILE}") -message(STATUS "Ensuring CMake ${CPACK_DESIRED_CMAKE_VERSION} is avaiable for packaging...") -file(DOWNLOAD - https://cmake.org/files/${_url_version_tag}/${CPACK_CMAKE_PACKAGE_FILE} - ${_cmake_package_dest} +message(STATUS "Ensuring CMake ${CPACK_DESIRED_CMAKE_VERSION} is available for packaging...") +download_file( + URL ${_package_url} + TARGET_FILE ${_cmake_package_dest} + EXPECTED_HASH ${CPACK_CMAKE_PACKAGE_HASH} + RESULTS _results ) +list(GET _results 0 _status_code) -file(SHA256 ${_cmake_package_dest} _package_hash) -if (NOT "${_package_hash}" STREQUAL "${CPACK_CMAKE_PACKAGE_HASH}") +if (${_status_code} EQUAL 0 AND EXISTS ${_cmake_package_dest}) + message(STATUS "-> Package found and verified!") +else() file(REMOVE ${_cmake_package_dest}) - message(FATAL_ERROR "Donwload package of CMake does not match expected hash value. " - "Please double check the properies CPACK_CMAKE_PACKAGE_FILE and CPACK_CMAKE_PACKAGE_HASH " - "before trying again.") + list(REMOVE_AT _results 0) + + set(_error_message "An error occurred, code ${_status_code}. URL ${_package_url} - ${_results}") + + if(${_status_code} EQUAL 1) + string(APPEND _error_message + " Please double check the CPACK_CMAKE_PACKAGE_FILE and " + "CPACK_CMAKE_PACKAGE_HASH properties before trying again.") + endif() + + message(FATAL_ERROR ${_error_message}) endif() install(FILES ${_cmake_package_dest}