-
Notifications
You must be signed in to change notification settings - Fork 71
/
gen_protocol_v3.py
executable file
·66 lines (53 loc) · 1.83 KB
/
gen_protocol_v3.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import string
import glob
import sys
import codecs
from subprocess import Popen
work_dir = os.getcwd()
script_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir(script_dir)
project_dir = '../'
proto_dir = './proto_v3'
header_dir = os.path.join(project_dir, 'header')
tools_dir = os.path.join(project_dir, 'tools')
sys.path.append(tools_dir)
from find_protoc import find_protoc
common_args = [
"-I", proto_dir, "-I",
os.path.join(project_dir, 'third_party', 'xresloader-protocol', 'core',
'extensions', 'v3'), "-I",
os.path.join(project_dir, 'third_party', 'xresloader-protocol', 'common')
]
proto_file = glob.glob(os.path.join(proto_dir, '*.proto'))
# proto_file.append(os.path.join(header_dir, 'extensions', 'google', 'protobuf', 'descriptor.proto'))
# proto_file.extend(glob.glob(os.path.join(header_dir, 'extensions', 'v3', '*.proto')))
os.chdir(work_dir)
Popen([
sys.executable,
os.path.join(project_dir, 'loader-binding', 'cxx', 'gen_protocol_v3.py')
],
stdin=None,
stdout=None,
stderr=None,
shell=False).wait()
cpp_out_dir = os.path.join(script_dir, 'cxx')
proto_src_dir = os.path.join(cpp_out_dir, 'v3')
if not os.path.exists(proto_src_dir):
os.mkdir(proto_src_dir)
exec_args = [
find_protoc(), '-o',
os.path.join(proto_dir, 'kind.pb'), '--cpp_out', proto_src_dir
]
exec_args.extend(common_args)
exec_args.extend(proto_file)
gen_file = codecs.open(os.path.join(script_dir, 'gen_protocol_v3.gen.sh'),
"w",
encoding='utf-8')
gen_file.write("#!/bin/bash\n")
gen_file.write('"{0}"'.format('" "'.join(
[x.replace('\\', '/') for x in exec_args])))
Popen(exec_args, stdin=None, stdout=None, stderr=None, shell=False).wait()
print('Run "{0}" done'.format('" "'.join(exec_args)))