• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, env = 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            if env == "simulator":
73              entitlements_file = 'entitlements-simulator.plist'
74            else:
75              entitlements_file = 'entitlements.plist'
76            entitlements = os.path.join(test_dir, 'make', entitlements_file)
77            args['CODESIGN'] = 'codesign --entitlements {}'.format(
78                entitlements)
79
80        # Return extra args as a formatted string.
81        return ' '.join(
82            {'{}="{}"'.format(key, value)
83             for key, value in args.items()})
84
85    def getArchCFlags(self, arch):
86        """Returns the ARCH_CFLAGS for the make system."""
87        # Get the triple components.
88        vendor, os, version, env = get_triple()
89        if not vendor or not os or not version or not env:
90            return ""
91
92        # Construct the triple from its components.
93        triple = '-'.join([arch, vendor, os, version, env])
94
95        # Construct min version argument
96        version_min = ""
97        if env == "simulator":
98            version_min = "-m{}-simulator-version-min={}".format(os, version)
99        elif os == "macosx":
100            version_min = "-m{}-version-min={}".format(os, version)
101
102        return "ARCH_CFLAGS=\"-target {} {}\"".format(triple, version_min)
103
104    def buildDsym(self,
105                  sender=None,
106                  architecture=None,
107                  compiler=None,
108                  dictionary=None,
109                  testdir=None,
110                  testname=None):
111        """Build the binaries with dsym debug info."""
112        commands = []
113        commands.append(
114            self.getMake(testdir, testname) + [
115                "MAKE_DSYM=YES",
116                self.getArchCFlags(architecture),
117                self.getArchSpec(architecture),
118                self.getCCSpec(compiler),
119                self.getExtraMakeArgs(),
120                self.getSDKRootSpec(),
121                self.getModuleCacheSpec(), "all",
122                self.getCmdLine(dictionary)
123            ])
124
125        self.runBuildCommands(commands, sender=sender)
126
127        # True signifies that we can handle building dsym.
128        return True
129