[Lldb-commits] [lldb] e5d08fc - [lldb] Extend Darwin builder to pass the ARCH_CFLAGS spec to Make.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 19 11:47:38 PDT 2020


Author: Jonas Devlieghere
Date: 2020-08-19T11:47:29-07:00
New Revision: e5d08fcbac722d487973d9c96838c0589f1953c3

URL: https://github.com/llvm/llvm-project/commit/e5d08fcbac722d487973d9c96838c0589f1953c3
DIFF: https://github.com/llvm/llvm-project/commit/e5d08fcbac722d487973d9c96838c0589f1953c3.diff

LOG: [lldb] Extend Darwin builder to pass the ARCH_CFLAGS spec to Make.

Construct the ARCH_CFLAGS in Python rather than in Make by disassembling
the TRIPLE.

Differential revision: https://reviews.llvm.org/D85539

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/builders/builder.py
    lldb/packages/Python/lldbsuite/test/builders/darwin.py
    lldb/packages/Python/lldbsuite/test/dotest.py
    lldb/packages/Python/lldbsuite/test/make/Makefile.rules

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 160bafb95b56a..4a8985104874c 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -25,6 +25,9 @@ def getExtraMakeArgs(self):
         Helper function to return extra argumentsfor the make system. This
         method is meant to be overridden by platform specific builders.
         """
+
+    def getArchCFlags(self, architecture):
+        """Returns the ARCH_CFLAGS for the make system."""
         return ""
 
     def getMake(self, test_subdir, test_name):
@@ -139,6 +142,7 @@ def buildDefault(self,
         commands.append(
             self.getMake(testdir, testname) + [
                 "all",
+                self.getArchCFlags(architecture),
                 self.getArchSpec(architecture),
                 self.getCCSpec(compiler),
                 self.getExtraMakeArgs(),
@@ -164,6 +168,7 @@ def buildDwarf(self,
         commands.append(
             self.getMake(testdir, testname) + [
                 "MAKE_DSYM=NO",
+                self.getArchCFlags(architecture),
                 self.getArchSpec(architecture),
                 self.getCCSpec(compiler),
                 self.getExtraMakeArgs(),
@@ -188,6 +193,7 @@ def buildDwo(self,
         commands.append(
             self.getMake(testdir, testname) + [
                 "MAKE_DSYM=NO", "MAKE_DWO=YES",
+                self.getArchCFlags(architecture),
                 self.getArchSpec(architecture),
                 self.getCCSpec(compiler),
                 self.getExtraMakeArgs(),
@@ -212,6 +218,7 @@ def buildGModules(self,
         commands.append(
             self.getMake(testdir, testname) + [
                 "MAKE_DSYM=NO", "MAKE_GMODULES=YES",
+                self.getArchCFlags(architecture),
                 self.getArchSpec(architecture),
                 self.getCCSpec(compiler),
                 self.getExtraMakeArgs(),

diff  --git a/lldb/packages/Python/lldbsuite/test/builders/darwin.py b/lldb/packages/Python/lldbsuite/test/builders/darwin.py
index ce0aa0b13343e..704897d4a5f65 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/darwin.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/darwin.py
@@ -1,4 +1,43 @@
+import re
+import subprocess
+
 from .builder import Builder
+from lldbsuite.test import configuration
+
+REMOTE_PLATFORM_NAME_RE = re.compile(r"^remote-(.+)$")
+SIMULATOR_PLATFORM_RE = re.compile(r"^(.+)-simulator$")
+
+
+def get_sdk(os, env):
+    if os == "ios":
+        if env == "simulator":
+            return "iphonesimulator"
+        if env == "macabi":
+            return "macosx"
+        return "iphoneos"
+    elif os == "tvos":
+        if env == "simulator":
+            return "appletvsimulator"
+        return "appletvos"
+    elif os == "watchos":
+        if env == "simulator":
+            return "watchsimulator"
+        return "watchos"
+    return os
+
+
+def get_os_env_from_platform(platform):
+    match = REMOTE_PLATFORM_NAME_RE.match(platform)
+    if match:
+        return match.group(1), ""
+    match = SIMULATOR_PLATFORM_RE.match(platform)
+    if match:
+        return match.group(1), "simulator"
+    return None, None
+
+
+def get_os_from_sdk(sdk):
+    return sdk[:sdk.find('.')], ""
 
 from lldbsuite.test import configuration
 
@@ -14,10 +53,62 @@ def getExtraMakeArgs(self):
         if configuration.dsymutil:
             args['DSYMUTIL'] = configuration.dsymutil
 
+        os, _ = self.getOsAndEnv()
+        if os and os != "macosx":
+            args['CODESIGN'] = 'codesign'
+
         # Return extra args as a formatted string.
         return ' '.join(
             {'{}="{}"'.format(key, value)
              for key, value in args.items()})
+    def getOsAndEnv(self):
+        if configuration.lldb_platform_name:
+            return get_os_env_from_platform(configuration.lldb_platform_name)
+        elif configuration.apple_sdk:
+            return get_os_from_sdk(configuration.apple_sdk)
+        return None, None
+
+    def getArchCFlags(self, architecture):
+        """Returns the ARCH_CFLAGS for the make system."""
+
+        # Construct the arch component.
+        arch = architecture if architecture else configuration.arch
+        if not arch:
+            arch = subprocess.check_output(['machine'
+                                            ]).rstrip().decode('utf-8')
+        if not arch:
+            return ""
+
+        # Construct the vendor component.
+        vendor = "apple"
+
+        # Construct the os component.
+        os, env = self.getOsAndEnv()
+        if os is None or env is None:
+            return ""
+
+        # Get the SDK from the os and env.
+        sdk = get_sdk(os, env)
+        if not sdk:
+            return ""
+
+        version = subprocess.check_output(
+            ["xcrun", "--sdk", sdk,
+             "--show-sdk-version"]).rstrip().decode('utf-8')
+        if not version:
+            return ""
+
+        # Construct the triple from its components.
+        triple = "{}-{}-{}-{}".format(vendor, os, version, env)
+
+        # Construct min version argument
+        version_min = ""
+        if env == "simulator":
+            version_min = "-m{}-simulator-version-min={}".format(os, version)
+        elif os == "macosx":
+            version_min = "-m{}-version-min={}".format(os, version)
+
+        return "ARCH_CFLAGS=\"-target {} {}\"".format(triple, version_min)
 
     def buildDsym(self,
                   sender=None,
@@ -31,6 +122,7 @@ def buildDsym(self,
         commands.append(
             self.getMake(testdir, testname) + [
                 "MAKE_DSYM=YES",
+                self.getArchCFlags(architecture),
                 self.getArchSpec(architecture),
                 self.getCCSpec(compiler),
                 self.getExtraMakeArgs(),

diff  --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index e6f4974935870..9b1c7fd39da49 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -766,15 +766,6 @@ def getVersionForSDK(sdk):
     return ver
 
 
-def setDefaultTripleForPlatform():
-    if configuration.lldb_platform_name == 'ios-simulator':
-        triple_str = 'x86_64-apple-ios%s' % (
-            getVersionForSDK('iphonesimulator'))
-        os.environ['TRIPLE'] = triple_str
-        return {'TRIPLE': triple_str}
-    return {}
-
-
 def checkCompiler():
     # Add some intervention here to sanity check that the compiler requested is sane.
     # If found not to be an executable program, we abort.
@@ -947,14 +938,6 @@ def run_suite():
         else:
             configuration.lldb_platform_url = None
 
-    platform_changes = setDefaultTripleForPlatform()
-    first = True
-    for key in platform_changes:
-        if first:
-            print("Environment variables setup for platform support:")
-            first = False
-        print("%s = %s" % (key, platform_changes[key]))
-
     if configuration.lldb_platform_working_dir:
         print("Setting remote platform working directory to '%s'..." %
               (configuration.lldb_platform_working_dir))

diff  --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index a9e5c08223e4f..5f6218db4d6d2 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -94,65 +94,6 @@ endif
 # from the triple alone
 #----------------------------------------------------------------------
 ARCH_CFLAGS :=
-ifneq "$(TRIPLE)" ""
-	triple_space = $(subst -, ,$(TRIPLE))
-	ARCH =$(word 1, $(triple_space))
-	TRIPLE_VENDOR =$(word 2, $(triple_space))
-	triple_os_and_version =$(shell echo $(word 3, $(triple_space)) | sed 's/\([a-z]*\)\(.*\)/\1 \2/')
-	TRIPLE_OS =$(word 1, $(triple_os_and_version))
-	TRIPLE_VERSION =$(word 2, $(triple_os_and_version))
-	TRIPLE_ENV =$(word 4, $(triple_space))
-	ifeq "$(TRIPLE_VENDOR)" "apple"
-		ifeq "$(TRIPLE_OS)" "ios"
-			ifeq "$(TRIPLE_ENV)" "simulator"
-				SDK_NAME := iphonesimulator
-			else
-			ifeq "$(TRIPLE_ENV)" "macabi"
-				SDK_NAME := macosx
-			else
-				SDK_NAME := iphoneos
-			endif
-			endif
-		endif
-		ifeq "$(TRIPLE_OS)" "tvos"
-			ifeq "$(TRIPLE_ENV)" "simulator"
-				SDK_NAME := appletvsimulator
-			else
-				SDK_NAME := appletvos
-			endif
-		endif
-		ifeq "$(TRIPLE_OS)" "watchos"
-			ifeq "$(TRIPLE_ENV)" "simulator"
-				SDK_NAME := watchsimulator
-			else
-				SDK_NAME := watchos
-			endif
-		endif
-		ifneq "$(TRIPLE_OS)" "macosx"
-			ifeq "$(TRIPLE_ENV)" ""
-				CODESIGN := codesign
-			endif
-		endif
-
-		ifeq "$(SDKROOT)" ""
-			SDKROOT := $(shell xcrun --sdk $(SDK_NAME) --show-sdk-path)
-		endif
-		ifeq "$(TRIPLE_VERSION)" ""
-			ifeq "$(SDK_NAME)" ""
-                               $(error "SDK_NAME is empty")
-			endif
-			TRIPLE_VERSION := $(shell xcrun --sdk $(SDK_NAME) --show-sdk-version)
-		endif
-		ifeq "$(TRIPLE_ENV)" "simulator"
-			ARCH_CFLAGS := -m$(TRIPLE_OS)-simulator-version-min=$(TRIPLE_VERSION)
-		else
-		ifneq "$(TRIPLE_OS)" "macosx"
-			ARCH_CFLAGS := -m$(TRIPLE_OS)-version-min=$(TRIPLE_VERSION)
-		endif
-		endif
-	endif
-	ARCH_CFLAGS += -target $(TRIPLE)
-endif
 ifeq "$(OS)" "Android"
 	include $(THIS_FILE_DIR)/Android.rules
 endif


        


More information about the lldb-commits mailing list