Skip to content

Commit 7f2791c

Browse files
committed
[libc++] Improves type-safety in generator script.
This changes the code to use dataclasses instead of dict entries. It also adds type aliases to use in the typing information and updates the typing information.
1 parent cb1b51f commit 7f2791c

File tree

3 files changed

+160
-158
lines changed

3 files changed

+160
-158
lines changed

libcxx/test/libcxx/feature_test_macro/ftm_metadata.sh.py

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,37 @@
1111
import sys
1212

1313
sys.path.append(sys.argv[1])
14-
from generate_feature_test_macro_components import FeatureTestMacros
14+
from generate_feature_test_macro_components import FeatureTestMacros, Metadata
1515

1616

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

2020

2121
ftm = FeatureTestMacros(sys.argv[2])
22+
2223
test(
2324
ftm.ftm_metadata,
2425
{
25-
"__cpp_lib_any": {
26-
"headers": ["any"],
27-
"test_suite_guard": None,
28-
"libcxx_guard": None,
29-
},
30-
"__cpp_lib_barrier": {
31-
"headers": ["barrier"],
32-
"test_suite_guard": "!defined(_LIBCPP_VERSION) || (_LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC)",
33-
"libcxx_guard": "_LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC",
34-
},
35-
"__cpp_lib_format": {
36-
"headers": ["format"],
37-
"test_suite_guard": None,
38-
"libcxx_guard": None,
39-
},
40-
"__cpp_lib_parallel_algorithm": {
41-
"headers": ["algorithm", "numeric"],
42-
"test_suite_guard": None,
43-
"libcxx_guard": None,
44-
},
45-
"__cpp_lib_variant": {
46-
"headers": ["variant"],
47-
"test_suite_guard": None,
48-
"libcxx_guard": None,
49-
},
50-
"__cpp_lib_missing_FTM_in_older_standard": {
51-
"headers": [],
52-
"test_suite_guard": None,
53-
"libcxx_guard": None,
54-
},
26+
"__cpp_lib_any": Metadata(
27+
headers=["any"], test_suite_guard=None, libcxx_guard=None
28+
),
29+
"__cpp_lib_barrier": Metadata(
30+
headers=["barrier"],
31+
test_suite_guard="!defined(_LIBCPP_VERSION) || (_LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC)",
32+
libcxx_guard="_LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC",
33+
),
34+
"__cpp_lib_format": Metadata(
35+
headers=["format"], test_suite_guard=None, libcxx_guard=None
36+
),
37+
"__cpp_lib_parallel_algorithm": Metadata(
38+
headers=["algorithm", "numeric"], test_suite_guard=None, libcxx_guard=None
39+
),
40+
"__cpp_lib_variant": Metadata(
41+
headers=["variant"], test_suite_guard=None, libcxx_guard=None
42+
),
43+
"__cpp_lib_missing_FTM_in_older_standard": Metadata(
44+
headers=[], test_suite_guard=None, libcxx_guard=None
45+
),
5546
},
5647
)

libcxx/test/libcxx/feature_test_macro/version_header_implementation.sh.py

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
del sys.argv[1:3]
1717

1818
sys.path.append(UTILS)
19-
from generate_feature_test_macro_components import FeatureTestMacros
19+
from generate_feature_test_macro_components import FeatureTestMacros, VersionHeader
2020

2121
class Test(unittest.TestCase):
2222
def setUp(self):
@@ -27,114 +27,114 @@ def test_implementation(self):
2727
expected = {
2828
"17": [
2929
{
30-
"__cpp_lib_any": {
31-
"value": "201606L",
32-
"implemented": True,
33-
"need_undef": False,
34-
"condition": None,
35-
},
30+
"__cpp_lib_any": VersionHeader(
31+
value="201606L",
32+
implemented=True,
33+
need_undef=False,
34+
condition=None,
35+
),
3636
},
3737
{
38-
"__cpp_lib_parallel_algorithm": {
39-
"value": "201603L",
40-
"implemented": True,
41-
"need_undef": False,
42-
"condition": None,
43-
},
38+
"__cpp_lib_parallel_algorithm": VersionHeader(
39+
value="201603L",
40+
implemented=True,
41+
need_undef=False,
42+
condition=None,
43+
),
4444
},
4545
{
46-
"__cpp_lib_variant": {
47-
"value": "202102L",
48-
"implemented": True,
49-
"need_undef": False,
50-
"condition": None,
51-
},
46+
"__cpp_lib_variant": VersionHeader(
47+
value="202102L",
48+
implemented=True,
49+
need_undef=False,
50+
condition=None,
51+
),
5252
},
5353
{
54-
"__cpp_lib_missing_FTM_in_older_standard": {
55-
"value": "2017L",
56-
"implemented": False,
57-
"need_undef": False,
58-
"condition": None,
59-
},
54+
"__cpp_lib_missing_FTM_in_older_standard" : VersionHeader(
55+
value = "2017L",
56+
implemented = False,
57+
need_undef = False,
58+
condition = None,
59+
),
6060
},
6161
],
6262
"20": [
6363
{
64-
"__cpp_lib_barrier": {
65-
"value": "201907L",
66-
"implemented": True,
67-
"need_undef": False,
68-
"condition": "_LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC",
69-
},
64+
"__cpp_lib_barrier": VersionHeader(
65+
value="201907L",
66+
implemented=True,
67+
need_undef=False,
68+
condition="_LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC",
69+
),
7070
},
7171
{
72-
"__cpp_lib_format": {
73-
"value": "202110L",
74-
"implemented": False,
75-
"need_undef": False,
76-
"condition": None,
77-
},
72+
"__cpp_lib_format": VersionHeader(
73+
value="202110L",
74+
implemented=False,
75+
need_undef=False,
76+
condition=None,
77+
),
7878
},
7979
{
80-
"__cpp_lib_variant": {
81-
"value": "202106L",
82-
"implemented": False,
83-
"need_undef": False,
84-
"condition": None,
85-
},
80+
"__cpp_lib_variant": VersionHeader(
81+
value="202106L",
82+
implemented=False,
83+
need_undef=False,
84+
condition=None,
85+
),
8686
},
8787
{
88-
"__cpp_lib_missing_FTM_in_older_standard": {
89-
"value": "2020L",
90-
"implemented": False,
91-
"need_undef": False,
92-
"condition": None,
93-
},
88+
"__cpp_lib_missing_FTM_in_older_standard" : VersionHeader(
89+
value = "2020L",
90+
implemented = False,
91+
need_undef = False,
92+
condition = None,
93+
),
9494
},
9595
],
9696
"23": [
9797
{
98-
"__cpp_lib_format": {
99-
"value": "202207L",
100-
"implemented": False,
101-
"need_undef": False,
102-
"condition": None,
103-
},
98+
"__cpp_lib_format": VersionHeader(
99+
value="202207L",
100+
implemented=False,
101+
need_undef=False,
102+
condition=None,
103+
),
104104
},
105105
],
106106
"26": [
107107
{
108-
"__cpp_lib_barrier": {
109-
"value": "299900L",
110-
"implemented": True,
111-
"need_undef": True,
112-
"condition": "_LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC",
113-
},
108+
"__cpp_lib_barrier": VersionHeader(
109+
value="299900L",
110+
implemented=True,
111+
need_undef=True,
112+
condition="_LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC",
113+
),
114114
},
115115
{
116-
"__cpp_lib_format": {
117-
"value": "202311L",
118-
"implemented": False,
119-
"need_undef": False,
120-
"condition": None,
121-
},
116+
"__cpp_lib_format": VersionHeader(
117+
value="202311L",
118+
implemented=False,
119+
need_undef=False,
120+
condition=None,
121+
),
122122
},
123123
{
124-
"__cpp_lib_variant": {
125-
"value": "202306L",
126-
"implemented": False,
127-
"need_undef": False,
128-
"condition": None,
129-
},
124+
"__cpp_lib_variant": VersionHeader(
125+
value="202306L",
126+
implemented=False,
127+
need_undef=False,
128+
condition=None,
129+
),
130130
},
131131
{
132-
"__cpp_lib_missing_FTM_in_older_standard": {
133-
"value": "2026L",
134-
"implemented": False,
135-
"need_undef": False,
136-
"condition": None,
137-
},
132+
"__cpp_lib_missing_FTM_in_older_standard" : VersionHeader(
133+
value = "2026L",
134+
implemented = False,
135+
need_undef = False,
136+
condition = None,
137+
),
138138
},
139139
],
140140
}

0 commit comments

Comments
 (0)