Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / packages / Python / lldbsuite / test / builders / darwin.py
blob40dd13bcfdea1d639d8d4e792c91cc2537b86313
1 import re
2 import os
3 import subprocess
5 from .builder import Builder
6 from lldbsuite.test import configuration
7 import lldbsuite.test.lldbutil as lldbutil
9 REMOTE_PLATFORM_NAME_RE = re.compile(r"^remote-(.+)$")
10 SIMULATOR_PLATFORM_RE = re.compile(r"^(.+)-simulator$")
13 def 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
23 def get_os_from_sdk(sdk):
24 return sdk[: sdk.find(".")], ""
27 def 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
35 def get_triple():
36 # Construct the vendor component.
37 vendor = "apple"
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
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
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
54 return vendor, os, version, env
57 def get_triple_str(arch, vendor, os, version, env):
58 if None in [arch, vendor, os, version, env]:
59 return None
61 component = [arch, vendor, os + version]
62 if env:
63 components.append(env)
64 return "-".join(component)
67 class BuilderDarwin(Builder):
68 def getTriple(self, arch):
69 vendor, os, version, env = get_triple()
70 return get_triple_str(arch, vendor, os, version, env)
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()
79 if configuration.dsymutil:
80 args["DSYMUTIL"] = configuration.dsymutil
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"
88 args["FRAMEWORK_INCLUDES"] = "-F{}".format(private_frameworks)
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(entitlements)
100 else:
101 args["CODESIGN"] = "codesign"
103 # Return extra args as a formatted string.
104 return ["{}={}".format(key, value) for key, value in args.items()]
106 def getArchCFlags(self, arch):
107 """Returns the ARCH_CFLAGS for the make system."""
108 # Get the triple components.
109 vendor, os, version, env = get_triple()
110 triple = get_triple_str(arch, vendor, os, version, env)
111 if not triple:
112 return []
114 # Construct min version argument
115 version_min = ""
116 if env == "simulator":
117 version_min = "-m{}-simulator-version-min={}".format(os, version)
118 else:
119 version_min = "-m{}-version-min={}".format(os, version)
121 return ["ARCH_CFLAGS=-target {} {}".format(triple, version_min)]
123 def _getDebugInfoArgs(self, debug_info):
124 if debug_info == "dsym":
125 return ["MAKE_DSYM=YES"]
126 return super(BuilderDarwin, self)._getDebugInfoArgs(debug_info)