O3DE.exe Project-Centric "Open Editor" fix (#5852)

* The O3DE.exe Open Editor button now attempts to open the Editor in the
build directory of the project being opened.

If their is no Editor within the build directory of the Project, it uses
the Editor.exe in the current O3DE.exe executable directory if it exists

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Engine .gitignore now ignores the build directory if placed in the
AutomatedTesting project

Previously it was just ignoring a `[Bb]uild` directory if it was
directly within the engine root.
This change matches the behavior of the project templates.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Renamed the ProjectUtils GetEditorDirectory function to
GetEditorExecutablePath

Added a platform specific implementation for retrieving the path to the
Editor executable in the GetEditorExectuablePath function.

It first attempts to locate the Editor via checking the project build
directory for an Editor executable before falling back to checking the
binary directory of the currently running O3DE executable.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Correct the MacOS GetEditorExecutablePath to return the Editor path

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
This commit is contained in:
lumberyard-employee-dm
2021-11-23 18:25:00 -06:00
committed by GitHub
parent 4ac8b5dc42
commit 99d0c39273
7 changed files with 201 additions and 39 deletions
@@ -1,6 +1,6 @@
/*
* 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
*
*/
@@ -15,6 +15,8 @@
#include <QProcessEnvironment>
#include <QStandardPaths>
#include <AzCore/Settings/SettingsRegistryImpl.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/Utils/Utils.h>
namespace O3DE::ProjectManager
@@ -27,7 +29,7 @@ namespace O3DE::ProjectManager
auto engineInfoResult = PythonBindingsInterface::Get()->GetEngineInfo();
if (!engineInfoResult.IsSuccess())
{
return AZ::Failure(QObject::tr("Failed to get engine info"));
return AZ::Failure(QObject::tr("Failed to get engine info"));
}
auto engineInfo = engineInfoResult.GetValue();
@@ -52,7 +54,7 @@ namespace O3DE::ProjectManager
AZ::Outcome<QString, QString> FindSupportedCompilerForPlatform()
{
// Validate that cmake is installed
// Validate that cmake is installed
auto cmakeProcessEnvResult = SetupCommandLineProcessEnvironment();
if (!cmakeProcessEnvResult.IsSuccess())
{
@@ -109,7 +111,7 @@ namespace O3DE::ProjectManager
" or update to a newer version before proceeding to the next step."
" While installing configure Visual Studio with these <a href='https://o3de.org/docs/welcome-guide/setup/requirements/#visual-studio-configuration'>workloads</a>."));
}
AZ::Outcome<void, QString> OpenCMakeGUI(const QString& projectPath)
{
AZ::Outcome processEnvResult = SetupCommandLineProcessEnvironment();
@@ -127,7 +129,7 @@ namespace O3DE::ProjectManager
QProcess process;
// if the project build path is relative, it should be relative to the project path
// if the project build path is relative, it should be relative to the project path
process.setWorkingDirectory(projectPath);
process.setProgram("cmake-gui");
@@ -149,9 +151,53 @@ namespace O3DE::ProjectManager
QObject::tr("Running get_python script..."));
}
AZ::IO::FixedMaxPath GetEditorDirectory()
AZ::IO::FixedMaxPath GetEditorExecutablePath(const AZ::IO::PathView& projectPath)
{
return AZ::Utils::GetExecutableDirectory();
AZ::IO::FixedMaxPath editorPath;
AZ::IO::FixedMaxPath fixedProjectPath{ projectPath };
// First attempt to launch the Editor.exe within the project build directory if it exists
AZ::IO::FixedMaxPath buildPathSetregPath = fixedProjectPath
/ AZ::SettingsRegistryInterface::DevUserRegistryFolder
/ "Platform" / AZ_TRAIT_OS_PLATFORM_CODENAME / "build_path.setreg";
if (AZ::IO::SystemFile::Exists(buildPathSetregPath.c_str()))
{
AZ::SettingsRegistryImpl settingsRegistry;
// Merge the build_path.setreg into the local SettingsRegistry instance
if (AZ::IO::FixedMaxPath projectBuildPath;
settingsRegistry.MergeSettingsFile(buildPathSetregPath.Native(),
AZ::SettingsRegistryInterface::Format::JsonMergePatch)
&& settingsRegistry.Get(projectBuildPath.Native(), AZ::SettingsRegistryMergeUtils::ProjectBuildPath))
{
// local Settings Registry will be used to merge the build_path.setreg for the supplied projectPath
AZ::IO::FixedMaxPath buildConfigurationPath = (fixedProjectPath / projectBuildPath).LexicallyNormal();
// First try <project-build-path>/bin/$<CONFIG> and if that path doesn't exist
// try <project-build-path>/bin/$<PLATFORM>/$<CONFIG>
buildConfigurationPath /= "bin";
if (editorPath = (buildConfigurationPath / AZ_BUILD_CONFIGURATION_TYPE / "Editor").
ReplaceExtension(AZ_TRAIT_OS_EXECUTABLE_EXTENSION);
AZ::IO::SystemFile::Exists(editorPath.c_str()))
{
return editorPath;
}
else if (editorPath = (buildConfigurationPath / AZ_TRAIT_OS_PLATFORM_CODENAME
/ AZ_BUILD_CONFIGURATION_TYPE / "Editor").
ReplaceExtension(AZ_TRAIT_OS_EXECUTABLE_EXTENSION);
AZ::IO::SystemFile::Exists(editorPath.c_str()))
{
return editorPath;
}
}
}
// Fall back to checking if an Editor exists in O3DE executable directory
editorPath = AZ::IO::FixedMaxPath(AZ::Utils::GetExecutableDirectory()) / "Editor";
editorPath.ReplaceExtension(AZ_TRAIT_OS_EXECUTABLE_EXTENSION);
if (AZ::IO::SystemFile::Exists(editorPath.c_str()))
{
return editorPath;
}
return {};
}
AZ::Outcome<QString, QString> CreateDesktopShortcut(const QString& filename, const QString& targetPath, const QStringList& arguments)