Skip to content

Commit a011cba

Browse files
committed
Simplify whether a header is present.
This use the status used for the Standard library modules.
1 parent da82709 commit a011cba

12 files changed

+62
-96
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class Test(unittest.TestCase):
2323
def setUp(self):
24-
self.ftm = FeatureTestMacros(TEST_DATA)
24+
self.ftm = FeatureTestMacros(TEST_DATA, ["charconv"])
2525
self.maxDiff = None # This causes the diff to be printed when the test fails
2626

2727
def test_implementation(self):

libcxx/test/libcxx/feature_test_macro/generate_header_test.sh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
class Test(unittest.TestCase):
2525
def setUp(self):
26-
self.ftm = FeatureTestMacros(TEST_DATA)
26+
self.ftm = FeatureTestMacros(TEST_DATA, ["charconv"])
2727
self.maxDiff = None # This causes the diff to be printed when the test fails
2828

2929
self.expected = dict(
@@ -299,7 +299,7 @@ def setUp(self):
299299
300300
// clang-format off
301301
302-
#if __has_include(<charconv>)
302+
#if !defined(_WIN32) && __has_include(<charconv>)
303303
# include <charconv>
304304
#endif
305305
#include "test_macros.h"

libcxx/test/libcxx/feature_test_macro/implemented_ftms.sh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class Test(unittest.TestCase):
2323
def setUp(self):
24-
self.ftm = FeatureTestMacros(TEST_DATA)
24+
self.ftm = FeatureTestMacros(TEST_DATA, ["charconv"])
2525
self.maxDiff = None # This causes the diff to be printed when the test fails
2626

2727
def test_implementation(self):

libcxx/test/libcxx/feature_test_macro/implemented_standard_library_headers.sh.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

libcxx/test/libcxx/feature_test_macro/invalid.sh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_error(data, type, message):
2323
tmp = sys.argv[2]
2424
with open(tmp, "w") as file:
2525
file.write(json.dumps(data))
26-
ftm = FeatureTestMacros(tmp)
26+
ftm = FeatureTestMacros(tmp, ["charconv"])
2727
try:
2828
ftm.implemented_ftms
2929
except type as error:

libcxx/test/libcxx/feature_test_macro/is_implemented.sh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class Test(unittest.TestCase):
2323
def setUp(self):
24-
self.ftm = FeatureTestMacros(TEST_DATA)
24+
self.ftm = FeatureTestMacros(TEST_DATA, ["charconv"])
2525
self.maxDiff = None # This causes the diff to be printed when the test fails
2626

2727
def test_implementation(self):

libcxx/test/libcxx/feature_test_macro/standard_ftms.sh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class Test(unittest.TestCase):
2323
def setUp(self):
24-
self.ftm = FeatureTestMacros(TEST_DATA)
24+
self.ftm = FeatureTestMacros(TEST_DATA, ["charconv"])
2525
self.maxDiff = None # This causes the diff to be printed when the test fails
2626

2727
def test_implementation(self):

libcxx/test/libcxx/feature_test_macro/standard_library_headers.sh.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,35 @@
1010

1111
import sys
1212

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-
sorted(ftm.standard_library_headers),
24-
[
25-
"algorithm",
26-
"any",
27-
"barrier",
28-
"charconv",
29-
"format",
30-
"numeric",
31-
"variant",
32-
],
33-
)
13+
import unittest
14+
15+
UTILS = sys.argv[1]
16+
TEST_DATA = sys.argv[2]
17+
del sys.argv[1:3]
18+
19+
sys.path.append(UTILS)
20+
from generate_feature_test_macro_components import FeatureTestMacros, Metadata
21+
22+
23+
class Test(unittest.TestCase):
24+
def setUp(self):
25+
self.ftm = FeatureTestMacros(TEST_DATA, ["charconv"])
26+
self.maxDiff = None # This causes the diff to be printed when the test fails
27+
28+
def test_implementation(self):
29+
self.assertEqual(
30+
sorted(self.ftm.standard_library_headers),
31+
[
32+
"algorithm",
33+
"any",
34+
"barrier",
35+
"charconv",
36+
"format",
37+
"numeric",
38+
"variant",
39+
],
40+
)
41+
42+
43+
if __name__ == "__main__":
44+
unittest.main()

libcxx/test/libcxx/feature_test_macro/std_dialects.sh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class Test(unittest.TestCase):
2323
def setUp(self):
24-
self.ftm = FeatureTestMacros(TEST_DATA)
24+
self.ftm = FeatureTestMacros(TEST_DATA, ["charconv"])
2525
self.maxDiff = None # This causes the diff to be printed when the test fails
2626

2727
def test_implementation(self):

libcxx/test/libcxx/feature_test_macro/version_header.sh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class Test(unittest.TestCase):
2323
def setUp(self):
24-
self.ftm = FeatureTestMacros(TEST_DATA)
24+
self.ftm = FeatureTestMacros(TEST_DATA, ["charconv"])
2525
self.maxDiff = None # This causes the diff to be printed when the test fails
2626

2727
def test_implementeation(self):

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class Test(unittest.TestCase):
2323
def setUp(self):
24-
self.ftm = FeatureTestMacros(TEST_DATA)
24+
self.ftm = FeatureTestMacros(TEST_DATA, ["charconv"])
2525
self.maxDiff = None # This causes the diff to be printed when the test fails
2626

2727
def test_implementation(self):

libcxx/utils/generate_feature_test_macro_components.py

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,8 +2110,12 @@ def generate_version_header_implementation(
21102110
#include <{header}>\
21112111
"""
21122112

2113+
# On Windows the Windows SDK is on the include path, that means the MSVC STL
2114+
# headers can be found as well, tricking __has_include into thinking that
2115+
# libc++ provides the header. This means the test is also not executed when
2116+
# using this test with MSVC and MSVC STL.
21132117
ftm_header_test_file_include_conditional = """\
2114-
#if __has_include(<{header}>)
2118+
#if !defined(_WIN32) && __has_include(<{header}>)
21152119
# include <{header}>
21162120
#endif\
21172121
"""
@@ -2264,12 +2268,21 @@ class FeatureTestMacros:
22642268

22652269
# The JSON data structure.
22662270
__data = None
2267-
2268-
def __init__(self, filename: str):
2271+
# The headers not available in libc++.
2272+
#
2273+
# This could be detected based on FTM status, however that gives some odd
2274+
# results. For example, at the moment __cpp_lib_constexpr_cmath is not
2275+
# implemented, which flags `<cstdlib>` as not implemented. The availablilty
2276+
# of headers in maintained for the C++ Standard Libarary modules.
2277+
__unavailable_headers = None
2278+
2279+
def __init__(self, filename: str, not_implemented_headers: List[str]):
22692280
"""Initializes the class with the JSON data in the file 'filename'."""
22702281
with open(filename) as f:
22712282
self.__data = json.load(f)
22722283

2284+
self.__unavailable_headers = set(not_implemented_headers)
2285+
22732286
@functools.cached_property
22742287
def std_dialects(self) -> List[Std]:
22752288
"""Returns the C++ dialects avaiable.
@@ -2321,32 +2334,6 @@ def implemented_ftms(self) -> Dict[Ftm, Dict[Std, Optional[Value]]]:
23212334

23222335
return get_ftms(self.__data, self.std_dialects, True)
23232336

2324-
@functools.cached_property
2325-
def implemented_standard_library_headers(self) -> Set[str]:
2326-
"""Returns a list of headers that contain at least one paper implemented in libc++.
2327-
2328-
When a paper is implemented it means the associated header(s) should exist.
2329-
"""
2330-
2331-
result = set()
2332-
for feature in self.__data:
2333-
for std in self.std_dialects:
2334-
if std in feature["values"].keys():
2335-
values = feature["values"][std]
2336-
assert len(values) > 0, f"{feature['name']}[{std}] has no entries"
2337-
for value in values:
2338-
papers = list(values[value])
2339-
assert (
2340-
len(papers) > 0
2341-
), f"{feature['name']}[{std}][{value}] has no entries"
2342-
for paper in papers:
2343-
if paper["implemented"]:
2344-
for header in self.ftm_metadata[feature["name"]].headers:
2345-
result.add(header)
2346-
break
2347-
2348-
return result
2349-
23502337

23512338
def is_implemented(self, ftm: Ftm, std: Std) -> bool:
23522339
"""Has the FTM `ftm` been implemented in the dialect `std`?"""
@@ -2523,9 +2510,9 @@ def generate_header_test(self, header: str) -> str:
25232510
lit_markup=self.generate_lit_markup(header),
25242511
header=header,
25252512
include=(
2526-
ftm_header_test_file_include_unconditional.format(header=header)
2527-
if header in self.implemented_standard_library_headers
2528-
else ftm_header_test_file_include_conditional.format(header=header)
2513+
ftm_header_test_file_include_conditional.format(header=header)
2514+
if header in self.__unavailable_headers
2515+
else ftm_header_test_file_include_unconditional.format(header=header)
25292516
),
25302517
data=
25312518
# FTM block before the first Standard that introduced them.
@@ -2583,7 +2570,7 @@ def main():
25832570
ftm = FeatureTestMacros(
25842571
os.path.join(
25852572
source_root, "test", "libcxx", "feature_test_macro", "test_data.json"
2586-
)
2573+
), headers_not_available
25872574
)
25882575
version_header_path = os.path.join(include_path, "version")
25892576
with open(version_header_path, "w", newline="\n") as f:

0 commit comments

Comments
 (0)