-
Notifications
You must be signed in to change notification settings - Fork 3
/
compile.py
87 lines (76 loc) · 2.52 KB
/
compile.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
import glob
import sys
CURRENT_DIRECTORY = os.getcwd()
XRAY_API_PATH = os.path.join(CURRENT_DIRECTORY, 'xray_api')
DIST_PATH = os.path.join(CURRENT_DIRECTORY, 'dist')
PYTHON_OUTPUT_PATH = os.path.join(DIST_PATH, "python")
CPP_OUTPUT_PATH = os.path.join(DIST_PATH, "cpp")
CSHARP_OUTPUT_PATH = os.path.join(DIST_PATH, "csharp")
RUBY_OUTPUT_PATH = os.path.join(DIST_PATH, "ruby")
NODEJS_OUTPUT_PATH = os.path.join(DIST_PATH, "nodejs")
def find_proto_files():
return glob.glob(os.path.join(XRAY_API_PATH, '**', '*.proto'), recursive=True)
proto_files = find_proto_files()
if len(sys.argv) < 2:
print("Please use the script correctly!")
sys.exit(1)
compiler = sys.argv[1]
if compiler == "python":
command = (
f"python -m grpc_tools.protoc "
f"--proto_path={XRAY_API_PATH} "
f"--python_out={PYTHON_OUTPUT_PATH} "
f"--grpc_python_out={PYTHON_OUTPUT_PATH} "
f"{' '.join(proto_files)}"
)
elif compiler == "cpp":
command = (
f"protoc "
f"--proto_path={XRAY_API_PATH} "
f"--cpp_out={CPP_OUTPUT_PATH} "
f"--grpc_out={CPP_OUTPUT_PATH} "
"--plugin=protoc-gen-grpc=$(which grpc_cpp_plugin) "
f"{' '.join(proto_files)}"
)
elif compiler == "csharp":
command = (
f"protoc "
f"--proto_path={XRAY_API_PATH} "
f"--csharp_out={CSHARP_OUTPUT_PATH} "
f"--grpc_out={CSHARP_OUTPUT_PATH} "
"--plugin=protoc-gen-grpc=$(which grpc_csharp_plugin) "
f"{' '.join(proto_files)}"
)
elif compiler == "ruby":
command = (
f"protoc "
f"--proto_path={XRAY_API_PATH} "
f"--ruby_out={RUBY_OUTPUT_PATH} "
f"--grpc_out={RUBY_OUTPUT_PATH} "
"--plugin=protoc-gen-grpc=$(which grpc_ruby_plugin) "
f"{' '.join(proto_files)}"
)
elif compiler == "nodejs":
command = (
f"protoc "
f"--proto_path={XRAY_API_PATH} "
f"--js_out={RUBY_OUTPUT_PATH} "
f"--grpc_out={RUBY_OUTPUT_PATH} "
"--plugin=protoc-gen-grpc=$(which grpc_node_plugin) "
f"{' '.join(proto_files)}"
)
else:
print("warning: not valid input! we will compile for python")
command = (
f"python -m grpc_tools.protoc "
f"--proto_path={XRAY_API_PATH} "
f"--python_out={PYTHON_OUTPUT_PATH} "
f"--grpc_python_out={PYTHON_OUTPUT_PATH} "
f"{' '.join(proto_files)}"
)
exit_code = os.system(command)
if exit_code == 0:
print("Proto files compiled successfully.")
else:
print("Error: Proto files compilation failed.")