[lldb/build.py] Always pass an SDK to the compiler on Darwin
authorFred Riss <friss@apple.com>
Thu, 2 Jul 2020 02:54:11 +0000 (19:54 -0700)
committerFred Riss <friss@apple.com>
Thu, 2 Jul 2020 03:27:38 +0000 (20:27 -0700)
On macOS 11, system libraries which are part of the shared cache
are not present on the filesystem anymore. This causes issues
with build.py, because it fails to link binaries with libSystem
or libc++.

The real issue is that build.py was not passing an SDK to the
compiler. The script accepts an argument for the SDK, but it
is currently unused. This patch just threads the SDK through
to the compile and link steps and this fixes a bunch of Shell
test failures on very recent macOS builds.

lldb/test/Shell/helper/build.py

index d2cb52f..3de2f33 100755 (executable)
@@ -623,6 +623,9 @@ class MsvcBuilder(Builder):
 class GccBuilder(Builder):
     def __init__(self, toolchain_type, args):
         Builder.__init__(self, toolchain_type, args, '.o')
+        if sys.platform == 'darwin':
+            cmd = ['xcrun', '--sdk', args.apple_sdk, '--show-sdk-path']
+            self.apple_sdk = subprocess.check_output(cmd).strip().decode('utf-8')
 
     def _get_compilation_command(self, source, obj):
         args = []
@@ -645,6 +648,9 @@ class GccBuilder(Builder):
         args.extend(['-o', obj])
         args.append(source)
 
+        if sys.platform == 'darwin':
+            args.extend(['-isysroot', self.apple_sdk])
+
         return ('compiling', [source], obj, None, args)
 
     def _get_link_command(self):
@@ -664,6 +670,9 @@ class GccBuilder(Builder):
         args.extend(['-o', self._exe_file_name()])
         args.extend(self._obj_file_names())
 
+        if sys.platform == 'darwin':
+            args.extend(['-isysroot', self.apple_sdk])
+
         return ('linking', self._obj_file_names(), self._exe_file_name(), None, args)