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 not sdk: 47 return None, None, None, None 48 49 # Get the version from the SDK. 50 version = lldbutil.get_xcode_sdk_version(sdk) 51 if not version: 52 return None, None, None, None 53 54 return vendor, os, version, env 55 56 57class BuilderDarwin(Builder): 58 def getExtraMakeArgs(self): 59 """ 60 Helper function to return extra argumentsfor the make system. This 61 method is meant to be overridden by platform specific builders. 62 """ 63 args = dict() 64 65 if configuration.dsymutil: 66 args['DSYMUTIL'] = configuration.dsymutil 67 68 operating_system, _ = get_os_and_env() 69 if operating_system and operating_system != "macosx": 70 builder_dir = os.path.dirname(os.path.abspath(__file__)) 71 test_dir = os.path.dirname(builder_dir) 72 entitlements = os.path.join(test_dir, 'make', 'entitlements.plist') 73 args['CODESIGN'] = 'codesign --entitlements {}'.format( 74 entitlements) 75 76 # Return extra args as a formatted string. 77 return ' '.join( 78 {'{}="{}"'.format(key, value) 79 for key, value in args.items()}) 80 81 def getArchCFlags(self, architecture): 82 """Returns the ARCH_CFLAGS for the make system.""" 83 # Get the triple components. 84 vendor, os, version, env = get_triple() 85 if not vendor or not os or not version or not env: 86 return "" 87 88 # Construct the triple from its components. 89 triple = "{}-{}-{}-{}".format(vendor, os, version, env) 90 91 # Construct min version argument 92 version_min = "" 93 if env == "simulator": 94 version_min = "-m{}-simulator-version-min={}".format(os, version) 95 elif os == "macosx": 96 version_min = "-m{}-version-min={}".format(os, version) 97 98 return "ARCH_CFLAGS=\"-target {} {}\"".format(triple, version_min) 99 100 def buildDsym(self, 101 sender=None, 102 architecture=None, 103 compiler=None, 104 dictionary=None, 105 testdir=None, 106 testname=None): 107 """Build the binaries with dsym debug info.""" 108 commands = [] 109 commands.append( 110 self.getMake(testdir, testname) + [ 111 "MAKE_DSYM=YES", 112 self.getArchCFlags(architecture), 113 self.getArchSpec(architecture), 114 self.getCCSpec(compiler), 115 self.getExtraMakeArgs(), 116 self.getSDKRootSpec(), 117 self.getModuleCacheSpec(), "all", 118 self.getCmdLine(dictionary) 119 ]) 120 121 self.runBuildCommands(commands, sender=sender) 122 123 # True signifies that we can handle building dsym. 124 return True 125