[LYN-8041] Enable relocation of the Project Game Release Layout (#5380)
* Enable relocation of the Project Game Release Layout Relocating the Project Game Release Layout to another directory on the file system failed due to the querying of the engine root failing due to the ComponentApplication::m_engineRoot not using the project path stored in the SettingsRegisry if the engine root cannot be detected Removed the ApplicationRequestBus GetEngineRoot function. The ComponentApplicationRequestBus has a function of the same name that returns the same path. Removed the deprecated GetAppRoot function. The path it returns has no defined value. It was not the engine root or the project root. Removed unused CFileUtil and CFileUtil_impl functions that were invoking the ApplicationREquestBus GetEngineRoot function. On the way to update the functions it was discovered that they aren't called Added a CalculateBranchToken overload that can populate a fixed_string to avoid heap allocations Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Protect against an empty list of artifacts to remove when generating the engine.pak Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
d053a03b5f
commit
5fc4551ac0
@@ -485,16 +485,6 @@ namespace AZ
|
||||
constexpr bool executeRegDumpCommands = false;
|
||||
SettingsRegistryMergeUtils::MergeSettingsToRegistry_CommandLine(*m_settingsRegistry, m_commandLine, executeRegDumpCommands);
|
||||
|
||||
// Query for the Executable Path using OS specific functions
|
||||
CalculateExecutablePath();
|
||||
|
||||
// Determine the path to the engine
|
||||
CalculateEngineRoot();
|
||||
|
||||
// If the current platform returns an engaged optional from Utils::GetDefaultAppRootPath(), that is used
|
||||
// for the application root.
|
||||
CalculateAppRoot();
|
||||
|
||||
SettingsRegistryMergeUtils::MergeSettingsToRegistry_O3deUserRegistry(*m_settingsRegistry, AZ_TRAIT_OS_PLATFORM_CODENAME, {});
|
||||
SettingsRegistryMergeUtils::MergeSettingsToRegistry_CommandLine(*m_settingsRegistry, m_commandLine, executeRegDumpCommands);
|
||||
SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*m_settingsRegistry);
|
||||
@@ -614,7 +604,8 @@ namespace AZ
|
||||
{
|
||||
AZ_Assert(!m_isStarted, "Component application already started!");
|
||||
|
||||
if (m_engineRoot.empty())
|
||||
using Type = AZ::SettingsRegistryInterface::Type;
|
||||
if (m_settingsRegistry->GetType(SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder) == Type::NoType)
|
||||
{
|
||||
ReportBadEngineRoot();
|
||||
return nullptr;
|
||||
@@ -1180,6 +1171,24 @@ namespace AZ
|
||||
return ReflectionEnvironment::GetReflectionManager() ? ReflectionEnvironment::GetReflectionManager()->GetReflectContext<JsonRegistrationContext>() : nullptr;
|
||||
}
|
||||
|
||||
/// Returns the path to the engine.
|
||||
|
||||
const char* ComponentApplication::GetEngineRoot() const
|
||||
{
|
||||
static IO::FixedMaxPathString engineRoot;
|
||||
engineRoot.clear();
|
||||
m_settingsRegistry->Get(engineRoot, SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder);
|
||||
return engineRoot.c_str();
|
||||
}
|
||||
|
||||
const char* ComponentApplication::GetExecutableFolder() const
|
||||
{
|
||||
static IO::FixedMaxPathString exeFolder;
|
||||
exeFolder.clear();
|
||||
m_settingsRegistry->Get(exeFolder, SettingsRegistryMergeUtils::FilePathKey_BinaryFolder);
|
||||
return exeFolder.c_str();
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// CreateReflectionManager
|
||||
//=========================================================================
|
||||
@@ -1485,27 +1494,6 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// CalculateExecutablePath
|
||||
//=========================================================================
|
||||
void ComponentApplication::CalculateExecutablePath()
|
||||
{
|
||||
m_exeDirectory = Utils::GetExecutableDirectory();
|
||||
}
|
||||
|
||||
void ComponentApplication::CalculateAppRoot()
|
||||
{
|
||||
if (AZStd::optional<AZ::StringFunc::Path::FixedString> appRootPath = Utils::GetDefaultAppRootPath(); appRootPath)
|
||||
{
|
||||
m_appRoot = AZStd::move(*appRootPath);
|
||||
}
|
||||
}
|
||||
|
||||
void ComponentApplication::CalculateEngineRoot()
|
||||
{
|
||||
m_engineRoot = AZ::SettingsRegistryMergeUtils::FindEngineRoot(*m_settingsRegistry).Native();
|
||||
}
|
||||
|
||||
void ComponentApplication::ResolveModulePath([[maybe_unused]] AZ::OSString& modulePath)
|
||||
{
|
||||
// No special parsing of the Module Path is done by the Component Application anymore
|
||||
|
||||
@@ -221,13 +221,10 @@ namespace AZ
|
||||
BehaviorContext* GetBehaviorContext() override;
|
||||
/// Returns the json registration context that has been registered with the app, if there is one.
|
||||
JsonRegistrationContext* GetJsonRegistrationContext() override;
|
||||
/// Returns the working root folder that has been registered with the app, if there is one.
|
||||
/// It's expected that derived applications will implement an application root.
|
||||
const char* GetAppRoot() const override { return m_appRoot.c_str(); }
|
||||
/// Returns the path to the engine.
|
||||
const char* GetEngineRoot() const override { return m_engineRoot.c_str(); }
|
||||
const char* GetEngineRoot() const override;
|
||||
/// Returns the path to the folder the executable is in.
|
||||
const char* GetExecutableFolder() const override { return m_exeDirectory.c_str(); }
|
||||
const char* GetExecutableFolder() const override;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// TickRequestBus
|
||||
@@ -352,15 +349,6 @@ namespace AZ
|
||||
/// Adds system components requested by modules and the application to the system entity.
|
||||
void AddRequiredSystemComponents(AZ::Entity* systemEntity);
|
||||
|
||||
/// Calculates the directory the application executable comes from.
|
||||
void CalculateExecutablePath();
|
||||
|
||||
/// Calculates the root directory of the engine.
|
||||
void CalculateEngineRoot();
|
||||
|
||||
/// Deprecated: The term "AppRoot" has no meaning
|
||||
void CalculateAppRoot();
|
||||
|
||||
template<typename Iterator>
|
||||
static void NormalizePath(Iterator begin, Iterator end, bool doLowercase = true)
|
||||
{
|
||||
@@ -388,9 +376,6 @@ namespace AZ
|
||||
void* m_fixedMemoryBlock{ nullptr }; //!< Pointer to the memory block allocator, so we can free it OnDestroy.
|
||||
IAllocatorAllocate* m_osAllocator{ nullptr };
|
||||
EntitySetType m_entities;
|
||||
AZ::IO::FixedMaxPath m_exeDirectory;
|
||||
AZ::IO::FixedMaxPath m_engineRoot;
|
||||
AZ::IO::FixedMaxPath m_appRoot;
|
||||
|
||||
AZ::SettingsRegistryInterface::NotifyEventHandler m_projectPathChangedHandler;
|
||||
AZ::SettingsRegistryInterface::NotifyEventHandler m_projectNameChangedHandler;
|
||||
|
||||
@@ -175,10 +175,6 @@ namespace AZ
|
||||
//! the serializers used by the best-effort json serialization.
|
||||
virtual class JsonRegistrationContext* GetJsonRegistrationContext() = 0;
|
||||
|
||||
//! Gets the name of the working root folder that was registered with the app.
|
||||
//! @return a pointer to the name of the app's root folder, if a root folder was registered.
|
||||
virtual const char* GetAppRoot() const = 0;
|
||||
|
||||
//! Gets the path of the working engine folder that the app is a part of.
|
||||
//! @return a pointer to the engine path.
|
||||
virtual const char* GetEngineRoot() const = 0;
|
||||
|
||||
@@ -266,7 +266,8 @@ namespace AZ::SettingsRegistryMergeUtils
|
||||
|
||||
// Step 3 locate the project root and attempt to find the engine root using the registered engine
|
||||
// for the project in the project.json file
|
||||
AZ::IO::FixedMaxPath projectRoot = FindProjectRoot(settingsRegistry);
|
||||
AZ::IO::FixedMaxPath projectRoot;
|
||||
settingsRegistry.Get(projectRoot.Native(), FilePathKey_ProjectPath);
|
||||
if (projectRoot.empty())
|
||||
{
|
||||
return {};
|
||||
@@ -693,6 +694,7 @@ namespace AZ::SettingsRegistryMergeUtils
|
||||
R"(Project path isn't set in the Settings Registry at "%.*s".)"
|
||||
" Project-related filepaths will be set relative to the executable directory\n",
|
||||
AZ_STRING_ARG(projectPathKey));
|
||||
projectPath = exePath;
|
||||
registry.Set(FilePathKey_ProjectPath, exePath.Native());
|
||||
}
|
||||
|
||||
|
||||
@@ -1427,26 +1427,36 @@ namespace AZ
|
||||
|
||||
namespace AssetPath
|
||||
{
|
||||
void CalculateBranchToken(const AZStd::string& appRootPath, AZStd::string& token)
|
||||
namespace Internal
|
||||
{
|
||||
// Normalize the token to prepare for CRC32 calculation
|
||||
AZStd::string normalized = appRootPath;
|
||||
AZ::u32 CalculateBranchTokenHash(AZStd::string_view engineRootPath)
|
||||
{
|
||||
// Normalize the token to prepare for CRC32 calculation
|
||||
auto NormalizeEnginePath = [](const char element) -> char
|
||||
{
|
||||
// Substitute path separators with '_' and lower case
|
||||
return element == AZ::IO::WindowsPathSeparator || element == AZ::IO::PosixPathSeparator
|
||||
? '_' : static_cast<char>(std::tolower(element));
|
||||
};
|
||||
|
||||
// Strip out any trailing path separators
|
||||
AZ::StringFunc::Strip(normalized, AZ_CORRECT_FILESYSTEM_SEPARATOR_STRING AZ_WRONG_FILESYSTEM_SEPARATOR_STRING,false, false, true);
|
||||
// Trim off trailing path separators
|
||||
engineRootPath = RStrip(engineRootPath, AZ_CORRECT_AND_WRONG_FILESYSTEM_SEPARATOR);
|
||||
AZ::IO::FixedMaxPathString enginePath;
|
||||
AZStd::transform(engineRootPath.begin(), engineRootPath.end(),
|
||||
AZStd::back_inserter(enginePath), AZStd::move(NormalizeEnginePath));
|
||||
|
||||
// Lower case always
|
||||
AZStd::to_lower(normalized.begin(), normalized.end());
|
||||
|
||||
// Substitute path separators with '_'
|
||||
AZStd::replace(normalized.begin(), normalized.end(), '\\', '_');
|
||||
AZStd::replace(normalized.begin(), normalized.end(), '/', '_');
|
||||
|
||||
// Perform the CRC32 calculation
|
||||
const AZ::Crc32 branchTokenCrc(normalized.c_str(), normalized.size(), true);
|
||||
char branchToken[12];
|
||||
azsnprintf(branchToken, AZ_ARRAY_SIZE(branchToken), "0x%08X", static_cast<AZ::u32>(branchTokenCrc));
|
||||
token = AZStd::string(branchToken);
|
||||
// Perform the CRC32 calculation
|
||||
constexpr bool forceLowercase = true;
|
||||
return static_cast<AZ::u32>(AZ::Crc32(enginePath.c_str(), enginePath.size(), forceLowercase));
|
||||
}
|
||||
}
|
||||
void CalculateBranchToken(AZStd::string_view engineRootPath, AZStd::string& token)
|
||||
{
|
||||
token = AZStd::string::format("0x%08X", Internal::CalculateBranchTokenHash(engineRootPath));
|
||||
}
|
||||
void CalculateBranchToken(AZStd::string_view engineRootPath, AZ::IO::FixedMaxPathString& token)
|
||||
{
|
||||
token = AZ::IO::FixedMaxPathString::format("0x%08X", Internal::CalculateBranchTokenHash(engineRootPath));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -485,10 +485,11 @@ namespace AZ
|
||||
//! CalculateBranchToken
|
||||
/*! Calculate the branch token that is used for asset processor connection negotiations
|
||||
*
|
||||
* \param appRootPath - The absolute path of the app root to base the token calculation on
|
||||
* \param engineRootPath - The absolute path to the engine root to base the token calculation on
|
||||
* \param token - The result of the branch token calculation
|
||||
*/
|
||||
void CalculateBranchToken(const AZStd::string& appRootPath, AZStd::string& token);
|
||||
void CalculateBranchToken(AZStd::string_view engineRootPath, AZStd::string& token);
|
||||
void CalculateBranchToken(AZStd::string_view engineRootPath, AZ::IO::FixedMaxPathString& token);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -41,7 +41,6 @@ namespace UnitTest
|
||||
MOCK_METHOD0(GetSerializeContext, AZ::SerializeContext* ());
|
||||
MOCK_METHOD0(GetJsonRegistrationContext, AZ::JsonRegistrationContext* ());
|
||||
MOCK_METHOD0(GetBehaviorContext, AZ::BehaviorContext* ());
|
||||
MOCK_CONST_METHOD0(GetAppRoot, const char* ());
|
||||
MOCK_CONST_METHOD0(GetEngineRoot, const char* ());
|
||||
MOCK_CONST_METHOD0(GetExecutableFolder, const char* ());
|
||||
MOCK_CONST_METHOD1(QueryApplicationType, void(AZ::ApplicationTypeQuery&));
|
||||
|
||||
Reference in New Issue
Block a user