Skip to content

[libc++] Implements the new version header generator. #97847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions libcxx/test/libcxx/feature_test_macro/ftm_metadata.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_metadata,
{
"__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
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
Copy link
Contributor

@cpplearner cpplearner Sep 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output seems incorrect: this value is marked as "implemented": false in test_data.json, and thus it should not be defined in the generated output.

"202106": [
{
"number": "",
"title": "Fully constexpr ``std::variant``",
"implemented": false
}
]

(I noticed this while working on an up-to-date FTM data file.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing! This PR should fix it: #108843

#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
Loading