From a3fc61c80f89ea709a1128caa2de2723fe307c81 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 19 Aug 2020 13:25:57 -0700 Subject: [PATCH] [lldb] Move Xcode SDK helper functions into lldbutil This allows the logic to be reused by both the builders and the tests. --- .../Python/lldbsuite/test/builders/darwin.py | 25 ++------------- lldb/packages/Python/lldbsuite/test/lldbutil.py | 37 +++++++++++++++++++++- .../tools/lldb-server/TestAppleSimulatorOSType.py | 3 +- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/builders/darwin.py b/lldb/packages/Python/lldbsuite/test/builders/darwin.py index 470ea5d..f900539 100644 --- a/lldb/packages/Python/lldbsuite/test/builders/darwin.py +++ b/lldb/packages/Python/lldbsuite/test/builders/darwin.py @@ -4,29 +4,12 @@ import subprocess from .builder import Builder from lldbsuite.test import configuration +import lldbsuite.test.lldbutil as lldbutil REMOTE_PLATFORM_NAME_RE = re.compile(r"^remote-(.+)$") SIMULATOR_PLATFORM_RE = re.compile(r"^(.+)-simulator$") -def get_sdk(os, env): - if os == "ios": - if env == "simulator": - return "iphonesimulator" - if env == "macabi": - return "macosx" - return "iphoneos" - elif os == "tvos": - if env == "simulator": - return "appletvsimulator" - return "appletvos" - elif os == "watchos": - if env == "simulator": - return "watchsimulator" - return "watchos" - return os - - def get_os_env_from_platform(platform): match = REMOTE_PLATFORM_NAME_RE.match(platform) if match: @@ -92,13 +75,11 @@ class BuilderDarwin(Builder): return "" # Get the SDK from the os and env. - sdk = get_sdk(os, env) + sdk = lldbutil.get_xcode_sdk(os, env) if not sdk: return "" - version = subprocess.check_output( - ["xcrun", "--sdk", sdk, - "--show-sdk-version"]).rstrip().decode('utf-8') + version = lldbutil.get_xcode_sdk_version(sdk) if not version: return "" diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py index d0ba25e..d4fd7f4 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py @@ -12,6 +12,7 @@ import errno import os import re import sys +import subprocess # Third-party modules from six import StringIO as SixStringIO @@ -54,6 +55,40 @@ def mkdir_p(path): raise if not os.path.isdir(path): raise OSError(errno.ENOTDIR, "%s is not a directory"%path) + + +# ============================ +# Dealing with SDK and triples +# ============================ + +def get_xcode_sdk(os, env): + if os == "ios": + if env == "simulator": + return "iphonesimulator" + if env == "macabi": + return "macosx" + return "iphoneos" + elif os == "tvos": + if env == "simulator": + return "appletvsimulator" + return "appletvos" + elif os == "watchos": + if env == "simulator": + return "watchsimulator" + return "watchos" + return os + + +def get_xcode_sdk_version(sdk): + return subprocess.check_output( + ['xcrun', '--sdk', sdk, '--show-sdk-version']).rstrip().decode('utf-8') + + +def get_xcode_sdk_root(sdk): + return subprocess.check_output(['xcrun', '--sdk', sdk, '--show-sdk-path' + ]).rstrip().decode('utf-8') + + # =================================================== # Disassembly for an SBFunction or an SBSymbol object # =================================================== @@ -525,7 +560,7 @@ def run_break_set_by_file_colon_line( file_name = path, line_number = line_number, column_number = column_number) - + return get_bpno_from_match(break_results) def run_break_set_command(test, command): diff --git a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py index 51aa004..2db6e33 100644 --- a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py +++ b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py @@ -48,8 +48,7 @@ class TestAppleSimulatorOSType(gdbremote_testcase.GdbRemoteTestCaseBase): # Launch the process using simctl self.assertIsNotNone(deviceUDID) exe_name = 'test_simulator_platform_{}'.format(platform) - sdkroot = subprocess.check_output(['xcrun', '--show-sdk-path', '--sdk', - sdk]).decode("utf-8") + sdkroot = lldbutil.get_xcode_sdk_root(sdk) self.build(dictionary={ 'EXE': exe_name, 'SDKROOT': sdkroot.strip(), 'ARCH': arch }) exe_path = self.getBuildArtifact(exe_name) -- 2.7.4