Fix Windows tests when __config_site is present.
authorBen Craig <ben.craig@ni.com>
Mon, 8 May 2017 13:15:22 +0000 (13:15 +0000)
committerBen Craig <ben.craig@ni.com>
Mon, 8 May 2017 13:15:22 +0000 (13:15 +0000)
Previously, the force includes would complain about a missing _DEBUG symbol.
Now we dump macros before adding the force includes to the command line.

llvm-svn: 302421

libcxx/utils/libcxx/test/config.py

index 7f1ae85..a998e21 100644 (file)
-#===----------------------------------------------------------------------===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is dual licensed under the MIT and the University of Illinois Open
-# Source Licenses. See LICENSE.TXT for details.
-#
-#===----------------------------------------------------------------------===##
-
-import locale
-import os
-import platform
-import pkgutil
-import pipes
-import re
-import shlex
-import shutil
-import sys
-
-from libcxx.compiler import CXXCompiler
-from libcxx.test.target_info import make_target_info
-from libcxx.test.executor import *
-from libcxx.test.tracing import *
-import libcxx.util
-
-def loadSiteConfig(lit_config, config, param_name, env_name):
-    # We haven't loaded the site specific configuration (the user is
-    # probably trying to run on a test file directly, and either the site
-    # configuration hasn't been created by the build system, or we are in an
-    # out-of-tree build situation).
-    site_cfg = lit_config.params.get(param_name,
-                                     os.environ.get(env_name))
-    if not site_cfg:
-        lit_config.warning('No site specific configuration file found!'
-                           ' Running the tests in the default configuration.')
-    elif not os.path.isfile(site_cfg):
-        lit_config.fatal(
-            "Specified site configuration file does not exist: '%s'" %
-            site_cfg)
-    else:
-        lit_config.note('using site specific configuration at %s' % site_cfg)
-        ld_fn = lit_config.load_config
-
-        # Null out the load_config function so that lit.site.cfg doesn't
-        # recursively load a config even if it tries.
-        # TODO: This is one hell of a hack. Fix it.
-        def prevent_reload_fn(*args, **kwargs):
-            pass
-        lit_config.load_config = prevent_reload_fn
-        ld_fn(config, site_cfg)
-        lit_config.load_config = ld_fn
-
-class Configuration(object):
-    # pylint: disable=redefined-outer-name
-    def __init__(self, lit_config, config):
-        self.lit_config = lit_config
-        self.config = config
-        self.is_windows = platform.system() == 'Windows'
-        self.cxx = None
-        self.cxx_is_clang_cl = None
-        self.cxx_stdlib_under_test = None
-        self.project_obj_root = None
-        self.libcxx_src_root = None
-        self.libcxx_obj_root = None
-        self.cxx_library_root = None
-        self.cxx_runtime_root = None
-        self.abi_library_root = None
-        self.link_shared = self.get_lit_bool('enable_shared', default=True)
-        self.debug_build = self.get_lit_bool('debug_build',   default=False)
-        self.exec_env = {}
-        self.use_target = False
-        self.use_system_cxx_lib = False
-        self.use_clang_verify = False
-        self.long_tests = None
-        self.execute_external = False
-
-    def get_lit_conf(self, name, default=None):
-        val = self.lit_config.params.get(name, None)
-        if val is None:
-            val = getattr(self.config, name, None)
-            if val is None:
-                val = default
-        return val
-
-    def get_lit_bool(self, name, default=None, env_var=None):
-        def check_value(value, var_name):
-            if value is None:
-                return default
-            if isinstance(value, bool):
-                return value
-            if not isinstance(value, str):
-                raise TypeError('expected bool or string')
-            if value.lower() in ('1', 'true'):
-                return True
-            if value.lower() in ('', '0', 'false'):
-                return False
-            self.lit_config.fatal(
-                "parameter '{}' should be true or false".format(var_name))
-
-        conf_val = self.get_lit_conf(name)
-        if env_var is not None and env_var in os.environ and \
-                os.environ[env_var] is not None:
-            val = os.environ[env_var]
-            if conf_val is not None:
-                self.lit_config.warning(
-                    'Environment variable %s=%s is overriding explicit '
-                    '--param=%s=%s' % (env_var, val, name, conf_val))
-            return check_value(val, env_var)
-        return check_value(conf_val, name)
-
-    def make_static_lib_name(self, name):
-        """Return the full filename for the specified library name"""
-        if self.is_windows:
-            assert name == 'c++'  # Only allow libc++ to use this function for now.
-            return 'lib' + name + '.lib'
-        else:
-            return 'lib' + name + '.a'
-
-    def configure(self):
-        self.configure_executor()
-        self.configure_use_system_cxx_lib()
-        self.configure_target_info()
-        self.configure_cxx()
-        self.configure_triple()
-        self.configure_deployment()
-        self.configure_availability()
-        self.configure_src_root()
-        self.configure_obj_root()
-        self.configure_cxx_stdlib_under_test()
-        self.configure_cxx_library_root()
-        self.configure_use_clang_verify()
-        self.configure_use_thread_safety()
-        self.configure_execute_external()
-        self.configure_ccache()
-        self.configure_compile_flags()
-        self.configure_filesystem_compile_flags()
-        self.configure_link_flags()
-        self.configure_env()
-        self.configure_color_diagnostics()
-        self.configure_debug_mode()
-        self.configure_warnings()
-        self.configure_sanitizer()
-        self.configure_coverage()
-        self.configure_modules()
-        self.configure_substitutions()
-        self.configure_features()
-
-    def print_config_info(self):
-        # Print the final compile and link flags.
-        self.lit_config.note('Using compiler: %s' % self.cxx.path)
-        self.lit_config.note('Using flags: %s' % self.cxx.flags)
-        if self.cxx.use_modules:
-            self.lit_config.note('Using modules flags: %s' %
-                                 self.cxx.modules_flags)
-        self.lit_config.note('Using compile flags: %s'
-                             % self.cxx.compile_flags)
-        if len(self.cxx.warning_flags):
-            self.lit_config.note('Using warnings: %s' % self.cxx.warning_flags)
-        self.lit_config.note('Using link flags: %s' % self.cxx.link_flags)
-        # Print as list to prevent "set([...])" from being printed.
-        self.lit_config.note('Using available_features: %s' %
-                             list(self.config.available_features))
-        self.lit_config.note('Using environment: %r' % self.exec_env)
-        sys.stderr.flush()  # Force flushing to avoid broken output on Windows
-
-    def get_test_format(self):
-        from libcxx.test.format import LibcxxTestFormat
-        return LibcxxTestFormat(
-            self.cxx,
-            self.use_clang_verify,
-            self.execute_external,
-            self.executor,
-            exec_env=self.exec_env)
-
-    def configure_executor(self):
-        exec_str = self.get_lit_conf('executor', "None")
-        te = eval(exec_str)
-        if te:
-            self.lit_config.note("Using executor: %r" % exec_str)
-            if self.lit_config.useValgrind:
-                # We have no way of knowing where in the chain the
-                # ValgrindExecutor is supposed to go. It is likely
-                # that the user wants it at the end, but we have no
-                # way of getting at that easily.
-                selt.lit_config.fatal("Cannot infer how to create a Valgrind "
-                                      " executor.")
-        else:
-            te = LocalExecutor()
-            if self.lit_config.useValgrind:
-                te = ValgrindExecutor(self.lit_config.valgrindArgs, te)
-        self.executor = te
-
-    def configure_target_info(self):
-        self.target_info = make_target_info(self)
-
-    def configure_cxx(self):
-        # Gather various compiler parameters.
-        cxx = self.get_lit_conf('cxx_under_test')
-        self.cxx_is_clang_cl = cxx is not None and \
-                               os.path.basename(cxx) == 'clang-cl.exe'
-        # If no specific cxx_under_test was given, attempt to infer it as
-        # clang++.
-        if cxx is None or self.cxx_is_clang_cl:
-            search_paths = self.config.environment['PATH']
-            if cxx is not None and os.path.isabs(cxx):
-                search_paths = os.path.dirname(cxx)
-            clangxx = libcxx.util.which('clang++', search_paths)
-            if clangxx:
-                cxx = clangxx
-                self.lit_config.note(
-                    "inferred cxx_under_test as: %r" % cxx)
-            elif self.cxx_is_clang_cl:
-                self.lit_config.fatal('Failed to find clang++ substitution for'
-                                      ' clang-cl')
-        if not cxx:
-            self.lit_config.fatal('must specify user parameter cxx_under_test '
-                                  '(e.g., --param=cxx_under_test=clang++)')
-        self.cxx = CXXCompiler(cxx) if not self.cxx_is_clang_cl else \
-                   self._configure_clang_cl(cxx)
-        cxx_type = self.cxx.type
-        if cxx_type is not None:
-            assert self.cxx.version is not None
-            maj_v, min_v, _ = self.cxx.version
-            self.config.available_features.add(cxx_type)
-            self.config.available_features.add('%s-%s' % (cxx_type, maj_v))
-            self.config.available_features.add('%s-%s.%s' % (
-                cxx_type, maj_v, min_v))
-        self.cxx.compile_env = dict(os.environ)
-        # 'CCACHE_CPP2' prevents ccache from stripping comments while
-        # preprocessing. This is required to prevent stripping of '-verify'
-        # comments.
-        self.cxx.compile_env['CCACHE_CPP2'] = '1'
-
-    def _configure_clang_cl(self, clang_path):
-        def _split_env_var(var):
-            return [p.strip() for p in os.environ.get(var, '').split(';') if p.strip()]
-
-        def _prefixed_env_list(var, prefix):
-            from itertools import chain
-            return list(chain.from_iterable((prefix, path) for path in _split_env_var(var)))
-
-        assert self.cxx_is_clang_cl
-        flags = []
-        compile_flags = _prefixed_env_list('INCLUDE', '-isystem')
-        link_flags = _prefixed_env_list('LIB', '-L')
-        for path in _split_env_var('LIB'):
-            self.add_path(self.exec_env, path)
-        return CXXCompiler(clang_path, flags=flags,
-                           compile_flags=compile_flags,
-                           link_flags=link_flags)
-
-
-    def configure_src_root(self):
-        self.libcxx_src_root = self.get_lit_conf(
-            'libcxx_src_root', os.path.dirname(self.config.test_source_root))
-
-    def configure_obj_root(self):
-        self.project_obj_root = self.get_lit_conf('project_obj_root')
-        self.libcxx_obj_root = self.get_lit_conf('libcxx_obj_root')
-        if not self.libcxx_obj_root and self.project_obj_root is not None:
-            possible_root = os.path.join(self.project_obj_root, 'projects', 'libcxx')
-            if os.path.isdir(possible_root):
-                self.libcxx_obj_root = possible_root
-            else:
-                self.libcxx_obj_root = self.project_obj_root
-
-    def configure_cxx_library_root(self):
-        self.cxx_library_root = self.get_lit_conf('cxx_library_root',
-                                                  self.libcxx_obj_root)
-        self.cxx_runtime_root = self.get_lit_conf('cxx_runtime_root',
-                                                   self.cxx_library_root)
-
-    def configure_use_system_cxx_lib(self):
-        # This test suite supports testing against either the system library or
-        # the locally built one; the former mode is useful for testing ABI
-        # compatibility between the current headers and a shipping dynamic
-        # library.
-        # Default to testing against the locally built libc++ library.
-        self.use_system_cxx_lib = self.get_lit_conf('use_system_cxx_lib')
-        if self.use_system_cxx_lib == 'true':
-            self.use_system_cxx_lib = True
-        elif self.use_system_cxx_lib == 'false':
-            self.use_system_cxx_lib = False
-        elif self.use_system_cxx_lib:
-            assert os.path.isdir(self.use_system_cxx_lib)
-        self.lit_config.note(
-            "inferred use_system_cxx_lib as: %r" % self.use_system_cxx_lib)
-
-    def configure_availability(self):
-        # See http://llvm.org/docs/AvailabilityMarkup.html
-        self.with_availability = self.get_lit_bool('with_availability', False)
-        self.lit_config.note(
-            "inferred with_availability as: %r" % self.with_availability)
-
-    def configure_cxx_stdlib_under_test(self):
-        self.cxx_stdlib_under_test = self.get_lit_conf(
-            'cxx_stdlib_under_test', 'libc++')
-        if self.cxx_stdlib_under_test not in \
-                ['libc++', 'libstdc++', 'msvc', 'cxx_default']:
-            self.lit_config.fatal(
-                'unsupported value for "cxx_stdlib_under_test": %s'
-                % self.cxx_stdlib_under_test)
-        self.config.available_features.add(self.cxx_stdlib_under_test)
-        if self.cxx_stdlib_under_test == 'libstdc++':
-            self.config.available_features.add('libstdc++')
-            # Manually enable the experimental and filesystem tests for libstdc++
-            # if the options aren't present.
-            # FIXME this is a hack.
-            if self.get_lit_conf('enable_experimental') is None:
-                self.config.enable_experimental = 'true'
-            if self.get_lit_conf('enable_filesystem') is None:
-                self.config.enable_filesystem = 'true'
-
-    def configure_use_clang_verify(self):
-        '''If set, run clang with -verify on failing tests.'''
-        if self.with_availability:
-            self.use_clang_verify = False
-            return
-        self.use_clang_verify = self.get_lit_bool('use_clang_verify')
-        if self.use_clang_verify is None:
-            # NOTE: We do not test for the -verify flag directly because
-            #   -verify will always exit with non-zero on an empty file.
-            self.use_clang_verify = self.cxx.isVerifySupported()
-            self.lit_config.note(
-                "inferred use_clang_verify as: %r" % self.use_clang_verify)
-        if self.use_clang_verify:
-                self.config.available_features.add('verify-support')
-
-    def configure_use_thread_safety(self):
-        '''If set, run clang with -verify on failing tests.'''
-        has_thread_safety = self.cxx.hasCompileFlag('-Werror=thread-safety')
-        if has_thread_safety:
-            self.cxx.compile_flags += ['-Werror=thread-safety']
-            self.config.available_features.add('thread-safety')
-            self.lit_config.note("enabling thread-safety annotations")
-
-    def configure_execute_external(self):
-        # Choose between lit's internal shell pipeline runner and a real shell.
-        # If LIT_USE_INTERNAL_SHELL is in the environment, we use that as the
-        # default value. Otherwise we ask the target_info.
-        use_lit_shell_default = os.environ.get('LIT_USE_INTERNAL_SHELL')
-        if use_lit_shell_default is not None:
-            use_lit_shell_default = use_lit_shell_default != '0'
-        else:
-            use_lit_shell_default = self.target_info.use_lit_shell_default()
-        # Check for the command line parameter using the default value if it is
-        # not present.
-        use_lit_shell = self.get_lit_bool('use_lit_shell',
-                                          use_lit_shell_default)
-        self.execute_external = not use_lit_shell
-
-    def configure_ccache(self):
-        use_ccache_default = os.environ.get('LIBCXX_USE_CCACHE') is not None
-        use_ccache = self.get_lit_bool('use_ccache', use_ccache_default)
-        if use_ccache:
-            self.cxx.use_ccache = True
-            self.lit_config.note('enabling ccache')
-
-    def add_deployment_feature(self, feature):
-        (arch, name, version) = self.config.deployment
-        self.config.available_features.add('%s=%s-%s' % (feature, arch, name))
-        self.config.available_features.add('%s=%s' % (feature, name))
-        self.config.available_features.add('%s=%s%s' % (feature, name, version))
-
-    def configure_features(self):
-        additional_features = self.get_lit_conf('additional_features')
-        if additional_features:
-            for f in additional_features.split(','):
-                self.config.available_features.add(f.strip())
-        self.target_info.add_locale_features(self.config.available_features)
-
-        target_platform = self.target_info.platform()
-
-        # Write an "available feature" that combines the triple when
-        # use_system_cxx_lib is enabled. This is so that we can easily write
-        # XFAIL markers for tests that are known to fail with versions of
-        # libc++ as were shipped with a particular triple.
-        if self.use_system_cxx_lib:
-            self.config.available_features.add('with_system_cxx_lib')
-            self.config.available_features.add(
-                'with_system_cxx_lib=%s' % self.config.target_triple)
-
-            # Add subcomponents individually.
-            target_components = self.config.target_triple.split('-')
-            for component in target_components:
-                self.config.available_features.add(
-                    'with_system_cxx_lib=%s' % component)
-
-            # Add available features for more generic versions of the target
-            # triple attached to  with_system_cxx_lib.
-            if self.use_deployment:
-                self.add_deployment_feature('with_system_cxx_lib')
-
-        # Configure the availability markup checks features.
-        if self.with_availability:
-            self.config.available_features.add('availability_markup')
-            self.add_deployment_feature('availability_markup')
-
-        if self.use_system_cxx_lib or self.with_availability:
-            self.config.available_features.add('availability')
-            self.add_deployment_feature('availability')
-
-        if platform.system() == 'Darwin':
-            self.config.available_features.add('apple-darwin')
-
-        # Insert the platform name into the available features as a lower case.
-        self.config.available_features.add(target_platform)
-
-        # Simulator testing can take a really long time for some of these tests
-        # so add a feature check so we can REQUIRES: long_tests in them
-        self.long_tests = self.get_lit_bool('long_tests')
-        if self.long_tests is None:
-            # Default to running long tests.
-            self.long_tests = True
-            self.lit_config.note(
-                "inferred long_tests as: %r" % self.long_tests)
-
-        if self.long_tests:
-            self.config.available_features.add('long_tests')
-
-        # Run a compile test for the -fsized-deallocation flag. This is needed
-        # in test/std/language.support/support.dynamic/new.delete
-        if self.cxx.hasCompileFlag('-fsized-deallocation'):
-            self.config.available_features.add('fsized-deallocation')
-
-        if self.cxx.hasCompileFlag('-faligned-allocation'):
-            self.config.available_features.add('-faligned-allocation')
-        else:
-            # FIXME remove this once more than just clang-4.0 support
-            # C++17 aligned allocation.
-            self.config.available_features.add('no-aligned-allocation')
-
-        if self.get_lit_bool('has_libatomic', False):
-            self.config.available_features.add('libatomic')
-
-        macros = self.cxx.dumpMacros()
-        if '__cpp_if_constexpr' not in macros:
-            self.config.available_features.add('libcpp-no-if-constexpr')
-
-        if '__cpp_structured_bindings' not in macros:
-            self.config.available_features.add('libcpp-no-structured-bindings')
-
-        if '__cpp_deduction_guides' not in macros:
-            self.config.available_features.add('libcpp-no-deduction-guides')
-
-        if self.is_windows:
-            self.config.available_features.add('windows')
-            if self.cxx_stdlib_under_test == 'libc++':
-                # LIBCXX-WINDOWS-FIXME is the feature name used to XFAIL the
-                # initial Windows failures until they can be properly diagnosed
-                # and fixed. This allows easier detection of new test failures
-                # and regressions. Note: New failures should not be suppressed
-                # using this feature. (Also see llvm.org/PR32730)
-                self.config.available_features.add('LIBCXX-WINDOWS-FIXME')
-
-        # Attempt to detect the glibc version by querying for __GLIBC__
-        # in 'features.h'.
-        macros = self.cxx.dumpMacros(flags=['-include', 'features.h'])
-        if macros is not None and '__GLIBC__' in macros:
-            maj_v, min_v = (macros['__GLIBC__'], macros['__GLIBC_MINOR__'])
-            self.config.available_features.add('glibc')
-            self.config.available_features.add('glibc-%s' % maj_v)
-            self.config.available_features.add('glibc-%s.%s' % (maj_v, min_v))
-
-    def configure_compile_flags(self):
-        no_default_flags = self.get_lit_bool('no_default_flags', False)
-        if not no_default_flags:
-            self.configure_default_compile_flags()
-        # This include is always needed so add so add it regardless of
-        # 'no_default_flags'.
-        support_path = os.path.join(self.libcxx_src_root, 'test/support')
-        self.cxx.compile_flags += ['-I' + support_path]
-        # Configure extra flags
-        compile_flags_str = self.get_lit_conf('compile_flags', '')
-        self.cxx.compile_flags += shlex.split(compile_flags_str)
-        # FIXME: Can we remove this?
-        if self.is_windows:
-            self.cxx.compile_flags += ['-D_CRT_SECURE_NO_WARNINGS']
-
-    def configure_default_compile_flags(self):
-        # Try and get the std version from the command line. Fall back to
-        # default given in lit.site.cfg is not present. If default is not
-        # present then force c++11.
-        std = self.get_lit_conf('std')
-        if not std:
-            # Choose the newest possible language dialect if none is given.
-            possible_stds = ['c++1z', 'c++14', 'c++11', 'c++03']
-            if self.cxx.type == 'gcc':
-                maj_v, _, _ = self.cxx.version
-                maj_v = int(maj_v)
-                if maj_v < 7:
-                    possible_stds.remove('c++1z')
-                # FIXME: How many C++14 tests actually fail under GCC 5 and 6?
-                # Should we XFAIL them individually instead?
-                if maj_v <= 6:
-                    possible_stds.remove('c++14')
-            for s in possible_stds:
-                if self.cxx.hasCompileFlag('-std=%s' % s):
-                    std = s
-                    self.lit_config.note(
-                        'inferred language dialect as: %s' % std)
-                    break
-            if not std:
-                self.lit_config.fatal(
-                    'Failed to infer a supported language dialect from one of %r'
-                    % possible_stds)
-        self.cxx.compile_flags += ['-std={0}'.format(std)]
-        self.config.available_features.add(std.replace('gnu++', 'c++'))
-        # Configure include paths
-        self.configure_compile_flags_header_includes()
-        self.target_info.add_cxx_compile_flags(self.cxx.compile_flags)
-        # Configure feature flags.
-        self.configure_compile_flags_exceptions()
-        self.configure_compile_flags_rtti()
-        self.configure_compile_flags_abi_version()
-        enable_32bit = self.get_lit_bool('enable_32bit', False)
-        if enable_32bit:
-            self.cxx.flags += ['-m32']
-        # Use verbose output for better errors
-        self.cxx.flags += ['-v']
-        sysroot = self.get_lit_conf('sysroot')
-        if sysroot:
-            self.cxx.flags += ['--sysroot', sysroot]
-        gcc_toolchain = self.get_lit_conf('gcc_toolchain')
-        if gcc_toolchain:
-            self.cxx.flags += ['-gcc-toolchain', gcc_toolchain]
-        # NOTE: the _DEBUG definition must preceed the triple check because for
-        # the Windows build of libc++, the forced inclusion of a header requires
-        # that _DEBUG is defined.  Incorrect ordering will result in -target
-        # being elided.
-        if self.is_windows and self.debug_build:
-            self.cxx.compile_flags += ['-D_DEBUG']
-        if self.use_target:
-            if not self.cxx.addFlagIfSupported(
-                    ['-target', self.config.target_triple]):
-                self.lit_config.warning('use_target is true but -target is '\
-                        'not supported by the compiler')
-        if self.use_deployment:
-            arch, name, version = self.config.deployment
-            self.cxx.flags += ['-arch', arch]
-            self.cxx.flags += ['-m' + name + '-version-min=' + version]
-
-        # Disable availability unless explicitely requested
-        if not self.with_availability:
-            self.cxx.flags += ['-D_LIBCPP_DISABLE_AVAILABILITY']
-
-    def configure_compile_flags_header_includes(self):
-        support_path = os.path.join(self.libcxx_src_root, 'test', 'support')
-        if self.cxx_stdlib_under_test != 'libstdc++' and \
-           not self.is_windows:
-            self.cxx.compile_flags += [
-                '-include', os.path.join(support_path, 'nasty_macros.hpp')]
-        if self.cxx_stdlib_under_test == 'msvc':
-            self.cxx.compile_flags += [
-                '-include', os.path.join(support_path,
-                                         'msvc_stdlib_force_include.hpp')]
-            pass
-        if self.is_windows and self.debug_build and \
-                self.cxx_stdlib_under_test != 'msvc':
-            self.cxx.compile_flags += [
-                '-include', os.path.join(support_path,
-                                         'set_windows_crt_report_mode.h')
-            ]
-        self.configure_config_site_header()
-        cxx_headers = self.get_lit_conf('cxx_headers')
-        if cxx_headers == '' or (cxx_headers is None
-                                 and self.cxx_stdlib_under_test != 'libc++'):
-            self.lit_config.note('using the system cxx headers')
-            return
-        self.cxx.compile_flags += ['-nostdinc++']
-        if cxx_headers is None:
-            cxx_headers = os.path.join(self.libcxx_src_root, 'include')
-        if not os.path.isdir(cxx_headers):
-            self.lit_config.fatal("cxx_headers='%s' is not a directory."
-                                  % cxx_headers)
-        self.cxx.compile_flags += ['-I' + cxx_headers]
-        if self.libcxx_obj_root is not None:
-            cxxabi_headers = os.path.join(self.libcxx_obj_root, 'include',
-                                          'c++build')
-            if os.path.isdir(cxxabi_headers):
-                self.cxx.compile_flags += ['-I' + cxxabi_headers]
-
-    def configure_config_site_header(self):
-        # Check for a possible __config_site in the build directory. We
-        # use this if it exists.
-        if self.libcxx_obj_root is None:
-            return
-        config_site_header = os.path.join(self.libcxx_obj_root, '__config_site')
-        if not os.path.isfile(config_site_header):
-            return
-        contained_macros = self.parse_config_site_and_add_features(
-            config_site_header)
-        self.lit_config.note('Using __config_site header %s with macros: %r'
-            % (config_site_header, contained_macros))
-        # FIXME: This must come after the call to
-        # 'parse_config_site_and_add_features(...)' in order for it to work.
-        self.cxx.compile_flags += ['-include', config_site_header]
-
-    def parse_config_site_and_add_features(self, header):
-        """ parse_config_site_and_add_features - Deduce and add the test
-            features that that are implied by the #define's in the __config_site
-            header. Return a dictionary containing the macros found in the
-            '__config_site' header.
-        """
-        # Parse the macro contents of __config_site by dumping the macros
-        # using 'c++ -dM -E' and filtering the predefines.
-        predefines = self.cxx.dumpMacros()
-        macros = self.cxx.dumpMacros(header)
-        feature_macros_keys = set(macros.keys()) - set(predefines.keys())
-        feature_macros = {}
-        for k in feature_macros_keys:
-            feature_macros[k] = macros[k]
-        # We expect the header guard to be one of the definitions
-        assert '_LIBCPP_CONFIG_SITE' in feature_macros
-        del feature_macros['_LIBCPP_CONFIG_SITE']
-        # The __config_site header should be non-empty. Otherwise it should
-        # have never been emitted by CMake.
-        assert len(feature_macros) > 0
-        # Transform each macro name into the feature name used in the tests.
-        # Ex. _LIBCPP_HAS_NO_THREADS -> libcpp-has-no-threads
-        for m in feature_macros:
-            if m == '_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS':
-                continue
-            if m == '_LIBCPP_ABI_VERSION':
-                self.config.available_features.add('libcpp-abi-version-v%s'
-                    % feature_macros[m])
-                continue
-            assert m.startswith('_LIBCPP_HAS_') or m == '_LIBCPP_ABI_UNSTABLE'
-            m = m.lower()[1:].replace('_', '-')
-            self.config.available_features.add(m)
-        return feature_macros
-
-
-
-    def configure_compile_flags_exceptions(self):
-        enable_exceptions = self.get_lit_bool('enable_exceptions', True)
-        if not enable_exceptions:
-            self.config.available_features.add('libcpp-no-exceptions')
-            self.cxx.compile_flags += ['-fno-exceptions']
-
-    def configure_compile_flags_rtti(self):
-        enable_rtti = self.get_lit_bool('enable_rtti', True)
-        if not enable_rtti:
-            self.config.available_features.add('libcpp-no-rtti')
-            self.cxx.compile_flags += ['-fno-rtti', '-D_LIBCPP_NO_RTTI']
-
-    def configure_compile_flags_abi_version(self):
-        abi_version = self.get_lit_conf('abi_version', '').strip()
-        abi_unstable = self.get_lit_bool('abi_unstable')
-        # Only add the ABI version when it is non-default.
-        # FIXME(EricWF): Get the ABI version from the "__config_site".
-        if abi_version and abi_version != '1':
-          self.cxx.compile_flags += ['-D_LIBCPP_ABI_VERSION=' + abi_version]
-        if abi_unstable:
-          self.config.available_features.add('libcpp-abi-unstable')
-          self.cxx.compile_flags += ['-D_LIBCPP_ABI_UNSTABLE']
-
-    def configure_filesystem_compile_flags(self):
-        enable_fs = self.get_lit_bool('enable_filesystem', default=False)
-        if not enable_fs:
-            return
-        enable_experimental = self.get_lit_bool('enable_experimental', default=False)
-        if not enable_experimental:
-            self.lit_config.fatal(
-                'filesystem is enabled but libc++experimental.a is not.')
-        self.config.available_features.add('c++filesystem')
-        static_env = os.path.join(self.libcxx_src_root, 'test', 'std',
-                                  'experimental', 'filesystem', 'Inputs', 'static_test_env')
-        static_env = os.path.realpath(static_env)
-        assert os.path.isdir(static_env)
-        self.cxx.compile_flags += ['-DLIBCXX_FILESYSTEM_STATIC_TEST_ROOT="%s"' % static_env]
-
-        dynamic_env = os.path.join(self.config.test_exec_root,
-                                   'filesystem', 'Output', 'dynamic_env')
-        dynamic_env = os.path.realpath(dynamic_env)
-        if not os.path.isdir(dynamic_env):
-            os.makedirs(dynamic_env)
-        self.cxx.compile_flags += ['-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT="%s"' % dynamic_env]
-        self.exec_env['LIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT'] = ("%s" % dynamic_env)
-
-        dynamic_helper = os.path.join(self.libcxx_src_root, 'test', 'support',
-                                      'filesystem_dynamic_test_helper.py')
-        assert os.path.isfile(dynamic_helper)
-
-        self.cxx.compile_flags += ['-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_HELPER="%s %s"'
-                                   % (sys.executable, dynamic_helper)]
-
-
-    def configure_link_flags(self):
-        no_default_flags = self.get_lit_bool('no_default_flags', False)
-        if not no_default_flags:
-            # Configure library path
-            self.configure_link_flags_cxx_library_path()
-            self.configure_link_flags_abi_library_path()
-
-            # Configure libraries
-            if self.cxx_stdlib_under_test == 'libc++':
-                self.cxx.link_flags += ['-nodefaultlibs']
-                # FIXME: Handle MSVCRT as part of the ABI library handling.
-                if self.is_windows:
-                    self.cxx.link_flags += ['-nostdlib']
-                self.configure_link_flags_cxx_library()
-                self.configure_link_flags_abi_library()
-                self.configure_extra_library_flags()
-            elif self.cxx_stdlib_under_test == 'libstdc++':
-                enable_fs = self.get_lit_bool('enable_filesystem',
-                                              default=False)
-                if enable_fs:
-                    self.config.available_features.add('c++experimental')
-                    self.cxx.link_flags += ['-lstdc++fs']
-                self.cxx.link_flags += ['-lm', '-pthread']
-            elif self.cxx_stdlib_under_test == 'msvc':
-                # FIXME: Correctly setup debug/release flags here.
-                pass
-            elif self.cxx_stdlib_under_test == 'cxx_default':
-                self.cxx.link_flags += ['-pthread']
-            else:
-                self.lit_config.fatal(
-                    'unsupported value for "use_stdlib_type": %s'
-                    %  use_stdlib_type)
-
-        link_flags_str = self.get_lit_conf('link_flags', '')
-        self.cxx.link_flags += shlex.split(link_flags_str)
-
-    def configure_link_flags_cxx_library_path(self):
-        if not self.use_system_cxx_lib:
-            if self.cxx_library_root:
-                self.cxx.link_flags += ['-L' + self.cxx_library_root]
-                if self.is_windows and self.link_shared:
-                    self.add_path(self.cxx.compile_env, self.cxx_library_root)
-            if self.cxx_runtime_root:
-                if not self.is_windows:
-                    self.cxx.link_flags += ['-Wl,-rpath,' +
-                                            self.cxx_runtime_root]
-                elif self.is_windows and self.link_shared:
-                    self.add_path(self.exec_env, self.cxx_runtime_root)
-        elif os.path.isdir(str(self.use_system_cxx_lib)):
-            self.cxx.link_flags += ['-L' + self.use_system_cxx_lib]
-            if not self.is_windows:
-                self.cxx.link_flags += ['-Wl,-rpath,' +
-                                        self.use_system_cxx_lib]
-            if self.is_windows and self.link_shared:
-                self.add_path(self.cxx.compile_env, self.use_system_cxx_lib)
-
-    def configure_link_flags_abi_library_path(self):
-        # Configure ABI library paths.
-        self.abi_library_root = self.get_lit_conf('abi_library_path')
-        if self.abi_library_root:
-            self.cxx.link_flags += ['-L' + self.abi_library_root]
-            if not self.is_windows:
-                self.cxx.link_flags += ['-Wl,-rpath,' + self.abi_library_root]
-            else:
-                self.add_path(self.exec_env, self.abi_library_root)
-
-    def configure_link_flags_cxx_library(self):
-        libcxx_experimental = self.get_lit_bool('enable_experimental', default=False)
-        if libcxx_experimental:
-            self.config.available_features.add('c++experimental')
-            self.cxx.link_flags += ['-lc++experimental']
-        if self.link_shared:
-            self.cxx.link_flags += ['-lc++']
-        else:
-            cxx_library_root = self.get_lit_conf('cxx_library_root')
-            if cxx_library_root:
-                libname = self.make_static_lib_name('c++')
-                abs_path = os.path.join(cxx_library_root, libname)
-                assert os.path.exists(abs_path) and \
-                       "static libc++ library does not exist"
-                self.cxx.link_flags += [abs_path]
-            else:
-                self.cxx.link_flags += ['-lc++']
-
-    def configure_link_flags_abi_library(self):
-        cxx_abi = self.get_lit_conf('cxx_abi', 'libcxxabi')
-        if cxx_abi == 'libstdc++':
-            self.cxx.link_flags += ['-lstdc++']
-        elif cxx_abi == 'libsupc++':
-            self.cxx.link_flags += ['-lsupc++']
-        elif cxx_abi == 'libcxxabi':
-            if self.target_info.allow_cxxabi_link():
-                libcxxabi_shared = self.get_lit_bool('libcxxabi_shared', default=True)
-                if libcxxabi_shared:
-                    self.cxx.link_flags += ['-lc++abi']
-                else:
-                    cxxabi_library_root = self.get_lit_conf('abi_library_path')
-                    if cxxabi_library_root:
-                        libname = self.make_static_lib_name('c++abi')
-                        abs_path = os.path.join(cxxabi_library_root, libname)
-                        self.cxx.link_flags += [abs_path]
-                    else:
-                        self.cxx.link_flags += ['-lc++abi']
-        elif cxx_abi == 'libcxxrt':
-            self.cxx.link_flags += ['-lcxxrt']
-        elif cxx_abi == 'vcruntime':
-            debug_suffix = 'd' if self.debug_build else ''
-            self.cxx.link_flags += ['-l%s%s' % (lib, debug_suffix) for lib in
-                                    ['vcruntime', 'ucrt', 'msvcrt']]
-        elif cxx_abi == 'none' or cxx_abi == 'default':
-            if self.is_windows:
-                debug_suffix = 'd' if self.debug_build else ''
-                self.cxx.link_flags += ['-lmsvcrt%s' % debug_suffix]
-        else:
-            self.lit_config.fatal(
-                'C++ ABI setting %s unsupported for tests' % cxx_abi)
-
-    def configure_extra_library_flags(self):
-        if self.get_lit_bool('cxx_ext_threads', default=False):
-            self.cxx.link_flags += ['-lc++external_threads']
-        self.target_info.add_cxx_link_flags(self.cxx.link_flags)
-
-    def configure_color_diagnostics(self):
-        use_color = self.get_lit_conf('color_diagnostics')
-        if use_color is None:
-            use_color = os.environ.get('LIBCXX_COLOR_DIAGNOSTICS')
-        if use_color is None:
-            return
-        if use_color != '':
-            self.lit_config.fatal('Invalid value for color_diagnostics "%s".'
-                                  % use_color)
-        color_flag = '-fdiagnostics-color=always'
-        # Check if the compiler supports the color diagnostics flag. Issue a
-        # warning if it does not since color diagnostics have been requested.
-        if not self.cxx.hasCompileFlag(color_flag):
-            self.lit_config.warning(
-                'color diagnostics have been requested but are not supported '
-                'by the compiler')
-        else:
-            self.cxx.flags += [color_flag]
-
-    def configure_debug_mode(self):
-        debug_level = self.get_lit_conf('debug_level', None)
-        if not debug_level:
-            return
-        if debug_level not in ['0', '1']:
-            self.lit_config.fatal('Invalid value for debug_level "%s".'
-                                  % debug_level)
-        self.cxx.compile_flags += ['-D_LIBCPP_DEBUG=%s' % debug_level]
-
-    def configure_warnings(self):
-        # Turn on warnings by default for Clang based compilers when C++ >= 11
-        default_enable_warnings = self.cxx.type in ['clang', 'apple-clang'] \
-            and len(self.config.available_features.intersection(
-                ['c++11', 'c++14', 'c++1z'])) != 0
-        enable_warnings = self.get_lit_bool('enable_warnings',
-                                            default_enable_warnings)
-        self.cxx.useWarnings(enable_warnings)
-        self.cxx.warning_flags += [
-            '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER',
-            '-Wall', '-Wextra', '-Werror'
-        ]
-        if self.cxx.hasWarningFlag('-Wuser-defined-warnings'):
-            self.cxx.warning_flags += ['-Wuser-defined-warnings']
-            self.config.available_features.add('diagnose-if-support')
-        self.cxx.addWarningFlagIfSupported('-Wshadow')
-        self.cxx.addWarningFlagIfSupported('-Wno-unused-command-line-argument')
-        self.cxx.addWarningFlagIfSupported('-Wno-attributes')
-        self.cxx.addWarningFlagIfSupported('-Wno-pessimizing-move')
-        self.cxx.addWarningFlagIfSupported('-Wno-c++11-extensions')
-        self.cxx.addWarningFlagIfSupported('-Wno-user-defined-literals')
-        self.cxx.addWarningFlagIfSupported('-Wno-noexcept-type')
-        # These warnings should be enabled in order to support the MSVC
-        # team using the test suite; They enable the warnings below and
-        # expect the test suite to be clean.
-        self.cxx.addWarningFlagIfSupported('-Wsign-compare')
-        self.cxx.addWarningFlagIfSupported('-Wunused-variable')
-        self.cxx.addWarningFlagIfSupported('-Wunused-parameter')
-        self.cxx.addWarningFlagIfSupported('-Wunreachable-code')
-        # FIXME: Enable the two warnings below.
-        self.cxx.addWarningFlagIfSupported('-Wno-conversion')
-        self.cxx.addWarningFlagIfSupported('-Wno-unused-local-typedef')
-        std = self.get_lit_conf('std', None)
-        if std in ['c++98', 'c++03']:
-            # The '#define static_assert' provided by libc++ in C++03 mode
-            # causes an unused local typedef whenever it is used.
-            self.cxx.addWarningFlagIfSupported('-Wno-unused-local-typedef')
-
-    def configure_sanitizer(self):
-        san = self.get_lit_conf('use_sanitizer', '').strip()
-        if san:
-            self.target_info.add_sanitizer_features(san, self.config.available_features)
-            # Search for llvm-symbolizer along the compiler path first
-            # and then along the PATH env variable.
-            symbolizer_search_paths = os.environ.get('PATH', '')
-            cxx_path = libcxx.util.which(self.cxx.path)
-            if cxx_path is not None:
-                symbolizer_search_paths = (
-                    os.path.dirname(cxx_path) +
-                    os.pathsep + symbolizer_search_paths)
-            llvm_symbolizer = libcxx.util.which('llvm-symbolizer',
-                                                symbolizer_search_paths)
-
-            def add_ubsan():
-                self.cxx.flags += ['-fsanitize=undefined',
-                                   '-fno-sanitize=vptr,function,float-divide-by-zero',
-                                   '-fno-sanitize-recover=all']
-                self.exec_env['UBSAN_OPTIONS'] = 'print_stacktrace=1'
-                self.config.available_features.add('ubsan')
-
-            # Setup the sanitizer compile flags
-            self.cxx.flags += ['-g', '-fno-omit-frame-pointer']
-            if san == 'Address' or san == 'Address;Undefined' or san == 'Undefined;Address':
-                self.cxx.flags += ['-fsanitize=address']
-                if llvm_symbolizer is not None:
-                    self.exec_env['ASAN_SYMBOLIZER_PATH'] = llvm_symbolizer
-                # FIXME: Turn ODR violation back on after PR28391 is resolved
-                # https://bugs.llvm.org/show_bug.cgi?id=28391
-                self.exec_env['ASAN_OPTIONS'] = 'detect_odr_violation=0'
-                self.config.available_features.add('asan')
-                self.config.available_features.add('sanitizer-new-delete')
-                self.cxx.compile_flags += ['-O1']
-                if san == 'Address;Undefined' or san == 'Undefined;Address':
-                    add_ubsan()
-            elif san == 'Memory' or san == 'MemoryWithOrigins':
-                self.cxx.flags += ['-fsanitize=memory']
-                if san == 'MemoryWithOrigins':
-                    self.cxx.compile_flags += [
-                        '-fsanitize-memory-track-origins']
-                if llvm_symbolizer is not None:
-                    self.exec_env['MSAN_SYMBOLIZER_PATH'] = llvm_symbolizer
-                self.config.available_features.add('msan')
-                self.config.available_features.add('sanitizer-new-delete')
-                self.cxx.compile_flags += ['-O1']
-            elif san == 'Undefined':
-                add_ubsan()
-                self.cxx.compile_flags += ['-O2']
-            elif san == 'Thread':
-                self.cxx.flags += ['-fsanitize=thread']
-                self.config.available_features.add('tsan')
-                self.config.available_features.add('sanitizer-new-delete')
-            else:
-                self.lit_config.fatal('unsupported value for '
-                                      'use_sanitizer: {0}'.format(san))
-            san_lib = self.get_lit_conf('sanitizer_library')
-            if san_lib:
-                self.cxx.link_flags += [
-                    san_lib, '-Wl,-rpath,%s' % os.path.dirname(san_lib)]
-
-    def configure_coverage(self):
-        self.generate_coverage = self.get_lit_bool('generate_coverage', False)
-        if self.generate_coverage:
-            self.cxx.flags += ['-g', '--coverage']
-            self.cxx.compile_flags += ['-O0']
-
-    def configure_modules(self):
-        modules_flags = ['-fmodules']
-        if platform.system() != 'Darwin':
-            modules_flags += ['-Xclang', '-fmodules-local-submodule-visibility']
-        supports_modules = self.cxx.hasCompileFlag(modules_flags)
-        enable_modules = self.get_lit_bool('enable_modules',
-                                           default=False,
-                                           env_var='LIBCXX_ENABLE_MODULES')
-        if enable_modules and not supports_modules:
-            self.lit_config.fatal(
-                '-fmodules is enabled but not supported by the compiler')
-        if not supports_modules:
-            return
-        self.config.available_features.add('modules-support')
-        module_cache = os.path.join(self.config.test_exec_root,
-                                   'modules.cache')
-        module_cache = os.path.realpath(module_cache)
-        if os.path.isdir(module_cache):
-            shutil.rmtree(module_cache)
-        os.makedirs(module_cache)
-        self.cxx.modules_flags = modules_flags + \
-            ['-fmodules-cache-path=' + module_cache]
-        if enable_modules:
-            self.config.available_features.add('-fmodules')
-            self.cxx.useModules()
-
-    def configure_substitutions(self):
-        sub = self.config.substitutions
-        cxx_path = pipes.quote(self.cxx.path)
-        # Configure compiler substitutions
-        sub.append(('%cxx', cxx_path))
-        # Configure flags substitutions
-        flags_str = ' '.join([pipes.quote(f) for f in self.cxx.flags])
-        compile_flags_str = ' '.join([pipes.quote(f) for f in self.cxx.compile_flags])
-        link_flags_str = ' '.join([pipes.quote(f) for f in self.cxx.link_flags])
-        all_flags = '%s %s %s' % (flags_str, compile_flags_str, link_flags_str)
-        sub.append(('%flags', flags_str))
-        sub.append(('%compile_flags', compile_flags_str))
-        sub.append(('%link_flags', link_flags_str))
-        sub.append(('%all_flags', all_flags))
-        if self.cxx.isVerifySupported():
-            verify_str = ' ' + ' '.join(self.cxx.verify_flags) + ' '
-            sub.append(('%verify', verify_str))
-        # Add compile and link shortcuts
-        compile_str = (cxx_path + ' -o %t.o %s -c ' + flags_str
-                       + ' ' + compile_flags_str)
-        link_str = (cxx_path + ' -o %t.exe %t.o ' + flags_str + ' '
-                    + link_flags_str)
-        assert type(link_str) is str
-        build_str = cxx_path + ' -o %t.exe %s ' + all_flags
-        if self.cxx.use_modules:
-            sub.append(('%compile_module', compile_str))
-            sub.append(('%build_module', build_str))
-        elif self.cxx.modules_flags is not None:
-            modules_str = ' '.join(self.cxx.modules_flags) + ' '
-            sub.append(('%compile_module', compile_str + ' ' + modules_str))
-            sub.append(('%build_module', build_str + ' ' + modules_str))
-        sub.append(('%compile', compile_str))
-        sub.append(('%link', link_str))
-        sub.append(('%build', build_str))
-        # Configure exec prefix substitutions.
-        exec_env_str = ''
-        if not self.is_windows and len(self.exec_env) != 0:
-            exec_env_str = 'env '
-            for k, v in self.exec_env.items():
-                exec_env_str += ' %s=%s' % (k, v)
-        # Configure run env substitution.
-        exec_str = exec_env_str
-        if self.lit_config.useValgrind:
-            exec_str = ' '.join(self.lit_config.valgrindArgs) + exec_env_str
-        sub.append(('%exec', exec_str))
-        # Configure run shortcut
-        sub.append(('%run', exec_str + ' %t.exe'))
-        # Configure not program substitutions
-        not_py = os.path.join(self.libcxx_src_root, 'utils', 'not.py')
-        not_str = '%s %s ' % (pipes.quote(sys.executable), pipes.quote(not_py))
-        sub.append(('not ', not_str))
-
-    def can_use_deployment(self):
-        # Check if the host is on an Apple platform using clang.
-        if not self.target_info.platform() == "darwin":
-            return False
-        if not self.target_info.is_host_macosx():
-            return False
-        if not self.cxx.type.endswith('clang'):
-            return False
-        return True
-
-    def configure_triple(self):
-        # Get or infer the target triple.
-        target_triple = self.get_lit_conf('target_triple')
-        self.use_target = self.get_lit_bool('use_target', False)
-        if self.use_target and target_triple:
-            self.lit_config.warning('use_target is true but no triple is specified')
-
-        # Use deployment if possible.
-        self.use_deployment = not self.use_target and self.can_use_deployment()
-        if self.use_deployment:
-            return
-
-        # Save the triple (and warn on Apple platforms).
-        self.config.target_triple = target_triple
-        if self.use_target and 'apple' in target_triple:
-            self.lit_config.warning('consider using arch and platform instead'
-                                    ' of target_triple on Apple platforms')
-
-        # If no target triple was given, try to infer it from the compiler
-        # under test.
-        if not self.config.target_triple:
-            target_triple = self.cxx.getTriple()
-            # Drop sub-major version components from the triple, because the
-            # current XFAIL handling expects exact matches for feature checks.
-            # Example: x86_64-apple-darwin14.0.0 -> x86_64-apple-darwin14
-            # The 5th group handles triples greater than 3 parts
-            # (ex x86_64-pc-linux-gnu).
-            target_triple = re.sub(r'([^-]+)-([^-]+)-([^.]+)([^-]*)(.*)',
-                                   r'\1-\2-\3\5', target_triple)
-            # linux-gnu is needed in the triple to properly identify linuxes
-            # that use GLIBC. Handle redhat and opensuse triples as special
-            # cases and append the missing `-gnu` portion.
-            if (target_triple.endswith('redhat-linux') or
-                target_triple.endswith('suse-linux')):
-                target_triple += '-gnu'
-            self.config.target_triple = target_triple
-            self.lit_config.note(
-                "inferred target_triple as: %r" % self.config.target_triple)
-
-    def configure_deployment(self):
-        assert not self.use_deployment is None
-        assert not self.use_target is None
-        if not self.use_deployment:
-            # Warn about ignored parameters.
-            if self.get_lit_conf('arch'):
-                self.lit_config.warning('ignoring arch, using target_triple')
-            if self.get_lit_conf('platform'):
-                self.lit_config.warning('ignoring platform, using target_triple')
-            return
-
-        assert not self.use_target
-        assert self.target_info.is_host_macosx()
-
-        # Always specify deployment explicitly on Apple platforms, since
-        # otherwise a platform is picked up from the SDK.  If the SDK version
-        # doesn't match the system version, tests that use the system library
-        # may fail spuriously.
-        arch = self.get_lit_conf('arch')
-        if not arch:
-            arch = self.cxx.getTriple().split('-', 1)[0]
-            self.lit_config.note("inferred arch as: %r" % arch)
-
-        inferred_platform, name, version = self.target_info.get_platform()
-        if inferred_platform:
-            self.lit_config.note("inferred platform as: %r" % (name + version))
-        self.config.deployment = (arch, name, version)
-
-        # Set the target triple for use by lit.
-        self.config.target_triple = arch + '-apple-' + name + version
-        self.lit_config.note(
-            "computed target_triple as: %r" % self.config.target_triple)
-
-    def configure_env(self):
-        self.target_info.configure_env(self.exec_env)
-
-    def add_path(self, dest_env, new_path):
-        if 'PATH' not in dest_env:
-            dest_env['PATH'] = new_path
-        else:
-            split_char = ';' if self.is_windows else ':'
-            dest_env['PATH'] = '%s%s%s' % (new_path, split_char,
-                                           dest_env['PATH'])
+#===----------------------------------------------------------------------===##\r
+#\r
+#                     The LLVM Compiler Infrastructure\r
+#\r
+# This file is dual licensed under the MIT and the University of Illinois Open\r
+# Source Licenses. See LICENSE.TXT for details.\r
+#\r
+#===----------------------------------------------------------------------===##\r
+\r
+import locale\r
+import os\r
+import platform\r
+import pkgutil\r
+import pipes\r
+import re\r
+import shlex\r
+import shutil\r
+import sys\r
+\r
+from libcxx.compiler import CXXCompiler\r
+from libcxx.test.target_info import make_target_info\r
+from libcxx.test.executor import *\r
+from libcxx.test.tracing import *\r
+import libcxx.util\r
+\r
+def loadSiteConfig(lit_config, config, param_name, env_name):\r
+    # We haven't loaded the site specific configuration (the user is\r
+    # probably trying to run on a test file directly, and either the site\r
+    # configuration hasn't been created by the build system, or we are in an\r
+    # out-of-tree build situation).\r
+    site_cfg = lit_config.params.get(param_name,\r
+                                     os.environ.get(env_name))\r
+    if not site_cfg:\r
+        lit_config.warning('No site specific configuration file found!'\r
+                           ' Running the tests in the default configuration.')\r
+    elif not os.path.isfile(site_cfg):\r
+        lit_config.fatal(\r
+            "Specified site configuration file does not exist: '%s'" %\r
+            site_cfg)\r
+    else:\r
+        lit_config.note('using site specific configuration at %s' % site_cfg)\r
+        ld_fn = lit_config.load_config\r
+\r
+        # Null out the load_config function so that lit.site.cfg doesn't\r
+        # recursively load a config even if it tries.\r
+        # TODO: This is one hell of a hack. Fix it.\r
+        def prevent_reload_fn(*args, **kwargs):\r
+            pass\r
+        lit_config.load_config = prevent_reload_fn\r
+        ld_fn(config, site_cfg)\r
+        lit_config.load_config = ld_fn\r
+\r
+class Configuration(object):\r
+    # pylint: disable=redefined-outer-name\r
+    def __init__(self, lit_config, config):\r
+        self.lit_config = lit_config\r
+        self.config = config\r
+        self.is_windows = platform.system() == 'Windows'\r
+        self.cxx = None\r
+        self.cxx_is_clang_cl = None\r
+        self.cxx_stdlib_under_test = None\r
+        self.project_obj_root = None\r
+        self.libcxx_src_root = None\r
+        self.libcxx_obj_root = None\r
+        self.cxx_library_root = None\r
+        self.cxx_runtime_root = None\r
+        self.abi_library_root = None\r
+        self.link_shared = self.get_lit_bool('enable_shared', default=True)\r
+        self.debug_build = self.get_lit_bool('debug_build',   default=False)\r
+        self.exec_env = {}\r
+        self.use_target = False\r
+        self.use_system_cxx_lib = False\r
+        self.use_clang_verify = False\r
+        self.long_tests = None\r
+        self.execute_external = False\r
+\r
+    def get_lit_conf(self, name, default=None):\r
+        val = self.lit_config.params.get(name, None)\r
+        if val is None:\r
+            val = getattr(self.config, name, None)\r
+            if val is None:\r
+                val = default\r
+        return val\r
+\r
+    def get_lit_bool(self, name, default=None, env_var=None):\r
+        def check_value(value, var_name):\r
+            if value is None:\r
+                return default\r
+            if isinstance(value, bool):\r
+                return value\r
+            if not isinstance(value, str):\r
+                raise TypeError('expected bool or string')\r
+            if value.lower() in ('1', 'true'):\r
+                return True\r
+            if value.lower() in ('', '0', 'false'):\r
+                return False\r
+            self.lit_config.fatal(\r
+                "parameter '{}' should be true or false".format(var_name))\r
+\r
+        conf_val = self.get_lit_conf(name)\r
+        if env_var is not None and env_var in os.environ and \\r
+                os.environ[env_var] is not None:\r
+            val = os.environ[env_var]\r
+            if conf_val is not None:\r
+                self.lit_config.warning(\r
+                    'Environment variable %s=%s is overriding explicit '\r
+                    '--param=%s=%s' % (env_var, val, name, conf_val))\r
+            return check_value(val, env_var)\r
+        return check_value(conf_val, name)\r
+\r
+    def make_static_lib_name(self, name):\r
+        """Return the full filename for the specified library name"""\r
+        if self.is_windows:\r
+            assert name == 'c++'  # Only allow libc++ to use this function for now.\r
+            return 'lib' + name + '.lib'\r
+        else:\r
+            return 'lib' + name + '.a'\r
+\r
+    def configure(self):\r
+        self.configure_executor()\r
+        self.configure_use_system_cxx_lib()\r
+        self.configure_target_info()\r
+        self.configure_cxx()\r
+        self.configure_triple()\r
+        self.configure_deployment()\r
+        self.configure_availability()\r
+        self.configure_src_root()\r
+        self.configure_obj_root()\r
+        self.configure_cxx_stdlib_under_test()\r
+        self.configure_cxx_library_root()\r
+        self.configure_use_clang_verify()\r
+        self.configure_use_thread_safety()\r
+        self.configure_execute_external()\r
+        self.configure_ccache()\r
+        self.configure_compile_flags()\r
+        self.configure_filesystem_compile_flags()\r
+        self.configure_link_flags()\r
+        self.configure_env()\r
+        self.configure_color_diagnostics()\r
+        self.configure_debug_mode()\r
+        self.configure_warnings()\r
+        self.configure_sanitizer()\r
+        self.configure_coverage()\r
+        self.configure_modules()\r
+        self.configure_substitutions()\r
+        self.configure_features()\r
+\r
+    def print_config_info(self):\r
+        # Print the final compile and link flags.\r
+        self.lit_config.note('Using compiler: %s' % self.cxx.path)\r
+        self.lit_config.note('Using flags: %s' % self.cxx.flags)\r
+        if self.cxx.use_modules:\r
+            self.lit_config.note('Using modules flags: %s' %\r
+                                 self.cxx.modules_flags)\r
+        self.lit_config.note('Using compile flags: %s'\r
+                             % self.cxx.compile_flags)\r
+        if len(self.cxx.warning_flags):\r
+            self.lit_config.note('Using warnings: %s' % self.cxx.warning_flags)\r
+        self.lit_config.note('Using link flags: %s' % self.cxx.link_flags)\r
+        # Print as list to prevent "set([...])" from being printed.\r
+        self.lit_config.note('Using available_features: %s' %\r
+                             list(self.config.available_features))\r
+        self.lit_config.note('Using environment: %r' % self.exec_env)\r
+        sys.stderr.flush()  # Force flushing to avoid broken output on Windows\r
+\r
+    def get_test_format(self):\r
+        from libcxx.test.format import LibcxxTestFormat\r
+        return LibcxxTestFormat(\r
+            self.cxx,\r
+            self.use_clang_verify,\r
+            self.execute_external,\r
+            self.executor,\r
+            exec_env=self.exec_env)\r
+\r
+    def configure_executor(self):\r
+        exec_str = self.get_lit_conf('executor', "None")\r
+        te = eval(exec_str)\r
+        if te:\r
+            self.lit_config.note("Using executor: %r" % exec_str)\r
+            if self.lit_config.useValgrind:\r
+                # We have no way of knowing where in the chain the\r
+                # ValgrindExecutor is supposed to go. It is likely\r
+                # that the user wants it at the end, but we have no\r
+                # way of getting at that easily.\r
+                selt.lit_config.fatal("Cannot infer how to create a Valgrind "\r
+                                      " executor.")\r
+        else:\r
+            te = LocalExecutor()\r
+            if self.lit_config.useValgrind:\r
+                te = ValgrindExecutor(self.lit_config.valgrindArgs, te)\r
+        self.executor = te\r
+\r
+    def configure_target_info(self):\r
+        self.target_info = make_target_info(self)\r
+\r
+    def configure_cxx(self):\r
+        # Gather various compiler parameters.\r
+        cxx = self.get_lit_conf('cxx_under_test')\r
+        self.cxx_is_clang_cl = cxx is not None and \\r
+                               os.path.basename(cxx) == 'clang-cl.exe'\r
+        # If no specific cxx_under_test was given, attempt to infer it as\r
+        # clang++.\r
+        if cxx is None or self.cxx_is_clang_cl:\r
+            search_paths = self.config.environment['PATH']\r
+            if cxx is not None and os.path.isabs(cxx):\r
+                search_paths = os.path.dirname(cxx)\r
+            clangxx = libcxx.util.which('clang++', search_paths)\r
+            if clangxx:\r
+                cxx = clangxx\r
+                self.lit_config.note(\r
+                    "inferred cxx_under_test as: %r" % cxx)\r
+            elif self.cxx_is_clang_cl:\r
+                self.lit_config.fatal('Failed to find clang++ substitution for'\r
+                                      ' clang-cl')\r
+        if not cxx:\r
+            self.lit_config.fatal('must specify user parameter cxx_under_test '\r
+                                  '(e.g., --param=cxx_under_test=clang++)')\r
+        self.cxx = CXXCompiler(cxx) if not self.cxx_is_clang_cl else \\r
+                   self._configure_clang_cl(cxx)\r
+        cxx_type = self.cxx.type\r
+        if cxx_type is not None:\r
+            assert self.cxx.version is not None\r
+            maj_v, min_v, _ = self.cxx.version\r
+            self.config.available_features.add(cxx_type)\r
+            self.config.available_features.add('%s-%s' % (cxx_type, maj_v))\r
+            self.config.available_features.add('%s-%s.%s' % (\r
+                cxx_type, maj_v, min_v))\r
+        self.cxx.compile_env = dict(os.environ)\r
+        # 'CCACHE_CPP2' prevents ccache from stripping comments while\r
+        # preprocessing. This is required to prevent stripping of '-verify'\r
+        # comments.\r
+        self.cxx.compile_env['CCACHE_CPP2'] = '1'\r
+\r
+    def _configure_clang_cl(self, clang_path):\r
+        def _split_env_var(var):\r
+            return [p.strip() for p in os.environ.get(var, '').split(';') if p.strip()]\r
+\r
+        def _prefixed_env_list(var, prefix):\r
+            from itertools import chain\r
+            return list(chain.from_iterable((prefix, path) for path in _split_env_var(var)))\r
+\r
+        assert self.cxx_is_clang_cl\r
+        flags = []\r
+        compile_flags = _prefixed_env_list('INCLUDE', '-isystem')\r
+        link_flags = _prefixed_env_list('LIB', '-L')\r
+        for path in _split_env_var('LIB'):\r
+            self.add_path(self.exec_env, path)\r
+        return CXXCompiler(clang_path, flags=flags,\r
+                           compile_flags=compile_flags,\r
+                           link_flags=link_flags)\r
+\r
+\r
+    def configure_src_root(self):\r
+        self.libcxx_src_root = self.get_lit_conf(\r
+            'libcxx_src_root', os.path.dirname(self.config.test_source_root))\r
+\r
+    def configure_obj_root(self):\r
+        self.project_obj_root = self.get_lit_conf('project_obj_root')\r
+        self.libcxx_obj_root = self.get_lit_conf('libcxx_obj_root')\r
+        if not self.libcxx_obj_root and self.project_obj_root is not None:\r
+            possible_root = os.path.join(self.project_obj_root, 'projects', 'libcxx')\r
+            if os.path.isdir(possible_root):\r
+                self.libcxx_obj_root = possible_root\r
+            else:\r
+                self.libcxx_obj_root = self.project_obj_root\r
+\r
+    def configure_cxx_library_root(self):\r
+        self.cxx_library_root = self.get_lit_conf('cxx_library_root',\r
+                                                  self.libcxx_obj_root)\r
+        self.cxx_runtime_root = self.get_lit_conf('cxx_runtime_root',\r
+                                                   self.cxx_library_root)\r
+\r
+    def configure_use_system_cxx_lib(self):\r
+        # This test suite supports testing against either the system library or\r
+        # the locally built one; the former mode is useful for testing ABI\r
+        # compatibility between the current headers and a shipping dynamic\r
+        # library.\r
+        # Default to testing against the locally built libc++ library.\r
+        self.use_system_cxx_lib = self.get_lit_conf('use_system_cxx_lib')\r
+        if self.use_system_cxx_lib == 'true':\r
+            self.use_system_cxx_lib = True\r
+        elif self.use_system_cxx_lib == 'false':\r
+            self.use_system_cxx_lib = False\r
+        elif self.use_system_cxx_lib:\r
+            assert os.path.isdir(self.use_system_cxx_lib)\r
+        self.lit_config.note(\r
+            "inferred use_system_cxx_lib as: %r" % self.use_system_cxx_lib)\r
+\r
+    def configure_availability(self):\r
+        # See http://llvm.org/docs/AvailabilityMarkup.html\r
+        self.with_availability = self.get_lit_bool('with_availability', False)\r
+        self.lit_config.note(\r
+            "inferred with_availability as: %r" % self.with_availability)\r
+\r
+    def configure_cxx_stdlib_under_test(self):\r
+        self.cxx_stdlib_under_test = self.get_lit_conf(\r
+            'cxx_stdlib_under_test', 'libc++')\r
+        if self.cxx_stdlib_under_test not in \\r
+                ['libc++', 'libstdc++', 'msvc', 'cxx_default']:\r
+            self.lit_config.fatal(\r
+                'unsupported value for "cxx_stdlib_under_test": %s'\r
+                % self.cxx_stdlib_under_test)\r
+        self.config.available_features.add(self.cxx_stdlib_under_test)\r
+        if self.cxx_stdlib_under_test == 'libstdc++':\r
+            self.config.available_features.add('libstdc++')\r
+            # Manually enable the experimental and filesystem tests for libstdc++\r
+            # if the options aren't present.\r
+            # FIXME this is a hack.\r
+            if self.get_lit_conf('enable_experimental') is None:\r
+                self.config.enable_experimental = 'true'\r
+            if self.get_lit_conf('enable_filesystem') is None:\r
+                self.config.enable_filesystem = 'true'\r
+\r
+    def configure_use_clang_verify(self):\r
+        '''If set, run clang with -verify on failing tests.'''\r
+        if self.with_availability:\r
+            self.use_clang_verify = False\r
+            return\r
+        self.use_clang_verify = self.get_lit_bool('use_clang_verify')\r
+        if self.use_clang_verify is None:\r
+            # NOTE: We do not test for the -verify flag directly because\r
+            #   -verify will always exit with non-zero on an empty file.\r
+            self.use_clang_verify = self.cxx.isVerifySupported()\r
+            self.lit_config.note(\r
+                "inferred use_clang_verify as: %r" % self.use_clang_verify)\r
+        if self.use_clang_verify:\r
+                self.config.available_features.add('verify-support')\r
+\r
+    def configure_use_thread_safety(self):\r
+        '''If set, run clang with -verify on failing tests.'''\r
+        has_thread_safety = self.cxx.hasCompileFlag('-Werror=thread-safety')\r
+        if has_thread_safety:\r
+            self.cxx.compile_flags += ['-Werror=thread-safety']\r
+            self.config.available_features.add('thread-safety')\r
+            self.lit_config.note("enabling thread-safety annotations")\r
+\r
+    def configure_execute_external(self):\r
+        # Choose between lit's internal shell pipeline runner and a real shell.\r
+        # If LIT_USE_INTERNAL_SHELL is in the environment, we use that as the\r
+        # default value. Otherwise we ask the target_info.\r
+        use_lit_shell_default = os.environ.get('LIT_USE_INTERNAL_SHELL')\r
+        if use_lit_shell_default is not None:\r
+            use_lit_shell_default = use_lit_shell_default != '0'\r
+        else:\r
+            use_lit_shell_default = self.target_info.use_lit_shell_default()\r
+        # Check for the command line parameter using the default value if it is\r
+        # not present.\r
+        use_lit_shell = self.get_lit_bool('use_lit_shell',\r
+                                          use_lit_shell_default)\r
+        self.execute_external = not use_lit_shell\r
+\r
+    def configure_ccache(self):\r
+        use_ccache_default = os.environ.get('LIBCXX_USE_CCACHE') is not None\r
+        use_ccache = self.get_lit_bool('use_ccache', use_ccache_default)\r
+        if use_ccache:\r
+            self.cxx.use_ccache = True\r
+            self.lit_config.note('enabling ccache')\r
+\r
+    def add_deployment_feature(self, feature):\r
+        (arch, name, version) = self.config.deployment\r
+        self.config.available_features.add('%s=%s-%s' % (feature, arch, name))\r
+        self.config.available_features.add('%s=%s' % (feature, name))\r
+        self.config.available_features.add('%s=%s%s' % (feature, name, version))\r
+\r
+    def configure_features(self):\r
+        additional_features = self.get_lit_conf('additional_features')\r
+        if additional_features:\r
+            for f in additional_features.split(','):\r
+                self.config.available_features.add(f.strip())\r
+        self.target_info.add_locale_features(self.config.available_features)\r
+\r
+        target_platform = self.target_info.platform()\r
+\r
+        # Write an "available feature" that combines the triple when\r
+        # use_system_cxx_lib is enabled. This is so that we can easily write\r
+        # XFAIL markers for tests that are known to fail with versions of\r
+        # libc++ as were shipped with a particular triple.\r
+        if self.use_system_cxx_lib:\r
+            self.config.available_features.add('with_system_cxx_lib')\r
+            self.config.available_features.add(\r
+                'with_system_cxx_lib=%s' % self.config.target_triple)\r
+\r
+            # Add subcomponents individually.\r
+            target_components = self.config.target_triple.split('-')\r
+            for component in target_components:\r
+                self.config.available_features.add(\r
+                    'with_system_cxx_lib=%s' % component)\r
+\r
+            # Add available features for more generic versions of the target\r
+            # triple attached to  with_system_cxx_lib.\r
+            if self.use_deployment:\r
+                self.add_deployment_feature('with_system_cxx_lib')\r
+\r
+        # Configure the availability markup checks features.\r
+        if self.with_availability:\r
+            self.config.available_features.add('availability_markup')\r
+            self.add_deployment_feature('availability_markup')\r
+\r
+        if self.use_system_cxx_lib or self.with_availability:\r
+            self.config.available_features.add('availability')\r
+            self.add_deployment_feature('availability')\r
+\r
+        if platform.system() == 'Darwin':\r
+            self.config.available_features.add('apple-darwin')\r
+\r
+        # Insert the platform name into the available features as a lower case.\r
+        self.config.available_features.add(target_platform)\r
+\r
+        # Simulator testing can take a really long time for some of these tests\r
+        # so add a feature check so we can REQUIRES: long_tests in them\r
+        self.long_tests = self.get_lit_bool('long_tests')\r
+        if self.long_tests is None:\r
+            # Default to running long tests.\r
+            self.long_tests = True\r
+            self.lit_config.note(\r
+                "inferred long_tests as: %r" % self.long_tests)\r
+\r
+        if self.long_tests:\r
+            self.config.available_features.add('long_tests')\r
+\r
+        # Run a compile test for the -fsized-deallocation flag. This is needed\r
+        # in test/std/language.support/support.dynamic/new.delete\r
+        if self.cxx.hasCompileFlag('-fsized-deallocation'):\r
+            self.config.available_features.add('fsized-deallocation')\r
+\r
+        if self.cxx.hasCompileFlag('-faligned-allocation'):\r
+            self.config.available_features.add('-faligned-allocation')\r
+        else:\r
+            # FIXME remove this once more than just clang-4.0 support\r
+            # C++17 aligned allocation.\r
+            self.config.available_features.add('no-aligned-allocation')\r
+\r
+        if self.get_lit_bool('has_libatomic', False):\r
+            self.config.available_features.add('libatomic')\r
+\r
+        macros = self.cxx.dumpMacros()\r
+        if '__cpp_if_constexpr' not in macros:\r
+            self.config.available_features.add('libcpp-no-if-constexpr')\r
+\r
+        if '__cpp_structured_bindings' not in macros:\r
+            self.config.available_features.add('libcpp-no-structured-bindings')\r
+\r
+        if '__cpp_deduction_guides' not in macros:\r
+            self.config.available_features.add('libcpp-no-deduction-guides')\r
+\r
+        if self.is_windows:\r
+            self.config.available_features.add('windows')\r
+            if self.cxx_stdlib_under_test == 'libc++':\r
+                # LIBCXX-WINDOWS-FIXME is the feature name used to XFAIL the\r
+                # initial Windows failures until they can be properly diagnosed\r
+                # and fixed. This allows easier detection of new test failures\r
+                # and regressions. Note: New failures should not be suppressed\r
+                # using this feature. (Also see llvm.org/PR32730)\r
+                self.config.available_features.add('LIBCXX-WINDOWS-FIXME')\r
+\r
+        # Attempt to detect the glibc version by querying for __GLIBC__\r
+        # in 'features.h'.\r
+        macros = self.cxx.dumpMacros(flags=['-include', 'features.h'])\r
+        if macros is not None and '__GLIBC__' in macros:\r
+            maj_v, min_v = (macros['__GLIBC__'], macros['__GLIBC_MINOR__'])\r
+            self.config.available_features.add('glibc')\r
+            self.config.available_features.add('glibc-%s' % maj_v)\r
+            self.config.available_features.add('glibc-%s.%s' % (maj_v, min_v))\r
+\r
+    def configure_compile_flags(self):\r
+        no_default_flags = self.get_lit_bool('no_default_flags', False)\r
+        if not no_default_flags:\r
+            self.configure_default_compile_flags()\r
+        # This include is always needed so add so add it regardless of\r
+        # 'no_default_flags'.\r
+        support_path = os.path.join(self.libcxx_src_root, 'test/support')\r
+        self.cxx.compile_flags += ['-I' + support_path]\r
+        # Configure extra flags\r
+        compile_flags_str = self.get_lit_conf('compile_flags', '')\r
+        self.cxx.compile_flags += shlex.split(compile_flags_str)\r
+        # FIXME: Can we remove this?\r
+        if self.is_windows:\r
+            self.cxx.compile_flags += ['-D_CRT_SECURE_NO_WARNINGS']\r
+\r
+    def configure_default_compile_flags(self):\r
+        # Try and get the std version from the command line. Fall back to\r
+        # default given in lit.site.cfg is not present. If default is not\r
+        # present then force c++11.\r
+        std = self.get_lit_conf('std')\r
+        if not std:\r
+            # Choose the newest possible language dialect if none is given.\r
+            possible_stds = ['c++1z', 'c++14', 'c++11', 'c++03']\r
+            if self.cxx.type == 'gcc':\r
+                maj_v, _, _ = self.cxx.version\r
+                maj_v = int(maj_v)\r
+                if maj_v < 7:\r
+                    possible_stds.remove('c++1z')\r
+                # FIXME: How many C++14 tests actually fail under GCC 5 and 6?\r
+                # Should we XFAIL them individually instead?\r
+                if maj_v <= 6:\r
+                    possible_stds.remove('c++14')\r
+            for s in possible_stds:\r
+                if self.cxx.hasCompileFlag('-std=%s' % s):\r
+                    std = s\r
+                    self.lit_config.note(\r
+                        'inferred language dialect as: %s' % std)\r
+                    break\r
+            if not std:\r
+                self.lit_config.fatal(\r
+                    'Failed to infer a supported language dialect from one of %r'\r
+                    % possible_stds)\r
+        self.cxx.compile_flags += ['-std={0}'.format(std)]\r
+        self.config.available_features.add(std.replace('gnu++', 'c++'))\r
+        # Configure include paths\r
+        self.configure_compile_flags_header_includes()\r
+        self.target_info.add_cxx_compile_flags(self.cxx.compile_flags)\r
+        # Configure feature flags.\r
+        self.configure_compile_flags_exceptions()\r
+        self.configure_compile_flags_rtti()\r
+        self.configure_compile_flags_abi_version()\r
+        enable_32bit = self.get_lit_bool('enable_32bit', False)\r
+        if enable_32bit:\r
+            self.cxx.flags += ['-m32']\r
+        # Use verbose output for better errors\r
+        self.cxx.flags += ['-v']\r
+        sysroot = self.get_lit_conf('sysroot')\r
+        if sysroot:\r
+            self.cxx.flags += ['--sysroot', sysroot]\r
+        gcc_toolchain = self.get_lit_conf('gcc_toolchain')\r
+        if gcc_toolchain:\r
+            self.cxx.flags += ['-gcc-toolchain', gcc_toolchain]\r
+        # NOTE: the _DEBUG definition must preceed the triple check because for\r
+        # the Windows build of libc++, the forced inclusion of a header requires\r
+        # that _DEBUG is defined.  Incorrect ordering will result in -target\r
+        # being elided.\r
+        if self.is_windows and self.debug_build:\r
+            self.cxx.compile_flags += ['-D_DEBUG']\r
+        if self.use_target:\r
+            if not self.cxx.addFlagIfSupported(\r
+                    ['-target', self.config.target_triple]):\r
+                self.lit_config.warning('use_target is true but -target is '\\r
+                        'not supported by the compiler')\r
+        if self.use_deployment:\r
+            arch, name, version = self.config.deployment\r
+            self.cxx.flags += ['-arch', arch]\r
+            self.cxx.flags += ['-m' + name + '-version-min=' + version]\r
+\r
+        # Disable availability unless explicitely requested\r
+        if not self.with_availability:\r
+            self.cxx.flags += ['-D_LIBCPP_DISABLE_AVAILABILITY']\r
+\r
+    def configure_compile_flags_header_includes(self):\r
+        support_path = os.path.join(self.libcxx_src_root, 'test', 'support')\r
+        self.configure_config_site_header()\r
+        if self.cxx_stdlib_under_test != 'libstdc++' and \\r
+           not self.is_windows:\r
+            self.cxx.compile_flags += [\r
+                '-include', os.path.join(support_path, 'nasty_macros.hpp')]\r
+        if self.cxx_stdlib_under_test == 'msvc':\r
+            self.cxx.compile_flags += [\r
+                '-include', os.path.join(support_path,\r
+                                         'msvc_stdlib_force_include.hpp')]\r
+            pass\r
+        if self.is_windows and self.debug_build and \\r
+                self.cxx_stdlib_under_test != 'msvc':\r
+            self.cxx.compile_flags += [\r
+                '-include', os.path.join(support_path,\r
+                                         'set_windows_crt_report_mode.h')\r
+            ]\r
+        cxx_headers = self.get_lit_conf('cxx_headers')\r
+        if cxx_headers == '' or (cxx_headers is None\r
+                                 and self.cxx_stdlib_under_test != 'libc++'):\r
+            self.lit_config.note('using the system cxx headers')\r
+            return\r
+        self.cxx.compile_flags += ['-nostdinc++']\r
+        if cxx_headers is None:\r
+            cxx_headers = os.path.join(self.libcxx_src_root, 'include')\r
+        if not os.path.isdir(cxx_headers):\r
+            self.lit_config.fatal("cxx_headers='%s' is not a directory."\r
+                                  % cxx_headers)\r
+        self.cxx.compile_flags += ['-I' + cxx_headers]\r
+        if self.libcxx_obj_root is not None:\r
+            cxxabi_headers = os.path.join(self.libcxx_obj_root, 'include',\r
+                                          'c++build')\r
+            if os.path.isdir(cxxabi_headers):\r
+                self.cxx.compile_flags += ['-I' + cxxabi_headers]\r
+\r
+    def configure_config_site_header(self):\r
+        # Check for a possible __config_site in the build directory. We\r
+        # use this if it exists.\r
+        if self.libcxx_obj_root is None:\r
+            return\r
+        config_site_header = os.path.join(self.libcxx_obj_root, '__config_site')\r
+        if not os.path.isfile(config_site_header):\r
+            return\r
+        contained_macros = self.parse_config_site_and_add_features(\r
+            config_site_header)\r
+        self.lit_config.note('Using __config_site header %s with macros: %r'\r
+            % (config_site_header, contained_macros))\r
+        # FIXME: This must come after the call to\r
+        # 'parse_config_site_and_add_features(...)' in order for it to work.\r
+        self.cxx.compile_flags += ['-include', config_site_header]\r
+\r
+    def parse_config_site_and_add_features(self, header):\r
+        """ parse_config_site_and_add_features - Deduce and add the test\r
+            features that that are implied by the #define's in the __config_site\r
+            header. Return a dictionary containing the macros found in the\r
+            '__config_site' header.\r
+        """\r
+        # Parse the macro contents of __config_site by dumping the macros\r
+        # using 'c++ -dM -E' and filtering the predefines.\r
+        predefines = self.cxx.dumpMacros()\r
+        macros = self.cxx.dumpMacros(header)\r
+        feature_macros_keys = set(macros.keys()) - set(predefines.keys())\r
+        feature_macros = {}\r
+        for k in feature_macros_keys:\r
+            feature_macros[k] = macros[k]\r
+        # We expect the header guard to be one of the definitions\r
+        assert '_LIBCPP_CONFIG_SITE' in feature_macros\r
+        del feature_macros['_LIBCPP_CONFIG_SITE']\r
+        # The __config_site header should be non-empty. Otherwise it should\r
+        # have never been emitted by CMake.\r
+        assert len(feature_macros) > 0\r
+        # Transform each macro name into the feature name used in the tests.\r
+        # Ex. _LIBCPP_HAS_NO_THREADS -> libcpp-has-no-threads\r
+        for m in feature_macros:\r
+            if m == '_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS':\r
+                continue\r
+            if m == '_LIBCPP_ABI_VERSION':\r
+                self.config.available_features.add('libcpp-abi-version-v%s'\r
+                    % feature_macros[m])\r
+                continue\r
+            assert m.startswith('_LIBCPP_HAS_') or m == '_LIBCPP_ABI_UNSTABLE'\r
+            m = m.lower()[1:].replace('_', '-')\r
+            self.config.available_features.add(m)\r
+        return feature_macros\r
+\r
+\r
+\r
+    def configure_compile_flags_exceptions(self):\r
+        enable_exceptions = self.get_lit_bool('enable_exceptions', True)\r
+        if not enable_exceptions:\r
+            self.config.available_features.add('libcpp-no-exceptions')\r
+            self.cxx.compile_flags += ['-fno-exceptions']\r
+\r
+    def configure_compile_flags_rtti(self):\r
+        enable_rtti = self.get_lit_bool('enable_rtti', True)\r
+        if not enable_rtti:\r
+            self.config.available_features.add('libcpp-no-rtti')\r
+            self.cxx.compile_flags += ['-fno-rtti', '-D_LIBCPP_NO_RTTI']\r
+\r
+    def configure_compile_flags_abi_version(self):\r
+        abi_version = self.get_lit_conf('abi_version', '').strip()\r
+        abi_unstable = self.get_lit_bool('abi_unstable')\r
+        # Only add the ABI version when it is non-default.\r
+        # FIXME(EricWF): Get the ABI version from the "__config_site".\r
+        if abi_version and abi_version != '1':\r
+          self.cxx.compile_flags += ['-D_LIBCPP_ABI_VERSION=' + abi_version]\r
+        if abi_unstable:\r
+          self.config.available_features.add('libcpp-abi-unstable')\r
+          self.cxx.compile_flags += ['-D_LIBCPP_ABI_UNSTABLE']\r
+\r
+    def configure_filesystem_compile_flags(self):\r
+        enable_fs = self.get_lit_bool('enable_filesystem', default=False)\r
+        if not enable_fs:\r
+            return\r
+        enable_experimental = self.get_lit_bool('enable_experimental', default=False)\r
+        if not enable_experimental:\r
+            self.lit_config.fatal(\r
+                'filesystem is enabled but libc++experimental.a is not.')\r
+        self.config.available_features.add('c++filesystem')\r
+        static_env = os.path.join(self.libcxx_src_root, 'test', 'std',\r
+                                  'experimental', 'filesystem', 'Inputs', 'static_test_env')\r
+        static_env = os.path.realpath(static_env)\r
+        assert os.path.isdir(static_env)\r
+        self.cxx.compile_flags += ['-DLIBCXX_FILESYSTEM_STATIC_TEST_ROOT="%s"' % static_env]\r
+\r
+        dynamic_env = os.path.join(self.config.test_exec_root,\r
+                                   'filesystem', 'Output', 'dynamic_env')\r
+        dynamic_env = os.path.realpath(dynamic_env)\r
+        if not os.path.isdir(dynamic_env):\r
+            os.makedirs(dynamic_env)\r
+        self.cxx.compile_flags += ['-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT="%s"' % dynamic_env]\r
+        self.exec_env['LIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT'] = ("%s" % dynamic_env)\r
+\r
+        dynamic_helper = os.path.join(self.libcxx_src_root, 'test', 'support',\r
+                                      'filesystem_dynamic_test_helper.py')\r
+        assert os.path.isfile(dynamic_helper)\r
+\r
+        self.cxx.compile_flags += ['-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_HELPER="%s %s"'\r
+                                   % (sys.executable, dynamic_helper)]\r
+\r
+\r
+    def configure_link_flags(self):\r
+        no_default_flags = self.get_lit_bool('no_default_flags', False)\r
+        if not no_default_flags:\r
+            # Configure library path\r
+            self.configure_link_flags_cxx_library_path()\r
+            self.configure_link_flags_abi_library_path()\r
+\r
+            # Configure libraries\r
+            if self.cxx_stdlib_under_test == 'libc++':\r
+                self.cxx.link_flags += ['-nodefaultlibs']\r
+                # FIXME: Handle MSVCRT as part of the ABI library handling.\r
+                if self.is_windows:\r
+                    self.cxx.link_flags += ['-nostdlib']\r
+                self.configure_link_flags_cxx_library()\r
+                self.configure_link_flags_abi_library()\r
+                self.configure_extra_library_flags()\r
+            elif self.cxx_stdlib_under_test == 'libstdc++':\r
+                enable_fs = self.get_lit_bool('enable_filesystem',\r
+                                              default=False)\r
+                if enable_fs:\r
+                    self.config.available_features.add('c++experimental')\r
+                    self.cxx.link_flags += ['-lstdc++fs']\r
+                self.cxx.link_flags += ['-lm', '-pthread']\r
+            elif self.cxx_stdlib_under_test == 'msvc':\r
+                # FIXME: Correctly setup debug/release flags here.\r
+                pass\r
+            elif self.cxx_stdlib_under_test == 'cxx_default':\r
+                self.cxx.link_flags += ['-pthread']\r
+            else:\r
+                self.lit_config.fatal(\r
+                    'unsupported value for "use_stdlib_type": %s'\r
+                    %  use_stdlib_type)\r
+\r
+        link_flags_str = self.get_lit_conf('link_flags', '')\r
+        self.cxx.link_flags += shlex.split(link_flags_str)\r
+\r
+    def configure_link_flags_cxx_library_path(self):\r
+        if not self.use_system_cxx_lib:\r
+            if self.cxx_library_root:\r
+                self.cxx.link_flags += ['-L' + self.cxx_library_root]\r
+                if self.is_windows and self.link_shared:\r
+                    self.add_path(self.cxx.compile_env, self.cxx_library_root)\r
+            if self.cxx_runtime_root:\r
+                if not self.is_windows:\r
+                    self.cxx.link_flags += ['-Wl,-rpath,' +\r
+                                            self.cxx_runtime_root]\r
+                elif self.is_windows and self.link_shared:\r
+                    self.add_path(self.exec_env, self.cxx_runtime_root)\r
+        elif os.path.isdir(str(self.use_system_cxx_lib)):\r
+            self.cxx.link_flags += ['-L' + self.use_system_cxx_lib]\r
+            if not self.is_windows:\r
+                self.cxx.link_flags += ['-Wl,-rpath,' +\r
+                                        self.use_system_cxx_lib]\r
+            if self.is_windows and self.link_shared:\r
+                self.add_path(self.cxx.compile_env, self.use_system_cxx_lib)\r
+\r
+    def configure_link_flags_abi_library_path(self):\r
+        # Configure ABI library paths.\r
+        self.abi_library_root = self.get_lit_conf('abi_library_path')\r
+        if self.abi_library_root:\r
+            self.cxx.link_flags += ['-L' + self.abi_library_root]\r
+            if not self.is_windows:\r
+                self.cxx.link_flags += ['-Wl,-rpath,' + self.abi_library_root]\r
+            else:\r
+                self.add_path(self.exec_env, self.abi_library_root)\r
+\r
+    def configure_link_flags_cxx_library(self):\r
+        libcxx_experimental = self.get_lit_bool('enable_experimental', default=False)\r
+        if libcxx_experimental:\r
+            self.config.available_features.add('c++experimental')\r
+            self.cxx.link_flags += ['-lc++experimental']\r
+        if self.link_shared:\r
+            self.cxx.link_flags += ['-lc++']\r
+        else:\r
+            cxx_library_root = self.get_lit_conf('cxx_library_root')\r
+            if cxx_library_root:\r
+                libname = self.make_static_lib_name('c++')\r
+                abs_path = os.path.join(cxx_library_root, libname)\r
+                assert os.path.exists(abs_path) and \\r
+                       "static libc++ library does not exist"\r
+                self.cxx.link_flags += [abs_path]\r
+            else:\r
+                self.cxx.link_flags += ['-lc++']\r
+\r
+    def configure_link_flags_abi_library(self):\r
+        cxx_abi = self.get_lit_conf('cxx_abi', 'libcxxabi')\r
+        if cxx_abi == 'libstdc++':\r
+            self.cxx.link_flags += ['-lstdc++']\r
+        elif cxx_abi == 'libsupc++':\r
+            self.cxx.link_flags += ['-lsupc++']\r
+        elif cxx_abi == 'libcxxabi':\r
+            if self.target_info.allow_cxxabi_link():\r
+                libcxxabi_shared = self.get_lit_bool('libcxxabi_shared', default=True)\r
+                if libcxxabi_shared:\r
+                    self.cxx.link_flags += ['-lc++abi']\r
+                else:\r
+                    cxxabi_library_root = self.get_lit_conf('abi_library_path')\r
+                    if cxxabi_library_root:\r
+                        libname = self.make_static_lib_name('c++abi')\r
+                        abs_path = os.path.join(cxxabi_library_root, libname)\r
+                        self.cxx.link_flags += [abs_path]\r
+                    else:\r
+                        self.cxx.link_flags += ['-lc++abi']\r
+        elif cxx_abi == 'libcxxrt':\r
+            self.cxx.link_flags += ['-lcxxrt']\r
+        elif cxx_abi == 'vcruntime':\r
+            debug_suffix = 'd' if self.debug_build else ''\r
+            self.cxx.link_flags += ['-l%s%s' % (lib, debug_suffix) for lib in\r
+                                    ['vcruntime', 'ucrt', 'msvcrt']]\r
+        elif cxx_abi == 'none' or cxx_abi == 'default':\r
+            if self.is_windows:\r
+                debug_suffix = 'd' if self.debug_build else ''\r
+                self.cxx.link_flags += ['-lmsvcrt%s' % debug_suffix]\r
+        else:\r
+            self.lit_config.fatal(\r
+                'C++ ABI setting %s unsupported for tests' % cxx_abi)\r
+\r
+    def configure_extra_library_flags(self):\r
+        if self.get_lit_bool('cxx_ext_threads', default=False):\r
+            self.cxx.link_flags += ['-lc++external_threads']\r
+        self.target_info.add_cxx_link_flags(self.cxx.link_flags)\r
+\r
+    def configure_color_diagnostics(self):\r
+        use_color = self.get_lit_conf('color_diagnostics')\r
+        if use_color is None:\r
+            use_color = os.environ.get('LIBCXX_COLOR_DIAGNOSTICS')\r
+        if use_color is None:\r
+            return\r
+        if use_color != '':\r
+            self.lit_config.fatal('Invalid value for color_diagnostics "%s".'\r
+                                  % use_color)\r
+        color_flag = '-fdiagnostics-color=always'\r
+        # Check if the compiler supports the color diagnostics flag. Issue a\r
+        # warning if it does not since color diagnostics have been requested.\r
+        if not self.cxx.hasCompileFlag(color_flag):\r
+            self.lit_config.warning(\r
+                'color diagnostics have been requested but are not supported '\r
+                'by the compiler')\r
+        else:\r
+            self.cxx.flags += [color_flag]\r
+\r
+    def configure_debug_mode(self):\r
+        debug_level = self.get_lit_conf('debug_level', None)\r
+        if not debug_level:\r
+            return\r
+        if debug_level not in ['0', '1']:\r
+            self.lit_config.fatal('Invalid value for debug_level "%s".'\r
+                                  % debug_level)\r
+        self.cxx.compile_flags += ['-D_LIBCPP_DEBUG=%s' % debug_level]\r
+\r
+    def configure_warnings(self):\r
+        # Turn on warnings by default for Clang based compilers when C++ >= 11\r
+        default_enable_warnings = self.cxx.type in ['clang', 'apple-clang'] \\r
+            and len(self.config.available_features.intersection(\r
+                ['c++11', 'c++14', 'c++1z'])) != 0\r
+        enable_warnings = self.get_lit_bool('enable_warnings',\r
+                                            default_enable_warnings)\r
+        self.cxx.useWarnings(enable_warnings)\r
+        self.cxx.warning_flags += [\r
+            '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER',\r
+            '-Wall', '-Wextra', '-Werror'\r
+        ]\r
+        if self.cxx.hasWarningFlag('-Wuser-defined-warnings'):\r
+            self.cxx.warning_flags += ['-Wuser-defined-warnings']\r
+            self.config.available_features.add('diagnose-if-support')\r
+        self.cxx.addWarningFlagIfSupported('-Wshadow')\r
+        self.cxx.addWarningFlagIfSupported('-Wno-unused-command-line-argument')\r
+        self.cxx.addWarningFlagIfSupported('-Wno-attributes')\r
+        self.cxx.addWarningFlagIfSupported('-Wno-pessimizing-move')\r
+        self.cxx.addWarningFlagIfSupported('-Wno-c++11-extensions')\r
+        self.cxx.addWarningFlagIfSupported('-Wno-user-defined-literals')\r
+        self.cxx.addWarningFlagIfSupported('-Wno-noexcept-type')\r
+        # These warnings should be enabled in order to support the MSVC\r
+        # team using the test suite; They enable the warnings below and\r
+        # expect the test suite to be clean.\r
+        self.cxx.addWarningFlagIfSupported('-Wsign-compare')\r
+        self.cxx.addWarningFlagIfSupported('-Wunused-variable')\r
+        self.cxx.addWarningFlagIfSupported('-Wunused-parameter')\r
+        self.cxx.addWarningFlagIfSupported('-Wunreachable-code')\r
+        # FIXME: Enable the two warnings below.\r
+        self.cxx.addWarningFlagIfSupported('-Wno-conversion')\r
+        self.cxx.addWarningFlagIfSupported('-Wno-unused-local-typedef')\r
+        std = self.get_lit_conf('std', None)\r
+        if std in ['c++98', 'c++03']:\r
+            # The '#define static_assert' provided by libc++ in C++03 mode\r
+            # causes an unused local typedef whenever it is used.\r
+            self.cxx.addWarningFlagIfSupported('-Wno-unused-local-typedef')\r
+\r
+    def configure_sanitizer(self):\r
+        san = self.get_lit_conf('use_sanitizer', '').strip()\r
+        if san:\r
+            self.target_info.add_sanitizer_features(san, self.config.available_features)\r
+            # Search for llvm-symbolizer along the compiler path first\r
+            # and then along the PATH env variable.\r
+            symbolizer_search_paths = os.environ.get('PATH', '')\r
+            cxx_path = libcxx.util.which(self.cxx.path)\r
+            if cxx_path is not None:\r
+                symbolizer_search_paths = (\r
+                    os.path.dirname(cxx_path) +\r
+                    os.pathsep + symbolizer_search_paths)\r
+            llvm_symbolizer = libcxx.util.which('llvm-symbolizer',\r
+                                                symbolizer_search_paths)\r
+\r
+            def add_ubsan():\r
+                self.cxx.flags += ['-fsanitize=undefined',\r
+                                   '-fno-sanitize=vptr,function,float-divide-by-zero',\r
+                                   '-fno-sanitize-recover=all']\r
+                self.exec_env['UBSAN_OPTIONS'] = 'print_stacktrace=1'\r
+                self.config.available_features.add('ubsan')\r
+\r
+            # Setup the sanitizer compile flags\r
+            self.cxx.flags += ['-g', '-fno-omit-frame-pointer']\r
+            if san == 'Address' or san == 'Address;Undefined' or san == 'Undefined;Address':\r
+                self.cxx.flags += ['-fsanitize=address']\r
+                if llvm_symbolizer is not None:\r
+                    self.exec_env['ASAN_SYMBOLIZER_PATH'] = llvm_symbolizer\r
+                # FIXME: Turn ODR violation back on after PR28391 is resolved\r
+                # https://bugs.llvm.org/show_bug.cgi?id=28391\r
+                self.exec_env['ASAN_OPTIONS'] = 'detect_odr_violation=0'\r
+                self.config.available_features.add('asan')\r
+                self.config.available_features.add('sanitizer-new-delete')\r
+                self.cxx.compile_flags += ['-O1']\r
+                if san == 'Address;Undefined' or san == 'Undefined;Address':\r
+                    add_ubsan()\r
+            elif san == 'Memory' or san == 'MemoryWithOrigins':\r
+                self.cxx.flags += ['-fsanitize=memory']\r
+                if san == 'MemoryWithOrigins':\r
+                    self.cxx.compile_flags += [\r
+                        '-fsanitize-memory-track-origins']\r
+                if llvm_symbolizer is not None:\r
+                    self.exec_env['MSAN_SYMBOLIZER_PATH'] = llvm_symbolizer\r
+                self.config.available_features.add('msan')\r
+                self.config.available_features.add('sanitizer-new-delete')\r
+                self.cxx.compile_flags += ['-O1']\r
+            elif san == 'Undefined':\r
+                add_ubsan()\r
+                self.cxx.compile_flags += ['-O2']\r
+            elif san == 'Thread':\r
+                self.cxx.flags += ['-fsanitize=thread']\r
+                self.config.available_features.add('tsan')\r
+                self.config.available_features.add('sanitizer-new-delete')\r
+            else:\r
+                self.lit_config.fatal('unsupported value for '\r
+                                      'use_sanitizer: {0}'.format(san))\r
+            san_lib = self.get_lit_conf('sanitizer_library')\r
+            if san_lib:\r
+                self.cxx.link_flags += [\r
+                    san_lib, '-Wl,-rpath,%s' % os.path.dirname(san_lib)]\r
+\r
+    def configure_coverage(self):\r
+        self.generate_coverage = self.get_lit_bool('generate_coverage', False)\r
+        if self.generate_coverage:\r
+            self.cxx.flags += ['-g', '--coverage']\r
+            self.cxx.compile_flags += ['-O0']\r
+\r
+    def configure_modules(self):\r
+        modules_flags = ['-fmodules']\r
+        if platform.system() != 'Darwin':\r
+            modules_flags += ['-Xclang', '-fmodules-local-submodule-visibility']\r
+        supports_modules = self.cxx.hasCompileFlag(modules_flags)\r
+        enable_modules = self.get_lit_bool('enable_modules',\r
+                                           default=False,\r
+                                           env_var='LIBCXX_ENABLE_MODULES')\r
+        if enable_modules and not supports_modules:\r
+            self.lit_config.fatal(\r
+                '-fmodules is enabled but not supported by the compiler')\r
+        if not supports_modules:\r
+            return\r
+        self.config.available_features.add('modules-support')\r
+        module_cache = os.path.join(self.config.test_exec_root,\r
+                                   'modules.cache')\r
+        module_cache = os.path.realpath(module_cache)\r
+        if os.path.isdir(module_cache):\r
+            shutil.rmtree(module_cache)\r
+        os.makedirs(module_cache)\r
+        self.cxx.modules_flags = modules_flags + \\r
+            ['-fmodules-cache-path=' + module_cache]\r
+        if enable_modules:\r
+            self.config.available_features.add('-fmodules')\r
+            self.cxx.useModules()\r
+\r
+    def configure_substitutions(self):\r
+        sub = self.config.substitutions\r
+        cxx_path = pipes.quote(self.cxx.path)\r
+        # Configure compiler substitutions\r
+        sub.append(('%cxx', cxx_path))\r
+        # Configure flags substitutions\r
+        flags_str = ' '.join([pipes.quote(f) for f in self.cxx.flags])\r
+        compile_flags_str = ' '.join([pipes.quote(f) for f in self.cxx.compile_flags])\r
+        link_flags_str = ' '.join([pipes.quote(f) for f in self.cxx.link_flags])\r
+        all_flags = '%s %s %s' % (flags_str, compile_flags_str, link_flags_str)\r
+        sub.append(('%flags', flags_str))\r
+        sub.append(('%compile_flags', compile_flags_str))\r
+        sub.append(('%link_flags', link_flags_str))\r
+        sub.append(('%all_flags', all_flags))\r
+        if self.cxx.isVerifySupported():\r
+            verify_str = ' ' + ' '.join(self.cxx.verify_flags) + ' '\r
+            sub.append(('%verify', verify_str))\r
+        # Add compile and link shortcuts\r
+        compile_str = (cxx_path + ' -o %t.o %s -c ' + flags_str\r
+                       + ' ' + compile_flags_str)\r
+        link_str = (cxx_path + ' -o %t.exe %t.o ' + flags_str + ' '\r
+                    + link_flags_str)\r
+        assert type(link_str) is str\r
+        build_str = cxx_path + ' -o %t.exe %s ' + all_flags\r
+        if self.cxx.use_modules:\r
+            sub.append(('%compile_module', compile_str))\r
+            sub.append(('%build_module', build_str))\r
+        elif self.cxx.modules_flags is not None:\r
+            modules_str = ' '.join(self.cxx.modules_flags) + ' '\r
+            sub.append(('%compile_module', compile_str + ' ' + modules_str))\r
+            sub.append(('%build_module', build_str + ' ' + modules_str))\r
+        sub.append(('%compile', compile_str))\r
+        sub.append(('%link', link_str))\r
+        sub.append(('%build', build_str))\r
+        # Configure exec prefix substitutions.\r
+        exec_env_str = ''\r
+        if not self.is_windows and len(self.exec_env) != 0:\r
+            exec_env_str = 'env '\r
+            for k, v in self.exec_env.items():\r
+                exec_env_str += ' %s=%s' % (k, v)\r
+        # Configure run env substitution.\r
+        exec_str = exec_env_str\r
+        if self.lit_config.useValgrind:\r
+            exec_str = ' '.join(self.lit_config.valgrindArgs) + exec_env_str\r
+        sub.append(('%exec', exec_str))\r
+        # Configure run shortcut\r
+        sub.append(('%run', exec_str + ' %t.exe'))\r
+        # Configure not program substitutions\r
+        not_py = os.path.join(self.libcxx_src_root, 'utils', 'not.py')\r
+        not_str = '%s %s ' % (pipes.quote(sys.executable), pipes.quote(not_py))\r
+        sub.append(('not ', not_str))\r
+\r
+    def can_use_deployment(self):\r
+        # Check if the host is on an Apple platform using clang.\r
+        if not self.target_info.platform() == "darwin":\r
+            return False\r
+        if not self.target_info.is_host_macosx():\r
+            return False\r
+        if not self.cxx.type.endswith('clang'):\r
+            return False\r
+        return True\r
+\r
+    def configure_triple(self):\r
+        # Get or infer the target triple.\r
+        target_triple = self.get_lit_conf('target_triple')\r
+        self.use_target = self.get_lit_bool('use_target', False)\r
+        if self.use_target and target_triple:\r
+            self.lit_config.warning('use_target is true but no triple is specified')\r
+\r
+        # Use deployment if possible.\r
+        self.use_deployment = not self.use_target and self.can_use_deployment()\r
+        if self.use_deployment:\r
+            return\r
+\r
+        # Save the triple (and warn on Apple platforms).\r
+        self.config.target_triple = target_triple\r
+        if self.use_target and 'apple' in target_triple:\r
+            self.lit_config.warning('consider using arch and platform instead'\r
+                                    ' of target_triple on Apple platforms')\r
+\r
+        # If no target triple was given, try to infer it from the compiler\r
+        # under test.\r
+        if not self.config.target_triple:\r
+            target_triple = self.cxx.getTriple()\r
+            # Drop sub-major version components from the triple, because the\r
+            # current XFAIL handling expects exact matches for feature checks.\r
+            # Example: x86_64-apple-darwin14.0.0 -> x86_64-apple-darwin14\r
+            # The 5th group handles triples greater than 3 parts\r
+            # (ex x86_64-pc-linux-gnu).\r
+            target_triple = re.sub(r'([^-]+)-([^-]+)-([^.]+)([^-]*)(.*)',\r
+                                   r'\1-\2-\3\5', target_triple)\r
+            # linux-gnu is needed in the triple to properly identify linuxes\r
+            # that use GLIBC. Handle redhat and opensuse triples as special\r
+            # cases and append the missing `-gnu` portion.\r
+            if (target_triple.endswith('redhat-linux') or\r
+                target_triple.endswith('suse-linux')):\r
+                target_triple += '-gnu'\r
+            self.config.target_triple = target_triple\r
+            self.lit_config.note(\r
+                "inferred target_triple as: %r" % self.config.target_triple)\r
+\r
+    def configure_deployment(self):\r
+        assert not self.use_deployment is None\r
+        assert not self.use_target is None\r
+        if not self.use_deployment:\r
+            # Warn about ignored parameters.\r
+            if self.get_lit_conf('arch'):\r
+                self.lit_config.warning('ignoring arch, using target_triple')\r
+            if self.get_lit_conf('platform'):\r
+                self.lit_config.warning('ignoring platform, using target_triple')\r
+            return\r
+\r
+        assert not self.use_target\r
+        assert self.target_info.is_host_macosx()\r
+\r
+        # Always specify deployment explicitly on Apple platforms, since\r
+        # otherwise a platform is picked up from the SDK.  If the SDK version\r
+        # doesn't match the system version, tests that use the system library\r
+        # may fail spuriously.\r
+        arch = self.get_lit_conf('arch')\r
+        if not arch:\r
+            arch = self.cxx.getTriple().split('-', 1)[0]\r
+            self.lit_config.note("inferred arch as: %r" % arch)\r
+\r
+        inferred_platform, name, version = self.target_info.get_platform()\r
+        if inferred_platform:\r
+            self.lit_config.note("inferred platform as: %r" % (name + version))\r
+        self.config.deployment = (arch, name, version)\r
+\r
+        # Set the target triple for use by lit.\r
+        self.config.target_triple = arch + '-apple-' + name + version\r
+        self.lit_config.note(\r
+            "computed target_triple as: %r" % self.config.target_triple)\r
+\r
+    def configure_env(self):\r
+        self.target_info.configure_env(self.exec_env)\r
+\r
+    def add_path(self, dest_env, new_path):\r
+        if 'PATH' not in dest_env:\r
+            dest_env['PATH'] = new_path\r
+        else:\r
+            split_char = ';' if self.is_windows else ':'\r
+            dest_env['PATH'] = '%s%s%s' % (new_path, split_char,\r
+                                           dest_env['PATH'])\r