forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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.
- Loading branch information
Showing
6 changed files
with
591 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
libcxx/test/libcxx/feature_test_macro/implemented_ftms.sh.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# ===----------------------------------------------------------------------===## | ||
# | ||
# 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.implemented_ftms, | ||
{ | ||
"__cpp_lib_any": { | ||
"c++17": "201606L", | ||
"c++20": "201606L", | ||
"c++23": "201606L", | ||
"c++26": "201606L", | ||
}, | ||
"__cpp_lib_barrier": { | ||
"c++20": "201907L", | ||
"c++23": "201907L", | ||
"c++26": "201907L", | ||
}, | ||
"__cpp_lib_format": { | ||
"c++20": None, | ||
"c++23": None, | ||
"c++26": None, | ||
}, | ||
"__cpp_lib_parallel_algorithm": { | ||
"c++17": "201603L", | ||
"c++20": "201603L", | ||
"c++23": "201603L", | ||
"c++26": "201603L", | ||
}, | ||
"__cpp_lib_variant": { | ||
"c++17": "202102L", | ||
"c++20": "202102L", | ||
"c++23": "202102L", | ||
"c++26": "202102L", | ||
}, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# ===----------------------------------------------------------------------===## | ||
# | ||
# 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 %t | ||
|
||
import sys | ||
import json | ||
|
||
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}" | ||
|
||
|
||
def test_error(data, type, message): | ||
tmp = sys.argv[2] | ||
with open(tmp, "w") as file: | ||
file.write(json.dumps(data)) | ||
ftm = FeatureTestMacros(tmp) | ||
try: | ||
ftm.implemented_ftms | ||
except type as error: | ||
test(str(error), message) | ||
else: | ||
assert False, "no exception was thrown" | ||
|
||
|
||
test_error( | ||
[ | ||
{ | ||
"values": { | ||
"c++17": { | ||
"197001": [ | ||
{ | ||
"implemented": False, | ||
}, | ||
], | ||
}, | ||
}, | ||
"headers": [], | ||
}, | ||
], | ||
KeyError, | ||
"'name'", | ||
) | ||
|
||
test_error( | ||
[ | ||
{ | ||
"name": "a", | ||
"headers": [], | ||
}, | ||
], | ||
KeyError, | ||
"'values'", | ||
) | ||
|
||
test_error( | ||
[ | ||
{ | ||
"name": "a", | ||
"values": {}, | ||
"headers": [], | ||
}, | ||
], | ||
AssertionError, | ||
"'values' is empty", | ||
) | ||
|
||
|
||
test_error( | ||
[ | ||
{ | ||
"name": "a", | ||
"values": { | ||
"c++17": {}, | ||
}, | ||
"headers": [], | ||
}, | ||
], | ||
AssertionError, | ||
"a[c++17] has no entries", | ||
) | ||
|
||
test_error( | ||
[ | ||
{ | ||
"name": "a", | ||
"values": { | ||
"c++17": { | ||
"197001": [ | ||
{}, | ||
], | ||
}, | ||
}, | ||
"headers": [], | ||
}, | ||
], | ||
KeyError, | ||
"'implemented'", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# ===----------------------------------------------------------------------===## | ||
# | ||
# 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.standard_ftms, | ||
{ | ||
"__cpp_lib_any": { | ||
"c++17": "201606L", | ||
"c++20": "201606L", | ||
"c++23": "201606L", | ||
"c++26": "201606L", | ||
}, | ||
"__cpp_lib_barrier": { | ||
"c++20": "201907L", | ||
"c++23": "201907L", | ||
"c++26": "201907L", | ||
}, | ||
"__cpp_lib_format": { | ||
"c++20": "202110L", | ||
"c++23": "202207L", | ||
"c++26": "202311L", | ||
}, | ||
"__cpp_lib_parallel_algorithm": { | ||
"c++17": "201603L", | ||
"c++20": "201603L", | ||
"c++23": "201603L", | ||
"c++26": "201603L", | ||
}, | ||
"__cpp_lib_variant": { | ||
"c++17": "202102L", | ||
"c++20": "202106L", | ||
"c++23": "202106L", | ||
"c++26": "202306L", | ||
}, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# ===----------------------------------------------------------------------===## | ||
# | ||
# 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.std_dialects, | ||
[ | ||
"c++17", | ||
"c++20", | ||
"c++23", | ||
"c++26", | ||
], | ||
) |
Oops, something went wrong.