@ -85,6 +85,16 @@ namespace AZ::Internal
[[maybe_unused]] AZ : : SettingsRegistryInterface : : Type type , AZStd : : string_view value ) override
{
m_enginePaths . emplace_back ( EngineInfo { AZ : : IO : : FixedMaxPath { value } . LexicallyNormal ( ) , FixedValueString { valueName } } ) ;
// Make sure any engine paths read from the manifest are absolute
AZ : : IO : : FixedMaxPath & recentEnginePath = m_enginePaths . back ( ) . m_path ;
if ( recentEnginePath . IsRelative ( ) )
{
if ( auto engineRootAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( recentEnginePath . Native ( ) ) ;
engineRootAbsPath . has_value ( ) )
{
recentEnginePath = AZStd : : move ( * engineRootAbsPath ) ;
}
}
}
AZStd : : vector < EngineInfo > m_enginePaths { } ;
@ -209,8 +219,15 @@ namespace AZ::Internal
return { } ;
}
void InjectSettingToCommandLineBack ( AZ : : SettingsRegistryInterface & settingsRegistry ,
AZStd : : string_view path , AZStd : : string_view value )
enum class InjectLocation : bool
{
Front ,
Back
} ;
void InjectSettingToCommandLine ( AZ : : SettingsRegistryInterface & settingsRegistry ,
AZStd : : string_view path , AZStd : : string_view value ,
InjectLocation injectLocation = InjectLocation : : Front )
{
AZ : : CommandLine commandLine ;
AZ : : SettingsRegistryMergeUtils : : GetCommandLineFromRegistry ( settingsRegistry , commandLine ) ;
@ -219,7 +236,8 @@ namespace AZ::Internal
auto projectPathOverride = AZStd : : string : : format ( R " (--regset= " % . * s = % . * s " ) " ,
aznumeric_cast < int > ( path . size ( ) ) , path . data ( ) , aznumeric_cast < int > ( value . size ( ) ) , value . data ( ) ) ;
paramContainer . emplace ( paramContainer . end ( ) , AZStd : : move ( projectPathOverride ) ) ;
auto emplaceIter = injectLocation = = InjectLocation : : Front ? paramContainer . begin ( ) : paramContainer . end ( ) ;
paramContainer . emplace ( emplaceIter , AZStd : : move ( projectPathOverride ) ) ;
commandLine . Parse ( paramContainer ) ;
AZ : : SettingsRegistryMergeUtils : : StoreCommandLineToRegistry ( settingsRegistry , commandLine ) ;
}
@ -244,13 +262,26 @@ namespace AZ::SettingsRegistryMergeUtils
{
// We can scan up from exe directory to find engine.json, use that for engine root if it exists.
engineRoot = Internal : : ScanUpRootLocator ( " engine.json " ) ;
// The Internal ScanUp Engine Root Key will be set as an absolute path
if ( ! engineRoot . empty ( ) )
{
if ( engineRoot . IsRelative ( ) )
{
if ( auto engineRootAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( engineRoot . Native ( ) ) ;
engineRootAbsPath . has_value ( ) )
{
engineRoot = AZStd : : move ( * engineRootAbsPath ) ;
}
}
}
// Set the {InternalScanUpEngineRootKey} to make sure this code path isn't called again for this settings registry
settingsRegistry . Set ( InternalScanUpEngineRootKey , engineRoot . Native ( ) ) ;
if ( ! engineRoot . empty ( ) )
{
settingsRegistry . Set ( engineRootKey , engineRoot . Native ( ) ) ;
// Inject the engine root at the end of the command line settings
Internal : : InjectSettingToCommandLineBack ( settingsRegistry , engineRootKey , engineRoot . Native ( ) ) ;
// Inject the engine root to the front of the command line settings
Internal : : InjectSettingToCommandLine ( settingsRegistry , engineRootKey , engineRoot . Native ( ) ) ;
return engineRoot ;
}
}
@ -258,6 +289,14 @@ namespace AZ::SettingsRegistryMergeUtils
// Step 2 check if the engine_path key has been supplied
if ( settingsRegistry . Get ( engineRoot . Native ( ) , engineRootKey ) ; ! engineRoot . empty ( ) )
{
if ( engineRoot . IsRelative ( ) )
{
if ( auto engineRootAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( engineRoot . Native ( ) ) ;
engineRootAbsPath . has_value ( ) )
{
engineRoot = AZStd : : move ( * engineRootAbsPath ) ;
}
}
return engineRoot ;
}
@ -298,13 +337,28 @@ namespace AZ::SettingsRegistryMergeUtils
if ( settingsRegistry . GetType ( InternalScanUpProjectRootKey ) = = Type : : NoType )
{
projectRoot = Internal : : ScanUpRootLocator ( " project.json " ) ;
// Convert the path to an absolute path before adding it as a setting to the
// InternalScanUpProjectRootKey
if ( ! projectRoot . empty ( ) )
{
if ( projectRoot . IsRelative ( ) )
{
if ( auto projectAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( projectRoot . Native ( ) ) ;
projectAbsPath . has_value ( ) )
{
projectRoot = AZStd : : move ( * projectAbsPath ) ;
}
}
}
// Set the {InternalScanUpProjectRootKey} to make sure this code path isn't called again for this settings registry
settingsRegistry . Set ( InternalScanUpProjectRootKey , projectRoot . Native ( ) ) ;
if ( ! projectRoot . empty ( ) )
{
settingsRegistry . Set ( projectRootKey , projectRoot . c_str ( ) ) ;
// Inject the project root at the end of the command line settings
Internal : : InjectSettingToCommandLineBack ( settingsRegistry , projectRootKey , projectRoot . Native ( ) ) ;
// Inject the project root at to the front of the command line settings
Internal : : InjectSettingToCommandLine ( settingsRegistry , projectRootKey , projectRoot . Native ( ) ) ;
return projectRoot ;
}
}
@ -312,6 +366,18 @@ namespace AZ::SettingsRegistryMergeUtils
// Step 2 Check the project-path key
// This is the project path root key, as passed from command-line or *.setreg files.
settingsRegistry . Get ( projectRoot . Native ( ) , projectRootKey ) ;
if ( ! projectRoot . empty ( ) )
{
if ( projectRoot . IsRelative ( ) )
{
if ( auto projectAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( projectRoot . Native ( ) ) ;
projectAbsPath . has_value ( ) )
{
projectRoot = AZStd : : move ( * projectAbsPath ) ;
}
}
}
return projectRoot ;
}
@ -325,13 +391,22 @@ namespace AZ::SettingsRegistryMergeUtils
constexpr auto projectCachePathKey = FixedValueString ( BootstrapSettingsRootKey ) + " /project_cache_path " ;
// Step 1 Check the project-cache-path key
if ( AZ : : IO : : FixedMaxPath projectCachePath ; settingsRegistry . Get ( projectCachePath . Native ( ) , projectCachePathKey ) )
AZ : : IO : : FixedMaxPath projectCachePath ;
if ( ! settingsRegistry . Get ( projectCachePath . Native ( ) , projectCachePathKey ) )
{
return projectCachePath ;
// Step 2 Append the "Cache" directory to the project-path
projectCachePath = projectPath / Internal : : ProductCacheDirectoryName ;
}
// Step 2 Append the "Cache" directory to the project-path
return projectPath / Internal : : ProductCacheDirectoryName ;
if ( projectCachePath . IsRelative ( ) )
{
if ( auto projectCacheAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( projectCachePath . Native ( ) ) ;
projectCacheAbsPath . has_value ( ) )
{
projectCachePath = AZStd : : move ( * projectCacheAbsPath ) ;
}
}
return projectCachePath ;
}
//! Set the user directory with the provided path or using <project-path>/user as default
@ -344,13 +419,22 @@ namespace AZ::SettingsRegistryMergeUtils
constexpr auto projectUserPathKey = FixedValueString ( BootstrapSettingsRootKey ) + " /project_user_path " ;
// Step 1 Check the project-user-path key
if ( AZ : : IO : : FixedMaxPath projectUserPath ; settingsRegistry . Get ( projectUserPath . Native ( ) , projectUserPathKey ) )
AZ : : IO : : FixedMaxPath projectUserPath ;
if ( ! settingsRegistry . Get ( projectUserPath . Native ( ) , projectUserPathKey ) )
{
return projectUserPath ;
// Step 2 Append the "User" directory to the project-path
projectUserPath = projectPath / " user " ;
}
// Step 2 Append the "User" directory to the project-path
return projectPath / " user " ;
if ( projectUserPath . IsRelative ( ) )
{
if ( auto projectUserAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( projectUserPath . Native ( ) ) ;
projectUserAbsPath . has_value ( ) )
{
projectUserPath = AZStd : : move ( * projectUserAbsPath ) ;
}
}
return projectUserPath ;
}
//! Set the log directory using the settings registry path or using <project-user-path>/log as default
@ -363,20 +447,37 @@ namespace AZ::SettingsRegistryMergeUtils
constexpr auto projectLogPathKey = FixedValueString ( BootstrapSettingsRootKey ) + " /project_log_path " ;
// Step 1 Check the project-user-path key
if ( AZ : : IO : : FixedMaxPath projectLogPath ; settingsRegistry . Get ( projectLogPath . Native ( ) , projectLogPathKey ) )
AZ : : IO : : FixedMaxPath projectLogPath ;
if ( ! settingsRegistry . Get ( projectLogPath . Native ( ) , projectLogPathKey ) )
{
// Step 2 Append the "Log" directory to the project-user-path
projectLogPath = projectUserPath / " log " ;
}
if ( projectLogPath . IsRelative ( ) )
{
return projectLogPath ;
if ( auto projectLogAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( projectLogPath . Native ( ) ) )
{
projectLogPath = AZStd : : move ( * projectLogAbsPath ) ;
}
}
// Step 2 Append the "Log" directory to the project-user-path
return projectUserPath / " log " ;
return projectLogPath ;
}
// check for a default write storage path, fall back to the <project-user-path> if not
static AZ : : IO : : FixedMaxPath FindDevWriteStoragePath ( const AZ : : IO : : FixedMaxPath & projectUserPath )
{
AZStd : : optional < AZ : : IO : : FixedMaxPathString > devWriteStorage = Utils : : GetDevWriteStoragePath ( ) ;
return devWriteStorage . has_value ( ) ? * devWriteStorage : projectUserPath ;
AZ : : IO : : FixedMaxPath devWriteStoragePath = devWriteStorage . has_value ( ) ? * devWriteStorage : projectUserPath ;
if ( devWriteStoragePath . IsRelative ( ) )
{
if ( auto devWriteStorageAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( devWriteStoragePath . Native ( ) ) )
{
devWriteStoragePath = AZStd : : move ( * devWriteStorageAbsPath ) ;
}
}
return devWriteStoragePath ;
}
// check for the project build path, which is a relative path from the project root
@ -669,15 +770,6 @@ namespace AZ::SettingsRegistryMergeUtils
if ( [[maybe_unused]] constexpr auto projectPathKey = FixedValueString ( BootstrapSettingsRootKey ) + " /project_path " ;
! projectPath . empty ( ) )
{
if ( projectPath . IsRelative ( ) )
{
if ( auto projectAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( projectPath . Native ( ) ) ;
projectAbsPath . has_value ( ) )
{
projectPath = AZStd : : move ( * projectAbsPath ) ;
}
}
projectPath = projectPath . LexicallyNormal ( ) ;
AZ_Warning ( " SettingsRegistryMergeUtils " , AZ : : IO : : SystemFile : : Exists ( projectPath . c_str ( ) ) ,
R " (Project path " % s " does not exist. Is the " % . * s " registry setting set to a valid absolute path?) "
@ -699,15 +791,6 @@ namespace AZ::SettingsRegistryMergeUtils
AZ : : IO : : FixedMaxPath engineRoot = FindEngineRoot ( registry ) ;
if ( ! engineRoot . empty ( ) )
{
if ( engineRoot . IsRelative ( ) )
{
if ( auto engineRootAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( engineRoot . Native ( ) ) ;
engineRootAbsPath . has_value ( ) )
{
engineRoot = AZStd : : move ( * engineRootAbsPath ) ;
}
}
engineRoot = engineRoot . LexicallyNormal ( ) ;
registry . Set ( FilePathKey_EngineRootFolder , engineRoot . Native ( ) ) ;
}
@ -716,15 +799,6 @@ namespace AZ::SettingsRegistryMergeUtils
AZ : : IO : : FixedMaxPath projectCachePath = FindProjectCachePath ( registry , projectPath ) . LexicallyNormal ( ) ;
if ( ! projectCachePath . empty ( ) )
{
if ( projectCachePath . IsRelative ( ) )
{
if ( auto projectCacheAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( projectCachePath . Native ( ) ) ;
projectCacheAbsPath . has_value ( ) )
{
projectCachePath = AZStd : : move ( * projectCacheAbsPath ) ;
}
}
projectCachePath = projectCachePath . LexicallyNormal ( ) ;
registry . Set ( FilePathKey_CacheProjectRootFolder , projectCachePath . Native ( ) ) ;
@ -755,15 +829,6 @@ namespace AZ::SettingsRegistryMergeUtils
AZ : : IO : : FixedMaxPath projectUserPath = FindProjectUserPath ( registry , projectPath ) ;
if ( ! projectUserPath . empty ( ) )
{
if ( projectUserPath . IsRelative ( ) )
{
if ( auto projectUserAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( projectUserPath . Native ( ) ) ;
projectUserAbsPath . has_value ( ) )
{
projectUserPath = AZStd : : move ( * projectUserAbsPath ) ;
}
}
projectUserPath = projectUserPath . LexicallyNormal ( ) ;
registry . Set ( FilePathKey_ProjectUserPath , projectUserPath . Native ( ) ) ;
}
@ -771,14 +836,6 @@ namespace AZ::SettingsRegistryMergeUtils
// Log folder
if ( AZ : : IO : : FixedMaxPath projectLogPath = FindProjectLogPath ( registry , projectUserPath ) ; ! projectLogPath . empty ( ) )
{
if ( projectLogPath . IsRelative ( ) )
{
if ( auto projectLogAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( projectLogPath . Native ( ) ) )
{
projectLogPath = AZStd : : move ( * projectLogAbsPath ) ;
}
}
projectLogPath = projectLogPath . LexicallyNormal ( ) ;
registry . Set ( FilePathKey_ProjectLogPath , projectLogPath . Native ( ) ) ;
}
@ -786,14 +843,6 @@ namespace AZ::SettingsRegistryMergeUtils
// Developer Write Storage folder
if ( AZ : : IO : : FixedMaxPath devWriteStoragePath = FindDevWriteStoragePath ( projectUserPath ) ; ! devWriteStoragePath . empty ( ) )
{
if ( devWriteStoragePath . IsRelative ( ) )
{
if ( auto devWriteStorageAbsPath = AZ : : Utils : : ConvertToAbsolutePath ( devWriteStoragePath . Native ( ) ) )
{
devWriteStoragePath = AZStd : : move ( * devWriteStorageAbsPath ) ;
}
}
devWriteStoragePath = devWriteStoragePath . LexicallyNormal ( ) ;
registry . Set ( FilePathKey_DevWriteStorage , devWriteStoragePath . Native ( ) ) ;
}