-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
98 lines (73 loc) · 2.76 KB
/
Copy pathmain.py
File metadata and controls
98 lines (73 loc) · 2.76 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from pathlib import Path
import sys
from core.analyzer.entity_builder import EntityBuilder
from core.analyzer.hasbits_analyzer import HasBitsAnalyzer
from core.analyzer.include_analyzer import IncludeAnalyzer
from core.analyzer.inheritance_analyzer import InheritanceAnalyzer
from core.analyzer.layout_order_analyzer import LayoutOrderAnalyzer
from core.analyzer.proto_reader import ProtoReader
from core.cli import parse_args
from core.generator.hpp import hpp_dump_modules
from core.resolver import resolve_inputs
from core.utils.logging import setup_logger
from core.protoc import compile_proto, resolve_protoc_binary, validate_protoc_bin_version
from core.utils.type_registery import TypeRegistry
def main():
args = parse_args()
workdir = Path(args.workdir)
# init logger (global)
log = setup_logger(args.log)
log.info("=== CS2ProtoMap started ===")
log.debug(f"Workdir: {args.workdir}")
log.debug(f"Inputs: {args.inputs}")
# resolve inputs (local + url → workdir/protos)
files = resolve_inputs(args.inputs, workdir, args.force_proto)
log.info(f"Resolved {len(files)} proto files")
for f in files:
log.debug(f" - {f}")
log.info("Step 1 complete: inputs resolved")
protoc_path = resolve_protoc_binary(args.protoc_path)
if not protoc_path:
sys.exit(1)
if not validate_protoc_bin_version(protoc_path):
sys.exit(1)
artifacts = []
for f in files:
artifact = compile_proto(
protoc_path,
f,
proto_paths=[f.parent, ],
workdir=workdir,
force=args.force_compile
)
if not artifact:
sys.exit(1)
artifacts.append(artifact)
log.info("Step 2 complete: compile protos")
reader = ProtoReader()
builder = EntityBuilder()
hasbits = HasBitsAnalyzer()
layout = LayoutOrderAnalyzer()
inheritance = InheritanceAnalyzer()
include = IncludeAnalyzer()
type_registry = TypeRegistry()
modules = []
for artifact in artifacts:
text = artifact.proto.read_text(errors="ignore")
parsed = reader.read(text)
module = builder.build(artifact, parsed)
modules.append(module)
hasbits.analyze(module)
layout.analyze(module)
inheritance.analyze(module)
include.analyze(module)
type_registry.register_module(module)
for module in modules:
log.info(
f'{module.artifact.proto.name}: class={len(module.classes)} enum={len(module.enums)} include={len(module.includes)}')
log.info("Step 3 complete: analyze proto files")
if args.hpp_out:
hpp_dump_modules(modules, Path(args.hpp_out), type_registry)
log.info("Step 4 complete: dump result")
if __name__ == "__main__":
main()