• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# RUN: %{python} %s
2
3# Verify that each list of private submodules in libcxx/include/module.modulemap.in
4# is maintained in alphabetical order.
5
6import os
7import re
8
9
10if __name__ == "__main__":
11    libcxx_test_libcxx_lint = os.path.dirname(os.path.abspath(__file__))
12    libcxx = os.path.abspath(os.path.join(libcxx_test_libcxx_lint, "../../.."))
13    modulemap_name = os.path.join(libcxx, "include/module.modulemap.in")
14    assert os.path.isfile(modulemap_name)
15
16    okay = True
17    prevline = None
18    with open(modulemap_name, "r") as f:
19        for line in f.readlines():
20            if re.match(r"^\s*module.*[{]\s*private", line):
21                # Check that these lines are all of the expected format.
22                # This incidentally checks for typos in the module name.
23                if re.match(
24                    r'^\s*module (\w+)\s+[{] private header "\1(.h)?"\s+export [*] [}]',
25                    line,
26                ):
27                    # It's a top-level private header, such as <__bit_reference>.
28                    pass
29                elif re.match(
30                    r'^\s*module (\w+)\s+[{] private (textual )?header "__(\w+/)*\1[.]h" [}]',
31                    line,
32                ):
33                    # It's a private submodule, such as <__utility/swap.h>.
34                    pass
35                elif re.match(
36                    r'^\s*module (\w+)_fwd\s+[{] private header "__fwd/\1[.]h" [}]',
37                    line,
38                ):
39                    # It's a private submodule with forward declarations, such as <__fwd/span.h>.
40                    pass
41                elif re.match(
42                    r'^\s*module (?:\w+_)*(\w+)\s+[{] private (textual )?header "__(\w+/)*\1[.]h" [}]',
43                    line,
44                ):
45                    # It's a private pstl submodule, such as <__algorithm/pstl_backends/cpu_backend.h>
46                    pass
47                else:
48                    okay = False
49                    print(
50                        "LINE DOESN'T MATCH REGEX in libcxx/include/module.modulemap.in!"
51                    )
52                    print(line)
53                # Check that these lines are alphabetized.
54                if (prevline is not None) and (line < prevline):
55                    okay = False
56                    print("LINES OUT OF ORDER in libcxx/include/module.modulemap.in!")
57                    print(prevline)
58                    print(line)
59                prevline = line
60            else:
61                prevline = None
62    assert okay
63