File: generate_iwyu_mapping_msvc.py

package info (click to toggle)
monado 25.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,708 kB
  • sloc: cpp: 175,132; ansic: 141,570; python: 2,913; java: 753; xml: 735; sh: 403; javascript: 255; makefile: 58
file content (57 lines) | stat: -rw-r--r-- 1,487 bytes parent folder | download
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
52
53
54
55
56
57
#!/usr/bin/env python3
# Copyright 2022-2023, Collabora, Ltd.
#
# SPDX-License-Identifier: BSL-1.0
#
# Original author: Rylie Pavlik <rylie.pavlik@collabora.com
"""Script to set up msvc.imp for include-what-you-use."""
from pathlib import Path
from generate_iwyu_mapping import write_mapping_file

_SCRIPT_DIR = Path(__file__).parent.resolve()
_OUTPUT_FILENAME = _SCRIPT_DIR / "msvc.imp"

_STL_EQUIVS = {
    "<xutility>": ["<utility>"],
    "<xstring>": ["<string>"],
    "<xatomic.h>": ["<atomic>"],
    "<xtr1common>": ["<type_traits>"],
    "<corecrt_math.h>": ["<math.h>", "<cmath>"],
    "<vcruntime_exceptions.h>": ["<exception>"],
    # This header contains common functionality used by a ton of containers
    "<xmemory>": [
        "<deque>",
        "<filesystem>",
        "<forward_list>",
        "<functional>",
        "<future>",
        "<hash_map>",
        "<hash_set>",
        "<list>",
        "<map>",
        "<memory>",
        "<set>",
        "<string>",
        "<unordered_map>",
        "<unordered_set>",
        "<vector>",
    ],
}


def get_all_stl_entries():
    for src, dests in _STL_EQUIVS.items():
        for dest in dests:
            yield """{ include: ["%s", "private", "%s", "public"] },""" % (
                src,
                dest,
            )


def write_file():
    entries = list(get_all_stl_entries())
    write_mapping_file(entries, _OUTPUT_FILENAME, Path(__file__).resolve().name)


if __name__ == "__main__":
    write_file()