brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · eebe0ef Raw
128 lines · python
1import re2import os3import subprocess4 5from .builder import Builder6from lldbsuite.test import configuration7import lldbsuite.test.lldbutil as lldbutil8 9REMOTE_PLATFORM_NAME_RE = re.compile(r"^remote-(.+)$")10SIMULATOR_PLATFORM_RE = re.compile(r"^(.+)-simulator$")11 12 13def get_os_env_from_platform(platform):14    match = REMOTE_PLATFORM_NAME_RE.match(platform)15    if match:16        return match.group(1), ""17    match = SIMULATOR_PLATFORM_RE.match(platform)18    if match:19        return match.group(1), "simulator"20    return None, None21 22 23def get_os_from_sdk(sdk):24    return sdk[: sdk.find(".")], ""25 26 27def get_os_and_env():28    if configuration.lldb_platform_name:29        return get_os_env_from_platform(configuration.lldb_platform_name)30    if configuration.apple_sdk:31        return get_os_from_sdk(configuration.apple_sdk)32    return None, None33 34 35def get_triple():36    # Construct the vendor component.37    vendor = "apple"38 39    # Construct the os component.40    os, env = get_os_and_env()41    if os is None or env is None:42        return None, None, None, None43 44    # Get the SDK from the os and env.45    sdk = lldbutil.get_xcode_sdk(os, env)46    if sdk is None:47        return None, None, None, None48 49    # Get the version from the SDK.50    version = lldbutil.get_xcode_sdk_version(sdk)51    if version is None:52        return None, None, None, None53 54    return vendor, os, version, env55 56 57def get_triple_str(arch, vendor, os, version, env):58    if None in [arch, vendor, os, version, env]:59        return None60 61    component = [arch, vendor, os + version]62    if env:63        component.append(env)64    return "-".join(component)65 66 67class BuilderDarwin(Builder):68    def getTriple(self, arch):69        vendor, os, version, env = get_triple()70        return get_triple_str(arch, vendor, os, version, env)71 72    def getExtraMakeArgs(self):73        """74        Helper function to return extra argumentsfor the make system. This75        method is meant to be overridden by platform specific builders.76        """77        args = dict()78 79        if configuration.dsymutil:80            args["DSYMUTIL"] = configuration.dsymutil81 82        if configuration.apple_sdk and "internal" in configuration.apple_sdk:83            sdk_root = lldbutil.get_xcode_sdk_root(configuration.apple_sdk)84            if sdk_root:85                private_frameworks = os.path.join(86                    sdk_root, "System", "Library", "PrivateFrameworks"87                )88                args["FRAMEWORK_INCLUDES"] = "-F{}".format(private_frameworks)89 90        operating_system, env = get_os_and_env()91 92        builder_dir = os.path.dirname(os.path.abspath(__file__))93        test_dir = os.path.dirname(builder_dir)94        if not operating_system:95            entitlements_file = "entitlements-macos.plist"96        else:97            if env == "simulator":98                entitlements_file = "entitlements-simulator.plist"99            else:100                entitlements_file = "entitlements.plist"101        entitlements = os.path.join(test_dir, "make", entitlements_file)102        args["CODESIGN"] = "codesign --entitlements {}".format(entitlements)103 104        # Return extra args as a formatted string.105        return ["{}={}".format(key, value) for key, value in args.items()]106 107    def getArchCFlags(self, arch):108        """Returns the ARCH_CFLAGS for the make system."""109        # Get the triple components.110        vendor, os, version, env = get_triple()111        triple = get_triple_str(arch, vendor, os, version, env)112        if not triple:113            return []114 115        # Construct min version argument116        version_min = ""117        if env == "simulator":118            version_min = "-m{}-simulator-version-min={}".format(os, version)119        else:120            version_min = "-m{}-version-min={}".format(os, version)121 122        return ["ARCH_CFLAGS=-target {} {}".format(triple, version_min)]123 124    def _getDebugInfoArgs(self, debug_info):125        if debug_info == "dsym":126            return ["MAKE_DSYM=YES"]127        return super(BuilderDarwin, self)._getDebugInfoArgs(debug_info)128