Allow building test suite with non-default libc++
- add new "--libcxx" parameter to dotest.py to specify path to custom libc++



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@187802 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/dotest.py b/test/dotest.py
index d4bb9d9..4bc4dab 100755
--- a/test/dotest.py
+++ b/test/dotest.py
@@ -454,6 +454,7 @@
     group.add_argument('-c', metavar='config-file', help='Read a config file specified after this option')  # FIXME: additional doc.
     group.add_argument('--framework', metavar='framework-path', help='The path to LLDB.framework')
     group.add_argument('--executable', metavar='executable-path', help='The path to the lldb executable')
+    group.add_argument('--libcxx', metavar='directory', help='The path to custom libc++ library')
     group.add_argument('-e', metavar='benchmark-exe', help='Specify the full path of an executable used for benchmark purposes (see also: -x)')
     group.add_argument('-k', metavar='command', action='append', help="Specify a runhook, which is an lldb command to be executed by the debugger; The option can occur multiple times. The commands are executed one after the other to bring the debugger to a desired state, so that, for example, further benchmarking can be done")
     group.add_argument('-R', metavar='dir', help='Specify a directory to relocate the tests and their intermediate files to. BE WARNED THAT the directory, if exists, will be deleted before running this test driver. No cleanup of intermediate test files is performed in this case')
@@ -605,6 +606,9 @@
     if args.executable:
         lldbExecutablePath = args.executable
 
+    if args.libcxx:
+        os.environ["LIBCXX_PATH"] = args.libcxx
+
     if args.n:
         noHeaders = True
 
diff --git a/test/lldbtest.py b/test/lldbtest.py
index 3fbaff1..32d51b7 100644
--- a/test/lldbtest.py
+++ b/test/lldbtest.py
@@ -821,6 +821,11 @@
         #import traceback
         #traceback.print_stack()
 
+        if "LIBCXX_PATH" in os.environ:
+            self.libcxxPath = os.environ["LIBCXX_PATH"]
+        else:
+            self.libcxxPath = None
+
         if "LLDB_EXEC" in os.environ:
             self.lldbExec = os.environ["LLDB_EXEC"]
         else:
@@ -1360,11 +1365,24 @@
         if not module.buildDwarf(self, architecture, compiler, dictionary, clean):
             raise Exception("Don't know how to build binary with dwarf")
 
-    def getBuildFlags(self, use_cpp11=True, use_pthreads=True):
+    def getBuildFlags(self, use_cpp11=True, use_libcxx=False, use_libstdcxx=False, use_pthreads=True):
         """ Returns a dictionary (which can be provided to build* functions above) which
             contains OS-specific build flags.
         """
         cflags = ""
+
+        # On Mac OS X, unless specifically requested to use libstdc++, use libc++
+        if not use_libstdcxx and sys.platform.startswith('darwin'):
+            use_libcxx = True
+
+        if use_libcxx and self.libcxxPath:
+            cflags += "-stdlib=libc++ "
+            if self.libcxxPath:
+                libcxxInclude = os.path.join(self.libcxxPath, "include")
+                libcxxLib = os.path.join(self.libcxxPath, "lib")
+                if os.path.isdir(libcxxInclude) and os.path.isdir(libcxxLib):
+                    cflags += "-nostdinc++ -I%s -L%s -Wl,-rpath,%s " % (libcxxInclude, libcxxLib, libcxxLib)
+
         if use_cpp11:
             cflags += "-std="
             if "gcc" in self.getCompiler() and "4.6" in self.getCompilerVersion():