[build] Update runtime library and tests to work with relocatable SDKs on OS X 10.9.

llvm-svn: 194168
diff --git a/clang/test/lit.cfg b/clang/test/lit.cfg
index 3b1c2c1..139126d 100644
--- a/clang/test/lit.cfg
+++ b/clang/test/lit.cfg
@@ -353,6 +353,18 @@
 # Will default to '/usr/lib/libgmalloc.dylib' if not set.
 gmalloc_path_str = lit_config.params.get('gmalloc_path',
                                          '/usr/lib/libgmalloc.dylib')
-
 if use_gmalloc:
      config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})
+
+# On Darwin, support relocatable SDKs by providing Clang with a
+# default system root path.
+if 'darwin' in config.target_triple:
+    cmd = subprocess.Popen(['xcrun', '--show-sdk-path'],
+                           stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    out, err = cmd.communicate()
+    out = out.strip()
+    res = cmd.wait()
+    if res == 0 and out:
+        sdk_path = out
+        lit_config.note('using SDKROOT: %r' % sdk_path)
+        config.environment['SDKROOT'] = sdk_path