Skip to content

Commit

Permalink
[libc++] Implements the new version header generator.
Browse files Browse the repository at this point in the history
The generator makes a few changes to the output
- removes the synopsis, it did not really show what was implemented
  correctly.
- the output now is clang-format clean.

This code uses the new FTM data structure. Since the contents of this
structure are not up-to-date the code is only used in its tests.
  • Loading branch information
mordante committed Jul 5, 2024
1 parent 130f0f5 commit f40e7af
Show file tree
Hide file tree
Showing 7 changed files with 390 additions and 2 deletions.
51 changes: 51 additions & 0 deletions libcxx/test/libcxx/feature_test_macro/ftm_meta_data.sh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ===----------------------------------------------------------------------===##
#
# 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
#
# ===----------------------------------------------------------------------===##

# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json

import sys

sys.path.append(sys.argv[1])
from generate_feature_test_macro_components import FeatureTestMacros


def test(output, expected):
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"


ftm = FeatureTestMacros(sys.argv[2])
test(
ftm.ftm_meta_data,
{
"__cpp_lib_any": {
"headers": ["any"],
"test_suite_guard": None,
"libcxx_guard": None,
},
"__cpp_lib_barrier": {
"headers": ["barrier"],
"test_suite_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && (!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_SYNC)",
"libcxx_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC",
},
"__cpp_lib_format": {
"headers": ["format"],
"test_suite_guard": None,
"libcxx_guard": None,
},
"__cpp_lib_parallel_algorithm": {
"headers": ["algorithm", "numeric"],
"test_suite_guard": None,
"libcxx_guard": None,
},
"__cpp_lib_variant": {
"headers": ["variant"],
"test_suite_guard": None,
"libcxx_guard": None,
},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test(output, expected):
"__cpp_lib_barrier": {
"c++20": "201907L",
"c++23": "201907L",
"c++26": "201907L",
"c++26": "299900L",
},
"__cpp_lib_format": {
"c++20": None,
Expand Down
2 changes: 1 addition & 1 deletion libcxx/test/libcxx/feature_test_macro/standard_ftms.sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test(output, expected):
"__cpp_lib_barrier": {
"c++20": "201907L",
"c++23": "201907L",
"c++26": "201907L",
"c++26": "299900L",
},
"__cpp_lib_format": {
"c++20": "202110L",
Expand Down
7 changes: 7 additions & 0 deletions libcxx/test/libcxx/feature_test_macro/test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
"implemented": true
}
]
},
"c++26": {
"299900": [
{
"implemented": true
}
]
}
},
"headers": [
Expand Down
73 changes: 73 additions & 0 deletions libcxx/test/libcxx/feature_test_macro/version_header.sh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# ===----------------------------------------------------------------------===##
#
# 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
#
# ===----------------------------------------------------------------------===##

# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json

import sys

sys.path.append(sys.argv[1])
from generate_feature_test_macro_components import FeatureTestMacros


def test(output, expected):
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"


ftm = FeatureTestMacros(sys.argv[2])
test(
ftm.version_header,
"""// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_VERSION
#define _LIBCPP_VERSION
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
#if _LIBCPP_STD_VER >= 17
# define __cpp_lib_any 201606L
# define __cpp_lib_parallel_algorithm 201603L
# define __cpp_lib_variant 202102L
#endif // _LIBCPP_STD_VER >= 17
#if _LIBCPP_STD_VER >= 20
# if !defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC
# define __cpp_lib_barrier 201907L
# endif
// define __cpp_lib_format 202110L
# undef __cpp_lib_variant
# define __cpp_lib_variant 202106L
#endif // _LIBCPP_STD_VER >= 20
#if _LIBCPP_STD_VER >= 23
// define __cpp_lib_format 202207L
#endif // _LIBCPP_STD_VER >= 23
#if _LIBCPP_STD_VER >= 26
# if !defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC
# undef __cpp_lib_barrier
# define __cpp_lib_barrier 299900L
# endif
// define __cpp_lib_format 202311L
# undef __cpp_lib_variant
# define __cpp_lib_variant 202306L
#endif // _LIBCPP_STD_VER >= 26
#endif // _LIBCPP_VERSION
""",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# ===----------------------------------------------------------------------===##
#
# 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
#
# ===----------------------------------------------------------------------===##

# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json

import sys

sys.path.append(sys.argv[1])
from generate_feature_test_macro_components import FeatureTestMacros


def test(output, expected):
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"


ftm = FeatureTestMacros(sys.argv[2])
test(
ftm.version_header_implementation,
{
"17": [
{
"__cpp_lib_any": {
"value": "201606L",
"implemented": True,
"need_undef": False,
"condition": None,
},
},
{
"__cpp_lib_parallel_algorithm": {
"value": "201603L",
"implemented": True,
"need_undef": False,
"condition": None,
},
},
{
"__cpp_lib_variant": {
"value": "202102L",
"implemented": True,
"need_undef": False,
"condition": None,
},
},
],
"20": [
{
"__cpp_lib_barrier": {
"value": "201907L",
"implemented": True,
"need_undef": False,
"condition": "!defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC",
},
},
{
"__cpp_lib_format": {
"value": "202110L",
"implemented": False,
"need_undef": False,
"condition": None,
},
},
{
"__cpp_lib_variant": {
"value": "202106L",
"implemented": True,
"need_undef": True,
"condition": None,
},
},
],
"23": [
{
"__cpp_lib_format": {
"value": "202207L",
"implemented": False,
"need_undef": False,
"condition": None,
},
},
],
"26": [
{
"__cpp_lib_barrier": {
"value": "299900L",
"implemented": True,
"need_undef": True,
"condition": "!defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC",
},
},
{
"__cpp_lib_format": {
"value": "202311L",
"implemented": False,
"need_undef": False,
"condition": None,
},
},
{
"__cpp_lib_variant": {
"value": "202306L",
"implemented": True,
"need_undef": True,
"condition": None,
},
},
],
},
)
Loading

0 comments on commit f40e7af

Please sign in to comment.