From c0dd9ac26bc2973b8243d102d9de9ef8a00ff42b Mon Sep 17 00:00:00 2001 From: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com> Date: Mon, 8 Nov 2021 12:25:10 -0800 Subject: [PATCH] [android_compat_fixes] fixed issues with running Android project generation scripts on Unix systems Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com> --- cmake/Tools/Platform/Android/android_support.py | 5 +---- cmake/Tools/common.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmake/Tools/Platform/Android/android_support.py b/cmake/Tools/Platform/Android/android_support.py index 054897262c..f52cc2736c 100755 --- a/cmake/Tools/Platform/Android/android_support.py +++ b/cmake/Tools/Platform/Android/android_support.py @@ -621,7 +621,7 @@ class AndroidProjectGenerator(object): gradle_wrapper_cmd.extend(['wrapper', '-p', str(self.build_dir.resolve())]) proc_result = subprocess.run(gradle_wrapper_cmd, - shell=True) + shell=(platform.system() == 'Windows')) if proc_result.returncode != 0: raise common.LmbrCmdError("Gradle was unable to generate a gradle wrapper for this project (code {}): {}" .format(proc_result.returncode, proc_result.stderr or ""), @@ -1579,9 +1579,6 @@ class AndroidSDKResolver(object): ext = '' if platform.system() == 'Windows': ext = '.bat' - else: - raise common.LmbrCmdError(f"This tool is not supported on the current platform {platform.system()}") - self.sdk_manager_path = tools_path / 'bin' / f'sdkmanager{ext}' if not self.sdk_manager_path.is_file(): diff --git a/cmake/Tools/common.py b/cmake/Tools/common.py index 02db0730d6..cd42d8c818 100755 --- a/cmake/Tools/common.py +++ b/cmake/Tools/common.py @@ -30,6 +30,9 @@ ENCODING_ERROR_HANDLINGS = 'ignore' # What to do if we encounter any encodin DEFAULT_PAK_ROOT = 'Pak' # The default Pak root folder under engine root where the game paks are built if platform.system() == 'Windows': + class PlatformError(WindowsError): + pass + # Re-use microsoft error codes since this script is meant to only run on windows host platforms ERROR_CODE_FILE_NOT_FOUND = 2 ERROR_CODE_ERROR_NOT_SUPPORTED = 50 @@ -37,6 +40,9 @@ if platform.system() == 'Windows': ERROR_CODE_CANNOT_COPY = 266 ERROR_CODE_ERROR_DIRECTORY = 267 else: + class PlatformError(Exception): + pass + # Posix does not match any of the following errors to specific codes, so just the standard '1' ERROR_CODE_FILE_NOT_FOUND = 1 ERROR_CODE_ERROR_NOT_SUPPORTED = 1 @@ -309,7 +315,7 @@ def verify_tool(override_tool_path, tool_name, tool_filename, argument_name, too # Extract the version and verify version_output = subprocess.check_output([tool_source, tool_version_argument], - shell=True, + shell=(platform.system() == 'Windows'), stderr=subprocess.PIPE).decode(DEFAULT_TEXT_READ_ENCODING, ENCODING_ERROR_HANDLINGS) version_match = tool_version_regex.search(version_output) @@ -330,13 +336,13 @@ def verify_tool(override_tool_path, tool_name, tool_filename, argument_name, too return result_version, resolved_override_tool_path except CalledProcessError as e: - error_msg = e.output.decode(DEFAULT_TEXT_READ_ENCODING, + error_msg = e.stderr.decode(DEFAULT_TEXT_READ_ENCODING, ENCODING_ERROR_HANDLINGS) raise LmbrCmdError(f"{tool_name} cannot be resolved or there was a problem determining its version number. " f"Either make sure its in the system path environment or a valid path is passed in " f"through the {argument_name} argument.\n{error_msg}", ERROR_CODE_ERROR_NOT_SUPPORTED) - except (WindowsError, RuntimeError) as e: + except (PlatformError, RuntimeError) as e: logging.error(f"Call to '{tool_source}' resulted in error: {e}") raise LmbrCmdError(f"{tool_name} cannot be resolved or there was a problem determining its version number. " f"Either make sure its in the system path environment or a valid path is passed in " @@ -552,7 +558,7 @@ class CommandLineExec(object): call_args.append(str(arguments)) logging.debug("exec(%s)", subprocess.list2cmdline(call_args)) result = subprocess.run(call_args, - shell=True, + shell=(platform.system() == 'Windows'), capture_output=capture_stdout, stderr=subprocess.DEVNULL if not capture_stdout and suppress_stderr else None, encoding='utf-8',