[libc++] Move handling of the target triple to the DSL

This fixes a long standing issue where the triple is not always set
consistently in all configurations. This change also moves the
back-deployment Lit features to using the proper target triple
instead of using something ad-hoc.

This will be necessary for using from scratch Lit configuration files
in both normal testing and back-deployment testing.

Differential Revision: https://reviews.llvm.org/D102012

GitOrigin-RevId: 74d096e5587969e0d1458ea2175515f6f02e7df3
diff --git a/test/catch_function_01.pass.cpp b/test/catch_function_01.pass.cpp
index 2978853..02ecec2 100644
--- a/test/catch_function_01.pass.cpp
+++ b/test/catch_function_01.pass.cpp
@@ -14,8 +14,8 @@
 // UNSUPPORTED: no-exceptions
 
 // 65ace9daa360 made it in the dylib in macOS 10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 #include <cassert>
 
diff --git a/test/catch_member_data_pointer_01.pass.cpp b/test/catch_member_data_pointer_01.pass.cpp
index 4819969..2ee68ba 100644
--- a/test/catch_member_data_pointer_01.pass.cpp
+++ b/test/catch_member_data_pointer_01.pass.cpp
@@ -9,8 +9,8 @@
 // UNSUPPORTED: no-exceptions
 
 // 1b00fc5d8133 made it in the dylib in macOS 10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 #include <cassert>
 
diff --git a/test/catch_member_pointer_nullptr.pass.cpp b/test/catch_member_pointer_nullptr.pass.cpp
index 6ffb9ab..321aa82 100644
--- a/test/catch_member_pointer_nullptr.pass.cpp
+++ b/test/catch_member_pointer_nullptr.pass.cpp
@@ -8,10 +8,10 @@
 
 // Catching an exception thrown as nullptr was not properly handled before
 // 2f984cab4fa7, which landed in macOS 10.13
-// XFAIL: with_system_cxx_lib=macosx10.12
-// XFAIL: with_system_cxx_lib=macosx10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 // UNSUPPORTED: no-exceptions
 
diff --git a/test/catch_multi_level_pointer.pass.cpp b/test/catch_multi_level_pointer.pass.cpp
index 76a734d..26b025e 100644
--- a/test/catch_multi_level_pointer.pass.cpp
+++ b/test/catch_multi_level_pointer.pass.cpp
@@ -9,8 +9,8 @@
 // UNSUPPORTED: no-exceptions
 
 // 1b00fc5d8133 made it in the dylib in macOS 10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 #include <cassert>
 #include <cstdio>
diff --git a/test/catch_pointer_nullptr.pass.cpp b/test/catch_pointer_nullptr.pass.cpp
index 78b3454..3320d28 100644
--- a/test/catch_pointer_nullptr.pass.cpp
+++ b/test/catch_pointer_nullptr.pass.cpp
@@ -8,10 +8,10 @@
 
 // Catching an exception thrown as nullptr was not properly handled before
 // 2f984cab4fa7, which landed in macOS 10.13
-// XFAIL: with_system_cxx_lib=macosx10.12
-// XFAIL: with_system_cxx_lib=macosx10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 // UNSUPPORTED: c++03
 // UNSUPPORTED: no-exceptions
diff --git a/test/catch_ptr_02.pass.cpp b/test/catch_ptr_02.pass.cpp
index ce4918e..444aac8 100644
--- a/test/catch_ptr_02.pass.cpp
+++ b/test/catch_ptr_02.pass.cpp
@@ -15,7 +15,7 @@
 // ADDITIONAL_COMPILE_FLAGS: -Wno-error
 
 // The fix for PR17222 made it in the dylib for macOS 10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 #include <cassert>
 
diff --git a/test/cxa_vec_new_overflow_PR41395.pass.cpp b/test/cxa_vec_new_overflow_PR41395.pass.cpp
index 17cf7c0..b821ae8 100644
--- a/test/cxa_vec_new_overflow_PR41395.pass.cpp
+++ b/test/cxa_vec_new_overflow_PR41395.pass.cpp
@@ -9,12 +9,12 @@
 // UNSUPPORTED: no-exceptions
 
 // PR41395 isn't fixed until the dylib shipped with macOS 10.15
-// XFAIL: with_system_cxx_lib=macosx10.14
-// XFAIL: with_system_cxx_lib=macosx10.13
-// XFAIL: with_system_cxx_lib=macosx10.12
-// XFAIL: with_system_cxx_lib=macosx10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.14
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.13
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 #include "cxxabi.h"
 #include <new>
diff --git a/test/dynamic_cast.pass.cpp b/test/dynamic_cast.pass.cpp
index cc0012c..87ca6a6 100644
--- a/test/dynamic_cast.pass.cpp
+++ b/test/dynamic_cast.pass.cpp
@@ -9,14 +9,14 @@
 // XFAIL: gcc-7, gcc-8, gcc-9
 
 // PR33425 and PR33487 are not fixed until the dylib shipped with macOS 10.15
-// XFAIL: with_system_cxx_lib=macosx10.14
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.14
 
 // PR33439 isn't fixed until the dylib shipped with macOS 10.14
-// XFAIL: with_system_cxx_lib=macosx10.13
-// XFAIL: with_system_cxx_lib=macosx10.12
-// XFAIL: with_system_cxx_lib=macosx10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.13
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 #include <cassert>
 
diff --git a/test/exception_object_alignment.pass.cpp b/test/exception_object_alignment.pass.cpp
index 2ff7448..2d39800 100644
--- a/test/exception_object_alignment.pass.cpp
+++ b/test/exception_object_alignment.pass.cpp
@@ -12,11 +12,11 @@
 // before macOS 10.14. The test fails on macOS 10.9 to 10.12, passes on macOS
 // 10.13 (no investigation done), and passes afterwards. Just mark all the OSes
 // before 10.14 as unsupported.
-// UNSUPPORTED: with_system_cxx_lib=macosx10.13
-// UNSUPPORTED: with_system_cxx_lib=macosx10.12
-// UNSUPPORTED: with_system_cxx_lib=macosx10.11
-// UNSUPPORTED: with_system_cxx_lib=macosx10.10
-// UNSUPPORTED: with_system_cxx_lib=macosx10.9
+// UNSUPPORTED: use_system_cxx_lib && x86_64-apple-macosx10.13
+// UNSUPPORTED: use_system_cxx_lib && x86_64-apple-macosx10.12
+// UNSUPPORTED: use_system_cxx_lib && x86_64-apple-macosx10.11
+// UNSUPPORTED: use_system_cxx_lib && x86_64-apple-macosx10.10
+// UNSUPPORTED: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 // Check that the pointer __cxa_allocate_exception returns is aligned to the
 // default alignment for the target architecture.
diff --git a/test/forced_unwind1.pass.cpp b/test/forced_unwind1.pass.cpp
index d1ed3bf..2bd39f3 100644
--- a/test/forced_unwind1.pass.cpp
+++ b/test/forced_unwind1.pass.cpp
@@ -12,13 +12,13 @@
 // UNSUPPORTED: no-exceptions, c++03
 
 // These tests fail on previously released dylibs, investigation needed.
-// XFAIL: with_system_cxx_lib=macosx10.15
-// XFAIL: with_system_cxx_lib=macosx10.14
-// XFAIL: with_system_cxx_lib=macosx10.13
-// XFAIL: with_system_cxx_lib=macosx10.12
-// XFAIL: with_system_cxx_lib=macosx10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.15
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.14
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.13
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 #include <stdlib.h>
 #include <string.h>
diff --git a/test/forced_unwind2.pass.cpp b/test/forced_unwind2.pass.cpp
index ca0b596..9f73a67 100644
--- a/test/forced_unwind2.pass.cpp
+++ b/test/forced_unwind2.pass.cpp
@@ -11,13 +11,13 @@
 // UNSUPPORTED: no-exceptions, c++03
 
 // These tests fail on previously released dylibs, investigation needed.
-// XFAIL: with_system_cxx_lib=macosx10.15
-// XFAIL: with_system_cxx_lib=macosx10.14
-// XFAIL: with_system_cxx_lib=macosx10.13
-// XFAIL: with_system_cxx_lib=macosx10.12
-// XFAIL: with_system_cxx_lib=macosx10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.15
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.14
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.13
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 #include <exception>
 #include <stdlib.h>
diff --git a/test/incomplete_type.sh.cpp b/test/incomplete_type.sh.cpp
index ebd37df..6995226 100644
--- a/test/incomplete_type.sh.cpp
+++ b/test/incomplete_type.sh.cpp
@@ -17,10 +17,10 @@
 // UNSUPPORTED: no-rtti
 
 // The fix for PR25898 landed in the system dylibs in macOS 10.13
-// XFAIL: with_system_cxx_lib=macosx10.12
-// XFAIL: with_system_cxx_lib=macosx10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 // RUN: %{cxx} %{flags} %{compile_flags} -Wno-unreachable-code -c %s -o %t.one.o
 // RUN: %{cxx} %{flags} %{compile_flags} -Wno-unreachable-code -c %s -o %t.two.o -DTU_ONE
diff --git a/test/libcxxabi/test/config.py b/test/libcxxabi/test/config.py
index 1c4d5be..c59d203 100644
--- a/test/libcxxabi/test/config.py
+++ b/test/libcxxabi/test/config.py
@@ -71,10 +71,11 @@
                                   % cxx_headers)
         (path, version) = os.path.split(cxx_headers)
         (path, cxx) = os.path.split(path)
-        cxx_target_headers = os.path.join(
-            path, self.get_lit_conf('target_triple', None), cxx, version)
-        if os.path.isdir(cxx_target_headers):
-            self.cxx.compile_flags += ['-I' + cxx_target_headers]
+        triple = self.get_lit_conf('target_triple', None)
+        if triple is not None:
+            cxx_target_headers = os.path.join(path, triple, cxx, version)
+            if os.path.isdir(cxx_target_headers):
+                self.cxx.compile_flags += ['-I' + cxx_target_headers]
         self.cxx.compile_flags += ['-I' + cxx_headers]
 
         libcxxabi_headers = self.get_lit_conf(
diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in
index 7607218..3445725 100644
--- a/test/lit.site.cfg.in
+++ b/test/lit.site.cfg.in
@@ -25,7 +25,8 @@
 config.enable_shared            = @LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX@
 config.enable_exceptions        = @LIBCXXABI_ENABLE_EXCEPTIONS@
 config.host_triple              = "@LLVM_HOST_TRIPLE@"
-config.target_triple            = "@TARGET_TRIPLE@"
+if "@TARGET_TRIPLE@":
+    config.target_triple        = "@TARGET_TRIPLE@"
 config.sysroot                  = "@LIBCXXABI_SYSROOT@"
 config.gcc_toolchain            = "@LIBCXXABI_GCC_TOOLCHAIN@"
 config.cxx_ext_threads          = @LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY@
diff --git a/test/native/arm-linux-eabi/lit.local.cfg b/test/native/arm-linux-eabi/lit.local.cfg
index 1b2c20c..d12eb20 100644
--- a/test/native/arm-linux-eabi/lit.local.cfg
+++ b/test/native/arm-linux-eabi/lit.local.cfg
@@ -1,6 +1,6 @@
 def is_arm_linux_eabi(triple):
     return ('arm' in triple) and ('linux' in triple) and ('eabi' in triple)
 
-is_native = config.root.host_triple == config.root.target_triple
+is_native = hasattr(config.root, 'target_triple') and (config.root.host_triple == config.root.target_triple)
 if not is_native or not is_arm_linux_eabi(config.root.host_triple):
     config.unsupported = True
diff --git a/test/test_aux_runtime_op_array_new.pass.cpp b/test/test_aux_runtime_op_array_new.pass.cpp
index 52ccce8..ddf802d 100644
--- a/test/test_aux_runtime_op_array_new.pass.cpp
+++ b/test/test_aux_runtime_op_array_new.pass.cpp
@@ -10,12 +10,12 @@
 
 // ___cxa_throw_bad_array_new_length is re-exported from libc++ only starting
 // in macosx 10.15
-// XFAIL: with_system_cxx_lib=macosx10.14
-// XFAIL: with_system_cxx_lib=macosx10.13
-// XFAIL: with_system_cxx_lib=macosx10.12
-// XFAIL: with_system_cxx_lib=macosx10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.14
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.13
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 #include <cxxabi.h>
 #include <new>
diff --git a/test/test_demangle.pass.cpp b/test/test_demangle.pass.cpp
index 4f19daf..449d705 100644
--- a/test/test_demangle.pass.cpp
+++ b/test/test_demangle.pass.cpp
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 // The demangler does not pass all these tests with the system dylibs on macOS.
-// XFAIL: with_system_cxx_lib=macosx10.15
-// XFAIL: with_system_cxx_lib=macosx10.14
-// XFAIL: with_system_cxx_lib=macosx10.13
-// XFAIL: with_system_cxx_lib=macosx10.12
-// XFAIL: with_system_cxx_lib=macosx10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.15
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.14
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.13
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 #include "support/timer.h"
 #include <cassert>
diff --git a/test/test_exception_address_alignment.pass.cpp b/test/test_exception_address_alignment.pass.cpp
index 182401c..5d59709 100644
--- a/test/test_exception_address_alignment.pass.cpp
+++ b/test/test_exception_address_alignment.pass.cpp
@@ -17,10 +17,10 @@
 // XFAIL: apple-clang-11 && !target-arm
 // XFAIL: apple-clang-10 && !target-arm
 // XFAIL: apple-clang-9 && !target-arm
-// XFAIL: with_system_cxx_lib=macosx10.12
-// XFAIL: with_system_cxx_lib=macosx10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 // Test that the address of the exception object is properly aligned as required
 // by the relevant ABI
diff --git a/test/uncaught_exceptions.pass.cpp b/test/uncaught_exceptions.pass.cpp
index c3c1aac..44186d5 100644
--- a/test/uncaught_exceptions.pass.cpp
+++ b/test/uncaught_exceptions.pass.cpp
@@ -9,12 +9,12 @@
 // UNSUPPORTED: no-exceptions
 
 // __cxa_uncaught_exceptions is not re-exported from libc++ until macOS 10.15.
-// XFAIL: with_system_cxx_lib=macosx10.14
-// XFAIL: with_system_cxx_lib=macosx10.13
-// XFAIL: with_system_cxx_lib=macosx10.12
-// XFAIL: with_system_cxx_lib=macosx10.11
-// XFAIL: with_system_cxx_lib=macosx10.10
-// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.14
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.13
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
+// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
 
 #include <cxxabi.h>
 #include <cassert>