Enable Resource Mapping Tool on Linux (#5779)

* Enable and fix AWS Resource Mapping Tool on Linux
- Enable the trait AWSCORE_EDITOR_RESOURCE_MAPPING_TOOL_ENABLED for Linux
- Add additional traits to handle launching o3de local python on Linux
- Update the resource_mapping_tool.py to support preloading the shared libraries for Pyside (like the QtForPython gem) in order to resolve the local pyside2 libraries

Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>

* Update pyside2 to a RUNTIME dependency

Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>

* Update special linux preloading comments for clarity

Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>

* Add CR at the end of traits files

Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>

* - Remove unnecessary extra argument '--executable-path' and use '--binaries-path' instead
- Add linux only loading of pyside modules to 'setup_qt_environment' instead
- Update README.md

Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>

* Updated unit tests for test_environment_utils.py

Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>

* Fix indentation for Linux specific logic in environment_utils.py

Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>

* Fix (more) indentation for Linux specific logic in environment_utils.py

Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>

* Replace exit with return in setup_qt_environment

Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>
monroegm-disable-blank-issue-2
Steve Pham 4 years ago committed by GitHub
parent af85060856
commit 3cf3e45b38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -111,6 +111,9 @@ if (PAL_TRAIT_BUILD_HOST_TOOLS)
BUILD_DEPENDENCIES
PRIVATE
Gem::AWSCore.Editor.Static
RUNTIME_DEPENDENCIES
3rdParty::pyside2
)
ly_add_dependencies(AWSCore.Editor AWSCore.ResourceMappingTool)

@ -13,6 +13,8 @@
#include <QAction>
#include <QObject>
#include "AWSCoreEditor_Traits_Platform.h"
namespace AWSCore
{
class AWSCoreResourceMappingToolAction
@ -22,7 +24,7 @@ namespace AWSCore
static constexpr const char AWSCoreResourceMappingToolActionName[] = "AWSCoreResourceMappingToolAction";
static constexpr const char ResourceMappingToolDirectoryPath[] = "Gems/AWSCore/Code/Tools/ResourceMappingTool";
static constexpr const char ResourceMappingToolLogDirectoryPath[] = "user/log/";
static constexpr const char EngineWindowsPythonEntryScriptPath[] = "python/python.cmd";
static constexpr const char EngineWindowsPythonEntryScriptPath[] = AWSCORE_EDITOR_PYTHON_COMMAND;
AWSCoreResourceMappingToolAction(const QString& text, QObject* parent = nullptr);

@ -7,4 +7,6 @@
*/
#pragma once
#define AWSCORE_EDITOR_RESOURCE_MAPPING_TOOL_ENABLED 0
#define AWSCORE_EDITOR_RESOURCE_MAPPING_TOOL_ENABLED 1
#define AWSCORE_EDITOR_PYTHON_DEBUG_ARGUMENT ""
#define AWSCORE_EDITOR_PYTHON_COMMAND "python/python.sh"

@ -8,3 +8,5 @@
#pragma once
#define AWSCORE_EDITOR_RESOURCE_MAPPING_TOOL_ENABLED 0
#define AWSCORE_EDITOR_PYTHON_DEBUG_ARGUMENT ""
#define AWSCORE_EDITOR_PYTHON_COMMAND "python/python.sh"

@ -8,3 +8,5 @@
#pragma once
#define AWSCORE_EDITOR_RESOURCE_MAPPING_TOOL_ENABLED 1
#define AWSCORE_EDITOR_PYTHON_DEBUG_ARGUMENT "debug "
#define AWSCORE_EDITOR_PYTHON_COMMAND "python/python.cmd"

@ -58,7 +58,7 @@ namespace AWSCore
if (m_isDebug)
{
return AZStd::string::format(
"\"%s\" debug -B \"%s\" --binaries-path \"%s\" --debug --profile \"%s\" --config-path \"%s\" --log-path \"%s\"",
"\"%s\" " AWSCORE_EDITOR_PYTHON_DEBUG_ARGUMENT "-B \"%s\" --binaries-path \"%s\" --debug --profile \"%s\" --config-path \"%s\" --log-path \"%s\"",
m_enginePythonEntryPath.c_str(), m_toolScriptPath.c_str(), m_toolQtBinDirectoryPath.c_str(),
profileName.c_str(), m_toolConfigDirectoryPath.c_str(), m_toolLogDirectoryPath.c_str());
}

@ -39,6 +39,16 @@ Follow cmake instructions to configure your project, for example:
```
$ python\python.cmd debug Gems\AWSCore\Code\Tools\ResourceMappingTool\resource_mapping_tool.py --binaries_path <PATH_TO_BUILD_FOLDER>\bin\debug\AWSCoreEditorQtBin
```
* Linux
* release mode
```
$ python/python.sh Gems/AWSCore/Code/Tools/ResourceMappingTool/resource_mapping_tool.py --binaries_path <PATH_TO_BUILD_FOLDER>/bin/profile/AWSCoreEditorQtBin
```
* debug mode
```
$ python/python.sh Gems/AWSCore/Code/Tools/ResourceMappingTool/resource_mapping_tool.py --binaries_path <PATH_TO_BUILD_FOLDER>/bin/debug/AWSCoreEditorQtBin
```
* Note - Editor is integrated with the same engine python environment to launch Resource Mapping Tool. If it is failed to launch the tool
in Editor, please follow above steps to make sure expected scripts/binaries are present.

@ -20,6 +20,7 @@ argument_parser.add_argument('--debug', action='store_true', help='Execute on de
argument_parser.add_argument('--log-path', help='Path to resource mapping tool logging directory '
'(if not provided, logging file will be located at tool directory)')
argument_parser.add_argument('--profile', default='default', help='Named AWS profile to use for querying AWS resources')
arguments: Namespace = argument_parser.parse_args()
# logging setup

@ -5,6 +5,7 @@ For complete copyright and license terms please see the LICENSE at the root of t
SPDX-License-Identifier: Apache-2.0 OR MIT
"""
import platform
from typing import List
from unittest import TestCase
from unittest.mock import (ANY, call, MagicMock, patch)
@ -27,14 +28,24 @@ class TestEnvironmentUtils(TestCase):
self.addCleanup(os_pathsep_patcher.stop)
self._mock_os_pathsep: MagicMock = os_pathsep_patcher.start()
def test_setup_qt_environment_global_flag_is_set(self) -> None:
@patch('os.path.exists')
@patch('ctypes.CDLL')
def test_setup_qt_environment_global_flag_is_set(self, mock_os_path_exists, mock_ctype_cdll) -> None:
mock_os_path_exists.return_value = True
environment_utils.setup_qt_environment("dummy")
self._mock_os_environ.copy.assert_called_once()
self._mock_os_pathsep.join.assert_called_once()
assert environment_utils.is_qt_linked() is True
if platform.system() == 'Linux':
mock_os_path_exists.assert_called()
def test_cleanup_qt_environment_global_flag_is_set(self) -> None:
@patch('os.path.exists')
@patch('ctypes.CDLL')
def test_cleanup_qt_environment_global_flag_is_set(self, mock_os_path_exists, mock_ctype_cdll) -> None:
mock_os_path_exists.return_value = True
environment_utils.setup_qt_environment("dummy")
assert environment_utils.is_qt_linked() is True
environment_utils.cleanup_qt_environment()
assert environment_utils.is_qt_linked() is False
if platform.system() == 'Linux':
mock_os_path_exists.assert_called()

@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT
import logging
import os
import platform
from typing import Dict
from utils import file_utils
@ -38,6 +39,20 @@ def setup_qt_environment(bin_path: str) -> None:
new_path = os.pathsep.join([binaries_path, path])
os.environ['PATH'] = new_path
# On Linux, we need to load pyside2 and related modules as well
if platform.system() == 'Linux':
import ctypes
preload_shared_libs = [f'{bin_path}/libpyside2.abi3.so.5.14',
f'{bin_path}/libQt5Widgets.so.5']
for preload_shared_lib in preload_shared_libs:
if not os.path.exists(preload_shared_lib):
logger.error(f"Cannot find required shared library at {preload_shared_lib}")
return
else:
ctypes.CDLL(preload_shared_lib)
global qt_binaries_linked
qt_binaries_linked = True

Loading…
Cancel
Save