Skip to content

Commit

Permalink
fix Mac editor plugin path (o3de#16849)
Browse files Browse the repository at this point in the history
* fix Mac editor plugin path

Signed-off-by: Alex Peterson <[email protected]>

* use GetPathToApplicationBundle helper

Signed-off-by: Alex Peterson <[email protected]>

* Remove redundant logic

Signed-off-by: Alex Peterson <[email protected]>

* added missing 'EditorPlugins' subdirectory to path

Signed-off-by: Alex Peterson <[email protected]>

* simplify plugin path logic

turns out the plugin path mask isn't actually used

Signed-off-by: Alex Peterson <[email protected]>

---------

Signed-off-by: Alex Peterson <[email protected]>
  • Loading branch information
AMZN-alexpete authored Oct 16, 2023
1 parent 66925b3 commit 8c3d719
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
38 changes: 22 additions & 16 deletions Code/Editor/IEditorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/Utils/Utils.h>

#if defined(AZ_PLATFORM_MAC)
#include <AzCore/Utils/SystemUtilsApple_Platform.h>
#endif

// AzFramework
#include <AzFramework/Terrain/TerrainDataRequestBus.h>

Expand Down Expand Up @@ -229,30 +233,32 @@ void CEditorImpl::LoadPlugins()
{
AZStd::scoped_lock lock(m_pluginMutex);

static const QString editor_plugins_folder("EditorPlugins");

// Build, verify, and set the engine root's editor plugin folder
QString editorPluginPathStr;
constexpr const char* editorPluginFolder = "EditorPlugins";

AZStd::string_view exeFolder;
AZ::ComponentApplicationBus::BroadcastResult(exeFolder, &AZ::ComponentApplicationRequests::GetExecutableFolder);
AZ::IO::FixedMaxPath pluginsPath;

QDir testDir;
testDir.setPath(AZStd::string(exeFolder).c_str());
if (testDir.exists() && testDir.cd(editor_plugins_folder))
#if defined(AZ_PLATFORM_MAC)
char maxPathBuffer[AZ::IO::MaxPathLength];
if (auto appBundlePathOutcome = AZ::SystemUtilsApple::GetPathToApplicationBundle(maxPathBuffer);
appBundlePathOutcome)
{
editorPluginPathStr = testDir.absolutePath();
AZ::IO::FixedMaxPath bundleRootDirectory = appBundlePathOutcome.GetValue();

// the bundle directory includes Editor.app so we want the parent directory
bundleRootDirectory = (bundleRootDirectory / "..").LexicallyNormal();
pluginsPath = bundleRootDirectory / editorPluginFolder;
}
#endif

// If no editor plugin path was found based on the root engine path, then fallback to the current editor.exe path
if (editorPluginPathStr.isEmpty())
if (pluginsPath.empty())
{
editorPluginPathStr = QString("%1/%2").arg(qApp->applicationDirPath(), editor_plugins_folder);
// Use the executable directory as the starting point for the EditorPlugins path
AZ::IO::FixedMaxPath executableDirectory = AZ::Utils::GetExecutableDirectory();
pluginsPath = executableDirectory / editorPluginFolder;
}

QString pluginSearchPath = QDir::toNativeSeparators(QString("%1/*" AZ_DYNAMIC_LIBRARY_EXTENSION).arg(editorPluginPathStr));

GetPluginManager()->LoadPlugins(pluginSearchPath.toUtf8().data());
// error handling for invalid paths is handled in LoadPlugins
GetPluginManager()->LoadPlugins(pluginsPath.c_str());
}

CEditorImpl::~CEditorImpl()
Expand Down
5 changes: 2 additions & 3 deletions Code/Editor/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ namespace
}
}

bool CPluginManager::LoadPlugins(const char* pPathWithMask)
bool CPluginManager::LoadPlugins(const char* pluginsPath)
{
QString strPath = PathUtil::GetPath(pPathWithMask).c_str();
QString strMask = PathUtil::GetFile(pPathWithMask);
QString strPath{ pluginsPath };

CLogFile::WriteLine("[Plugin Manager] Loading plugins...");

Expand Down
2 changes: 1 addition & 1 deletion Code/Editor/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SANDBOX_API CPluginManager
CPluginManager();
virtual ~CPluginManager();

bool LoadPlugins(const char* pPathWithMask);
bool LoadPlugins(const char* pluginsPath);

// release all plugins (ie, call Release() on them) - but don't drop their DLL
void ReleaseAllPlugins();
Expand Down

0 comments on commit 8c3d719

Please sign in to comment.