[libcxx-commits] [libcxx] [libc++] Split features.py into multiple files (PR #167353)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 10 10:00:16 PST 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {darker}-->
:warning: Python code formatter, darker found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
darker --check --diff -r origin/main...HEAD libcxx/utils/libcxx/test/features/__init__.py libcxx/utils/libcxx/test/features/availability.py libcxx/utils/libcxx/test/features/compiler.py libcxx/utils/libcxx/test/features/gdb.py libcxx/utils/libcxx/test/features/libcxx_macros.py libcxx/utils/libcxx/test/features/localization.py libcxx/utils/libcxx/test/features/misc.py libcxx/utils/libcxx/test/features/platform.py libcxx/utils/libcxx/test/params.py
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from darker here.
</summary>
``````````diff
--- features/compiler.py 2025-11-10 17:58:04.000000 +0000
+++ features/compiler.py 2025-11-10 17:59:45.407673 +0000
@@ -14,41 +14,51 @@
_isClang = lambda cfg: _isAnyClang(cfg) and not _isAppleClang(cfg)
_isGCC = lambda cfg: _isAnyGCC(cfg) and not _isAnyClang(cfg)
_isAnyClangOrGCC = lambda cfg: _isAnyClang(cfg) or _isAnyGCC(cfg)
_isClExe = lambda cfg: not _isAnyClangOrGCC(cfg)
_isMSVC = lambda cfg: "_MSC_VER" in compilerMacros(cfg)
-_msvcVersion = lambda cfg: (int(compilerMacros(cfg)["_MSC_VER"]) // 100, int(compilerMacros(cfg)["_MSC_VER"]) % 100)
+_msvcVersion = lambda cfg: (
+ int(compilerMacros(cfg)["_MSC_VER"]) // 100,
+ int(compilerMacros(cfg)["_MSC_VER"]) % 100,
+)
features = [
# gcc-style-warnings detects compilers that understand -Wno-meow flags, unlike MSVC's compiler driver cl.exe.
Feature(name="gcc-style-warnings", when=_isAnyClangOrGCC),
Feature(name="cl-style-warnings", when=_isClExe),
-
Feature(name="apple-clang", when=_isAppleClang),
Feature(
name=lambda cfg: "apple-clang-{__clang_major__}".format(**compilerMacros(cfg)),
when=_isAppleClang,
),
Feature(
- name=lambda cfg: "apple-clang-{__clang_major__}.{__clang_minor__}".format(**compilerMacros(cfg)),
+ name=lambda cfg: "apple-clang-{__clang_major__}.{__clang_minor__}".format(
+ **compilerMacros(cfg)
+ ),
when=_isAppleClang,
),
Feature(
- name=lambda cfg: "apple-clang-{__clang_major__}.{__clang_minor__}.{__clang_patchlevel__}".format(**compilerMacros(cfg)),
+ name=lambda cfg: "apple-clang-{__clang_major__}.{__clang_minor__}.{__clang_patchlevel__}".format(
+ **compilerMacros(cfg)
+ ),
when=_isAppleClang,
),
Feature(name="clang", when=_isClang),
Feature(
name=lambda cfg: "clang-{__clang_major__}".format(**compilerMacros(cfg)),
when=_isClang,
),
Feature(
- name=lambda cfg: "clang-{__clang_major__}.{__clang_minor__}".format(**compilerMacros(cfg)),
+ name=lambda cfg: "clang-{__clang_major__}.{__clang_minor__}".format(
+ **compilerMacros(cfg)
+ ),
when=_isClang,
),
Feature(
- name=lambda cfg: "clang-{__clang_major__}.{__clang_minor__}.{__clang_patchlevel__}".format(**compilerMacros(cfg)),
+ name=lambda cfg: "clang-{__clang_major__}.{__clang_minor__}.{__clang_patchlevel__}".format(
+ **compilerMacros(cfg)
+ ),
when=_isClang,
),
# Note: Due to a GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104760), we must disable deprecation warnings
# on GCC or spurious diagnostics are issued.
#
@@ -67,15 +77,19 @@
),
Feature(
name=lambda cfg: "gcc-{__GNUC__}".format(**compilerMacros(cfg)), when=_isGCC
),
Feature(
- name=lambda cfg: "gcc-{__GNUC__}.{__GNUC_MINOR__}".format(**compilerMacros(cfg)),
+ name=lambda cfg: "gcc-{__GNUC__}.{__GNUC_MINOR__}".format(
+ **compilerMacros(cfg)
+ ),
when=_isGCC,
),
Feature(
- name=lambda cfg: "gcc-{__GNUC__}.{__GNUC_MINOR__}.{__GNUC_PATCHLEVEL__}".format(**compilerMacros(cfg)),
+ name=lambda cfg: "gcc-{__GNUC__}.{__GNUC_MINOR__}.{__GNUC_PATCHLEVEL__}".format(
+ **compilerMacros(cfg)
+ ),
when=_isGCC,
),
Feature(name="msvc", when=_isMSVC),
Feature(name=lambda cfg: "msvc-{}".format(*_msvcVersion(cfg)), when=_isMSVC),
Feature(name=lambda cfg: "msvc-{}.{}".format(*_msvcVersion(cfg)), when=_isMSVC),
--- features/gdb.py 2025-11-10 17:58:04.000000 +0000
+++ features/gdb.py 2025-11-10 17:59:45.423802 +0000
@@ -7,10 +7,11 @@
# ===----------------------------------------------------------------------===##
from libcxx.test.dsl import Feature, AddSubstitution
import shutil
import subprocess
+
# Detect whether GDB is on the system, has Python scripting and supports
# adding breakpoint commands. If so add a substitution to access it.
def check_gdb(cfg):
gdb_path = shutil.which("gdb")
--- features/libcxx_macros.py 2025-11-10 17:58:04.000000 +0000
+++ features/libcxx_macros.py 2025-11-10 17:59:45.447471 +0000
@@ -34,11 +34,12 @@
"_LIBCPP_PSTL_BACKEND_LIBDISPATCH": "libcpp-pstl-backend-libdispatch",
}
for macro, feature in macros.items():
features.append(
Feature(
- name=lambda cfg, m=macro, f=feature: f + ("={}".format(compilerMacros(cfg)[m]) if compilerMacros(cfg)[m] else ""),
+ name=lambda cfg, m=macro, f=feature: f
+ + ("={}".format(compilerMacros(cfg)[m]) if compilerMacros(cfg)[m] else ""),
when=lambda cfg, m=macro: m in compilerMacros(cfg),
)
)
true_false_macros = {
--- features/localization.py 2025-11-10 17:58:04.000000 +0000
+++ features/localization.py 2025-11-10 17:59:45.478538 +0000
@@ -4,11 +4,18 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# ===----------------------------------------------------------------------===##
-from libcxx.test.dsl import compilerMacros, Feature, programSucceeds, hasAnyLocale, programOutput, AddSubstitution
+from libcxx.test.dsl import (
+ compilerMacros,
+ Feature,
+ programSucceeds,
+ hasAnyLocale,
+ programOutput,
+ AddSubstitution,
+)
import re
features = [
# Check for Glibc < 2.27, where the ru_RU.UTF-8 locale had
# mon_decimal_point == ".", which our tests don't handle.
@@ -55,15 +62,18 @@
when=lambda cfg, alts=alts: hasAnyLocale(cfg, alts),
actions=lambda cfg, locale=locale, alts=alts: _getLocaleFlagsAction(
cfg, locale, alts, _provide_locale_conversions[locale]
)
if locale in _provide_locale_conversions
- and ("_LIBCPP_HAS_WIDE_CHARACTERS" not in compilerMacros(cfg) or
- compilerMacros(cfg)["_LIBCPP_HAS_WIDE_CHARACTERS"] == "1")
+ and (
+ "_LIBCPP_HAS_WIDE_CHARACTERS" not in compilerMacros(cfg)
+ or compilerMacros(cfg)["_LIBCPP_HAS_WIDE_CHARACTERS"] == "1"
+ )
else [],
),
)
+
# Provide environment locale conversions through substitutions to avoid platform specific
# maintenance.
def _getLocaleFlagsAction(cfg, locale, alts, members):
alts_list = ",".join([f'"{l}"' for l in alts])
--- features/misc.py 2025-11-10 17:58:04.000000 +0000
+++ features/misc.py 2025-11-10 17:59:45.531377 +0000
@@ -4,14 +4,21 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# ===----------------------------------------------------------------------===##
-from libcxx.test.dsl import compilerMacros, sourceBuilds, hasCompileFlag, programSucceeds, runScriptExitCode
+from libcxx.test.dsl import (
+ compilerMacros,
+ sourceBuilds,
+ hasCompileFlag,
+ programSucceeds,
+ runScriptExitCode,
+)
from libcxx.test.dsl import Feature, AddCompileFlag, AddLinkFlag
import platform
import sys
+
def _mingwSupportsModules(cfg):
# Only mingw headers are known to work with libc++ built as a module,
# at the moment.
if not "__MINGW32__" in compilerMacros(cfg):
@@ -40,10 +47,11 @@
#endif
int main(int, char**) { return 0; }
""",
)
+
features = [
Feature(
name="diagnose-if-support",
when=lambda cfg: hasCompileFlag(cfg, "-Wuser-defined-warnings"),
actions=[AddCompileFlag("-Wuser-defined-warnings")],
@@ -206,11 +214,12 @@
# and executes bash, but bash then can't find any other common shell
# utilities. Test executing "bash -c 'bash --version'" to see if bash
# manages to find binaries to execute.
Feature(
name="executor-has-no-bash",
- when=lambda cfg: runScriptExitCode(cfg, ["%{exec} bash -c 'bash --version'"]) != 0,
+ when=lambda cfg: runScriptExitCode(cfg, ["%{exec} bash -c 'bash --version'"])
+ != 0,
),
# Whether module support for the platform is available.
Feature(
name="has-no-cxx-module-support",
# The libc of these platforms have functions with internal linkage.
--- features/platform.py 2025-11-10 17:58:04.000000 +0000
+++ features/platform.py 2025-11-10 17:59:45.575231 +0000
@@ -4,13 +4,21 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# ===----------------------------------------------------------------------===##
-from libcxx.test.dsl import programOutput, Feature, compilerMacros, programSucceeds, AddCompileFlag, sourceBuilds
+from libcxx.test.dsl import (
+ programOutput,
+ Feature,
+ compilerMacros,
+ programSucceeds,
+ AddCompileFlag,
+ sourceBuilds,
+)
import platform
import sys
+
def _getAndroidDeviceApi(cfg):
return int(
programOutput(
cfg,
@@ -22,10 +30,11 @@
return 0;
}
""",
)
)
+
# Add features representing the target platform name: darwin, linux, windows, etc...
features = [
Feature(name="darwin", when=lambda cfg: "__APPLE__" in compilerMacros(cfg)),
Feature(name="windows", when=lambda cfg: "_WIN32" in compilerMacros(cfg)),
``````````
</details>
https://github.com/llvm/llvm-project/pull/167353
More information about the libcxx-commits
mailing list