From 6e78bf2d3a3dc4be178419674c5ce8c4e1bd57e0 Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@sandoe.co.uk>
Date: Tue, 2 Apr 2019 10:55:43 +0100
Subject: [PATCH] [libcxx] If we have a sysroot, don't try to use xcrun
 --sdk.

It doesn't work on earlier Darwin.  Default to 10.4 if we fail everywhere.
---
 libcxx/utils/libcxx/test/target_info.py | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/libcxx/utils/libcxx/test/target_info.py b/libcxx/utils/libcxx/test/target_info.py
index 7cffcea359f..9f1b9b22951 100644
--- a/libcxx/utils/libcxx/test/target_info.py
+++ b/libcxx/utils/libcxx/test/target_info.py
@@ -85,17 +85,21 @@ class DarwinLocalTI(DefaultTargetInfo):
 
     def get_sdk_version(self, name):
         assert self.is_host_macosx()
-        cmd = ['xcrun', '--sdk', name, '--show-sdk-path']
-        try:
-            out = subprocess.check_output(cmd).strip()
-        except OSError:
-            pass
-
+        res = 0
+        out = self.full_config.get_lit_conf('sysroot')
         if not out:
+            cmd = ['xcrun', '--sdk', name, '--show-sdk-path']
+            try:
+                out = subprocess.check_output(cmd).strip()
+            except OSError:
+                res = -1
+        full_config.lit_config.note('out: %r' % out)
+        if res == 0 and out:
+            return re.sub(r'.*/[^0-9]+([0-9.]+)\.sdk', r'\1', out)
+        else:
             self.full_config.lit_config.fatal(
                     "cannot infer sdk version with: %r" % cmd)
-
-        return re.sub(r'.*/[^0-9]+([0-9.]+)\.sdk', r'\1', out)
+        return '10.4'
 
     def get_platform(self):
         platform = self.full_config.get_lit_conf('platform')
