1import re 2import os 3import subprocess 4 5from .builder import Builder 6from lldbsuite.test import configuration 7import lldbsuite.test.lldbutil as lldbutil 8 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, None 21 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, None 33 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, None 43 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, None 48 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, None 53 54 return vendor, os, version, env 55 56 57def get_triple_str(arch, vendor, os, version, env): 58 if None in [arch, vendor, os, version, env]: 59 return None 60 61 component = [arch, vendor, os + version] 62 if env: 63 components.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. This 75 method is meant to be overridden by platform specific builders. 76 """ 77 args = dict() 78 79 if configuration.dsymutil: 80 args['DSYMUTIL'] = configuration.dsymutil 81 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(sdk_root, 'System', 86 'Library', 87 'PrivateFrameworks') 88 args['FRAMEWORK_INCLUDES'] = '-F{}'.format(private_frameworks) 89 90 operating_system, env = get_os_and_env() 91 if operating_system and operating_system != "macosx": 92 builder_dir = os.path.dirname(os.path.abspath(__file__)) 93 test_dir = os.path.dirname(builder_dir) 94 if env == "simulator": 95 entitlements_file = 'entitlements-simulator.plist' 96 else: 97 entitlements_file = 'entitlements.plist' 98 entitlements = os.path.join(test_dir, 'make', entitlements_file) 99 args['CODESIGN'] = 'codesign --entitlements {}'.format( 100 entitlements) 101 else: 102 args['CODESIGN'] = 'codesign' 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 argument 116 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