From 14474dbac72650c05eeea0927f6fdc5d2b98fe11 Mon Sep 17 00:00:00 2001 From: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> Date: Tue, 5 Oct 2021 11:24:37 -0500 Subject: [PATCH] Swapped the order in which the engine.pak is searched (#4455) * Swapped the order in which the engine.pak is searched First the Project Cache Root folder is searched before falling back to the Executable Directory Removed the need for the engine.json and project.json in a project release layout when a "Cache" directory exist at the root. The project root uses the the first "Cache" directory it finds by scanning upwards as if fails to find a project.json, The engine root use the project root, if it fails to reconcile the engine path using project.json "engine" key and the o3de_manifest.json "engines_path" object. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed Generation of the engine.json and project.json in Release Install builds. The project and engine path can be determined based on the Cache directory location. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Added missing space for enginePakOpened Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding missing endif() and bracket argument terminator. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> --- .../Settings/SettingsRegistryMergeUtils.cpp | 12 ++++++-- .../Application/GameApplication.cpp | 28 ++++++++++--------- cmake/Platform/Common/Install_common.cmake | 15 ---------- cmake/Projects.cmake | 5 +--- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.cpp b/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.cpp index 113fdd433e..e1bd717e7b 100644 --- a/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.cpp +++ b/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.cpp @@ -276,7 +276,9 @@ namespace AZ::SettingsRegistryMergeUtils return engineRoot; } - return {}; + // Fall back to using the project root as the engine root if the engine path could not be reconciled + // by checking the project.json "engine" string within o3de_manifest.json "engine_paths" object + return projectRoot; } AZ::IO::FixedMaxPath FindProjectRoot(SettingsRegistryInterface& settingsRegistry) @@ -309,7 +311,13 @@ namespace AZ::SettingsRegistryMergeUtils return projectRoot; } - return {}; + // Step 3 Check for a "Cache" directory by scanning upwards from the executable directory + if (auto candidateRoot = Internal::ScanUpRootLocator("Cache"); + !candidateRoot.empty() && AZ::IO::SystemFile::IsDirectory(candidateRoot.c_str())) + { + projectRoot = AZStd::move(candidateRoot); + } + return projectRoot; } AZStd::string_view ConfigParserSettings::DefaultCommentPrefixFilter(AZStd::string_view line) diff --git a/Code/Framework/AzGameFramework/AzGameFramework/Application/GameApplication.cpp b/Code/Framework/AzGameFramework/AzGameFramework/Application/GameApplication.cpp index 475a7d5504..424132b624 100644 --- a/Code/Framework/AzGameFramework/AzGameFramework/Application/GameApplication.cpp +++ b/Code/Framework/AzGameFramework/AzGameFramework/Application/GameApplication.cpp @@ -28,20 +28,22 @@ namespace AzGameFramework // can read from the FileIOBase instance if available m_settingsRegistry->SetUseFileIO(true); - // Attempt to mount the engine pak from the Executable Directory - // at the Assets alias, otherwise to attempting to mount the engine pak - // from the Cache folder - AZ::IO::FixedMaxPath enginePakPath = AZ::Utils::GetExecutableDirectory(); - enginePakPath /= "engine.pak"; - if (!m_archive->OpenPack("@assets@", enginePakPath.Native())) + // Attempt to mount the engine pak to the project product asset alias + // Search Order: + // - Project Cache Root Directory + // - Executable Directory + bool enginePakOpened{}; + AZ::IO::FixedMaxPath enginePakPath; + if (m_settingsRegistry->Get(enginePakPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_CacheRootFolder)) { - enginePakPath.clear(); - if (m_settingsRegistry->Get(enginePakPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_CacheRootFolder)) - { - // fall back to checking Project Cache Root. - enginePakPath /= "engine.pak"; - m_archive->OpenPack("@assets@", enginePakPath.Native()); - } + // fall back to checking Project Cache Root. + enginePakPath /= "engine.pak"; + enginePakOpened = m_archive->OpenPack("@projectproductassets@", enginePakPath.Native()); + } + if (!enginePakOpened) + { + enginePakPath = AZ::IO::FixedMaxPath(AZ::Utils::GetExecutableDirectory()) / "engine.pak"; + m_archive->OpenPack("@projectproductassets@", enginePakPath.Native()); } } diff --git a/cmake/Platform/Common/Install_common.cmake b/cmake/Platform/Common/Install_common.cmake index 5fa7f21939..8fb2effe29 100644 --- a/cmake/Platform/Common/Install_common.cmake +++ b/cmake/Platform/Common/Install_common.cmake @@ -430,21 +430,6 @@ function(ly_setup_cmake_install) DESTINATION . COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} ) - string(CONFIGURE [=[ -if("${CMAKE_INSTALL_CONFIG_NAME}" MATCHES "^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$") - set(install_output_folder "${CMAKE_INSTALL_PREFIX}/@runtime_output_directory@") - file(WRITE ${install_output_folder}/engine.json -"{ - \"engine_name\": \"@LY_VERSION_ENGINE_NAME@\" -}") -endif() -]=] - install_engine_json_release - @ONLY - ) - install(CODE ${install_engine_json_release} - COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} # use the default for the time being - ) # Collect all Find files that were added with ly_add_external_target_path unset(additional_find_files) diff --git a/cmake/Projects.cmake b/cmake/Projects.cmake index 6109229e72..c09fe0fc6f 100644 --- a/cmake/Projects.cmake +++ b/cmake/Projects.cmake @@ -173,12 +173,9 @@ if("${CMAKE_INSTALL_CONFIG_NAME}" MATCHES "^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$") message(STATUS "${install_output_folder}/engine.pak generated") endif() endif() - file(WRITE ${install_output_folder}/project.json -"{ - \"project_name\": \"@project_name@\" -}") endif() ]=]) + string(CONFIGURE "${install_engine_pak_template}" install_engine_pak_code @ONLY) ly_install_run_code("${install_engine_pak_code}")