aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/.yandex_meta/scripts/sysincls.py
blob: a3fb43e6ea56270f63b1dc143eec04671be601bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3

import pathlib
import sys

include_dir = pathlib.Path(sys.argv[1]) / "include"
sysicncl_path = pathlib.Path(sys.argv[2])
sysincl = open(sysicncl_path).read()

GENERATED_BEG = "# GENERATED BY YM2\n"
GENERATED_END = "# END OF GENERATION\n"

assert sysincl.count("# GENERATED BY YM2") == 1
assert sysincl.count("# END OF GENERATION") == 1

headers = []

for header in include_dir.glob("**/*"):
    if not header.is_file():
        continue

    rel_path = header.relative_to(include_dir)

    if header.parent == include_dir:
        if header.name.startswith("__") or not '.' in header.name:
            headers.append(rel_path)
    else:
        str_path = str(rel_path)
        if str_path.startswith('experimental') or str_path.startswith('ext'):
            continue
        headers.append(rel_path)

headers = sorted(headers, key = lambda header: (str(header).count('/') != 0, str(header).count('__') != 0, header))

manual, generated = sysincl.split(GENERATED_BEG)
generated, manual_end = generated.split(GENERATED_END)

generated = []

for header in headers:
    generated.append(
        "  - {name}:{spaces}contrib/libs/cxxsupp/libcxx/include/{name}".format(
            name=str(header),
            spaces=' ' * max(1, 54 - len(str(header)))
        )
    )

generated = "- includes:\n" + '\n'.join(generated)

with open(sysicncl_path, 'w') as f:
    f.write(f"{manual}{GENERATED_BEG}{generated}\n{GENERATED_END}{manual_end}")