[libcxx-commits] [libcxx] ff4a3ee - [libc++] Define a few Lit features using the new DSL
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon May 4 05:54:17 PDT 2020
Author: Louis Dionne
Date: 2020-05-04T08:54:07-04:00
New Revision: ff4a3ee49ca5cdaf0face112a9a9cca3bd63522b
URL: https://github.com/llvm/llvm-project/commit/ff4a3ee49ca5cdaf0face112a9a9cca3bd63522b
DIFF: https://github.com/llvm/llvm-project/commit/ff4a3ee49ca5cdaf0face112a9a9cca3bd63522b.diff
LOG: [libc++] Define a few Lit features using the new DSL
This commit migrates some of the Lit features from config.py to the new
DSL. This simplifies config.py and is a first step towards defining all
the features using the DSL instead of the complex logic in config.py.
Differential Revision: https://reviews.llvm.org/D78382
Added:
libcxx/utils/libcxx/test/features.py
Modified:
libcxx/utils/libcxx/test/config.py
Removed:
################################################################################
diff --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py
index c61f46f749de..fe6251132309 100644
--- a/libcxx/utils/libcxx/test/config.py
+++ b/libcxx/utils/libcxx/test/config.py
@@ -22,6 +22,7 @@
from libcxx.test.executor import *
from libcxx.test.tracing import *
import libcxx.util
+import libcxx.test.features
def loadSiteConfig(lit_config, config, param_name, env_name):
# We haven't loaded the site specific configuration (the user is
@@ -130,7 +131,6 @@ def configure(self):
self.configure_obj_root()
self.configure_cxx_stdlib_under_test()
self.configure_cxx_library_root()
- self.configure_use_thread_safety()
self.configure_ccache()
self.configure_compile_flags()
self.configure_link_flags()
@@ -141,11 +141,14 @@ def configure(self):
self.configure_sanitizer()
self.configure_coverage()
self.configure_modules()
- self.configure_coroutines()
- self.configure_blocks()
- self.configure_objc_arc()
self.configure_substitutions()
self.configure_features()
+ self.configure_new_features()
+
+ def configure_new_features(self):
+ supportedFeatures = [f for f in libcxx.test.features.features if f.isSupported(self.config)]
+ for feature in supportedFeatures:
+ feature.enableIn(self.config)
def print_config_info(self):
# Print the final compile and link flags.
@@ -322,14 +325,6 @@ def configure_cxx_stdlib_under_test(self):
if self.get_lit_conf('enable_experimental') is None:
self.config.enable_experimental = 'true'
- 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_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)
@@ -384,36 +379,9 @@ def configure_features(self):
if not self.get_lit_bool('enable_filesystem', default=True):
self.config.available_features.add('c++filesystem-disabled')
-
- # 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')
-
- if self.cxx.hasCompileFlag('-fdelayed-template-parsing'):
- self.config.available_features.add('fdelayed-template-parsing')
-
if self.get_lit_bool('has_libatomic', False):
self.config.available_features.add('libatomic')
- macros = self._dump_macros_verbose()
- 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 or \
- intMacroValue(macros['__cpp_deduction_guides']) < 201611:
- self.config.available_features.add('libcpp-no-deduction-guides')
-
- if '__cpp_concepts' not in macros or \
- intMacroValue(macros['__cpp_concepts']) < 201811:
- self.config.available_features.add('libcpp-no-concepts')
-
if self.target_info.is_windows():
self.config.available_features.add('windows')
if self.cxx_stdlib_under_test == 'libc++':
@@ -429,12 +397,6 @@ def configure_features(self):
self.config.available_features.add('libcxx_gdb')
self.cxx.libcxx_gdb = libcxx_gdb
- # Support Objective-C++ only on MacOS and if the compiler supports it.
- if self.target_info.platform() == "darwin" and \
- self.target_info.is_host_macosx() and \
- self.cxx.hasCompileFlag(["-x", "objective-c++", "-fobjc-arc"]):
- self.config.available_features.add("objective-c++")
-
def configure_compile_flags(self):
self.configure_default_compile_flags()
# Configure extra flags
@@ -820,9 +782,6 @@ def configure_warnings(self):
# don't enable warnings in system headers on GCC.
if self.cxx.type != 'gcc':
self.cxx.warning_flags += ['-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER']
- 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')
@@ -908,27 +867,6 @@ def configure_coverage(self):
self.cxx.flags += ['-g', '--coverage']
self.cxx.compile_flags += ['-O0']
- def configure_coroutines(self):
- if self.cxx.hasCompileFlag('-fcoroutines-ts'):
- macros = self._dump_macros_verbose(flags=['-fcoroutines-ts'])
- if '__cpp_coroutines' not in macros:
- self.lit_config.warning('-fcoroutines-ts is supported but '
- '__cpp_coroutines is not defined')
- # Consider coroutines supported only when the feature test macro
- # reflects a recent value.
- if intMacroValue(macros['__cpp_coroutines']) >= 201703:
- self.config.available_features.add('fcoroutines-ts')
-
- def configure_blocks(self):
- if self.cxx.hasCompileFlag('-fblocks'):
- self.config.available_features.add('has-fblocks')
-
- def configure_objc_arc(self):
- cxx = copy.deepcopy(self.cxx)
- cxx.source_lang = 'objective-c++'
- if cxx.hasCompileFlag('-fobjc-arc'):
- self.config.available_features.add('has-fobjc-arc')
-
def configure_modules(self):
modules_flags = ['-fmodules']
if not self.target_info.is_darwin():
diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py
new file mode 100644
index 000000000000..091fffa599a5
--- /dev/null
+++ b/libcxx/utils/libcxx/test/features.py
@@ -0,0 +1,30 @@
+#===----------------------------------------------------------------------===##
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===----------------------------------------------------------------------===##
+
+from libcxx.test.dsl import *
+import sys
+
+features = [
+ Feature(name='fcoroutines-ts', compileFlag='-fcoroutines-ts',
+ when=lambda cfg: hasCompileFlag(cfg, '-fcoroutines-ts') and
+ featureTestMacros(cfg, flags='-fcoroutines-ts').get('__cpp_coroutines', 0) >= 201703),
+
+ Feature(name='thread-safety', when=lambda cfg: hasCompileFlag(cfg, '-Werror=thread-safety'), compileFlag='-Werror=thread-safety'),
+ Feature(name='has-fblocks', when=lambda cfg: hasCompileFlag(cfg, '-fblocks')),
+ Feature(name='-fsized-deallocation', when=lambda cfg: hasCompileFlag(cfg, '-fsized-deallocation')),
+ Feature(name='-faligned-allocation', when=lambda cfg: hasCompileFlag(cfg, '-faligned-allocation')),
+ Feature(name='fdelayed-template-parsing', when=lambda cfg: hasCompileFlag(cfg, '-fdelayed-template-parsing')),
+ Feature(name='libcpp-no-if-constexpr', when=lambda cfg: '__cpp_if_constexpr' not in featureTestMacros(cfg)),
+ Feature(name='libcpp-no-structured-bindings', when=lambda cfg: '__cpp_structured_bindings' not in featureTestMacros(cfg)),
+ Feature(name='libcpp-no-deduction-guides', when=lambda cfg: featureTestMacros(cfg).get('__cpp_deduction_guides', 0) < 201611),
+ Feature(name='libcpp-no-concepts', when=lambda cfg: featureTestMacros(cfg).get('__cpp_concepts', 0) < 201811),
+ Feature(name='has-fobjc-arc', when=lambda cfg: hasCompileFlag(cfg, '-xobjective-c++ -fobjc-arc') and
+ sys.platform.lower().strip() == 'darwin'), # TODO: this doesn't handle cross-compiling to Apple platforms.
+ Feature(name='objective-c++', when=lambda cfg: hasCompileFlag(cfg, '-xobjective-c++ -fobjc-arc')),
+ Feature(name='diagnose-if-support', when=lambda cfg: hasCompileFlag(cfg, '-Wuser-defined-warnings'), compileFlag='-Wuser-defined-warnings'),
+]
More information about the libcxx-commits
mailing list