Skip to content

Commit 00345a2

Browse files
mordantekbluck
authored andcommitted
[libc++] Adds a new feature-test macro generator class. (llvm#90889)
The new feature-test macro generator uses a JSON file as input. Separating the code from the data allows for testing the code. The generator has several tests. This JSON format is based on the new format proposed in llvm#88630 At the moment the FTM script has the existing code and an unused new generator. Followup patches will complete the generator and convert the existing Python `dict` to the new JSON format. Since that conversion is a manual job and quite a bit of work the transition path has some unused code for some time.
1 parent 72238a4 commit 00345a2

File tree

6 files changed

+591
-0
lines changed

6 files changed

+591
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# ===----------------------------------------------------------------------===##
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
# ===----------------------------------------------------------------------===##
8+
9+
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
10+
11+
import sys
12+
13+
sys.path.append(sys.argv[1])
14+
from generate_feature_test_macro_components import FeatureTestMacros
15+
16+
17+
def test(output, expected):
18+
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
19+
20+
21+
ftm = FeatureTestMacros(sys.argv[2])
22+
test(
23+
ftm.implemented_ftms,
24+
{
25+
"__cpp_lib_any": {
26+
"c++17": "201606L",
27+
"c++20": "201606L",
28+
"c++23": "201606L",
29+
"c++26": "201606L",
30+
},
31+
"__cpp_lib_barrier": {
32+
"c++20": "201907L",
33+
"c++23": "201907L",
34+
"c++26": "201907L",
35+
},
36+
"__cpp_lib_format": {
37+
"c++20": None,
38+
"c++23": None,
39+
"c++26": None,
40+
},
41+
"__cpp_lib_parallel_algorithm": {
42+
"c++17": "201603L",
43+
"c++20": "201603L",
44+
"c++23": "201603L",
45+
"c++26": "201603L",
46+
},
47+
"__cpp_lib_variant": {
48+
"c++17": "202102L",
49+
"c++20": "202102L",
50+
"c++23": "202102L",
51+
"c++26": "202102L",
52+
},
53+
},
54+
)
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# ===----------------------------------------------------------------------===##
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
# ===----------------------------------------------------------------------===##
8+
9+
# RUN: %{python} %s %{libcxx-dir}/utils %t
10+
11+
import sys
12+
import json
13+
14+
sys.path.append(sys.argv[1])
15+
from generate_feature_test_macro_components import FeatureTestMacros
16+
17+
18+
def test(output, expected):
19+
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
20+
21+
22+
def test_error(data, type, message):
23+
tmp = sys.argv[2]
24+
with open(tmp, "w") as file:
25+
file.write(json.dumps(data))
26+
ftm = FeatureTestMacros(tmp)
27+
try:
28+
ftm.implemented_ftms
29+
except type as error:
30+
test(str(error), message)
31+
else:
32+
assert False, "no exception was thrown"
33+
34+
35+
test_error(
36+
[
37+
{
38+
"values": {
39+
"c++17": {
40+
"197001": [
41+
{
42+
"implemented": False,
43+
},
44+
],
45+
},
46+
},
47+
"headers": [],
48+
},
49+
],
50+
KeyError,
51+
"'name'",
52+
)
53+
54+
test_error(
55+
[
56+
{
57+
"name": "a",
58+
"headers": [],
59+
},
60+
],
61+
KeyError,
62+
"'values'",
63+
)
64+
65+
test_error(
66+
[
67+
{
68+
"name": "a",
69+
"values": {},
70+
"headers": [],
71+
},
72+
],
73+
AssertionError,
74+
"'values' is empty",
75+
)
76+
77+
78+
test_error(
79+
[
80+
{
81+
"name": "a",
82+
"values": {
83+
"c++17": {},
84+
},
85+
"headers": [],
86+
},
87+
],
88+
AssertionError,
89+
"a[c++17] has no entries",
90+
)
91+
92+
test_error(
93+
[
94+
{
95+
"name": "a",
96+
"values": {
97+
"c++17": {
98+
"197001": [
99+
{},
100+
],
101+
},
102+
},
103+
"headers": [],
104+
},
105+
],
106+
KeyError,
107+
"'implemented'",
108+
)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# ===----------------------------------------------------------------------===##
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
# ===----------------------------------------------------------------------===##
8+
9+
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
10+
11+
import sys
12+
13+
sys.path.append(sys.argv[1])
14+
from generate_feature_test_macro_components import FeatureTestMacros
15+
16+
17+
def test(output, expected):
18+
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
19+
20+
21+
ftm = FeatureTestMacros(sys.argv[2])
22+
test(
23+
ftm.standard_ftms,
24+
{
25+
"__cpp_lib_any": {
26+
"c++17": "201606L",
27+
"c++20": "201606L",
28+
"c++23": "201606L",
29+
"c++26": "201606L",
30+
},
31+
"__cpp_lib_barrier": {
32+
"c++20": "201907L",
33+
"c++23": "201907L",
34+
"c++26": "201907L",
35+
},
36+
"__cpp_lib_format": {
37+
"c++20": "202110L",
38+
"c++23": "202207L",
39+
"c++26": "202311L",
40+
},
41+
"__cpp_lib_parallel_algorithm": {
42+
"c++17": "201603L",
43+
"c++20": "201603L",
44+
"c++23": "201603L",
45+
"c++26": "201603L",
46+
},
47+
"__cpp_lib_variant": {
48+
"c++17": "202102L",
49+
"c++20": "202106L",
50+
"c++23": "202106L",
51+
"c++26": "202306L",
52+
},
53+
},
54+
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# ===----------------------------------------------------------------------===##
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
# ===----------------------------------------------------------------------===##
8+
9+
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
10+
11+
import sys
12+
13+
sys.path.append(sys.argv[1])
14+
from generate_feature_test_macro_components import FeatureTestMacros
15+
16+
17+
def test(output, expected):
18+
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
19+
20+
21+
ftm = FeatureTestMacros(sys.argv[2])
22+
test(
23+
ftm.std_dialects,
24+
[
25+
"c++17",
26+
"c++20",
27+
"c++23",
28+
"c++26",
29+
],
30+
)

0 commit comments

Comments
 (0)