1
This commit is contained in:
parent
360b1d2d8c
commit
80f14970e1
111
scripts/construct/build_pb.py
Normal file
111
scripts/construct/build_pb.py
Normal file
@ -0,0 +1,111 @@
|
||||
#coding utf8
|
||||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import threading
|
||||
import subprocess
|
||||
from optparse import OptionParser
|
||||
|
||||
g_is_terminated = False
|
||||
def is_terminated():
|
||||
return g_is_terminated
|
||||
|
||||
def printp_stdout(p):
|
||||
try:
|
||||
while not is_terminated():
|
||||
line = p.stdout.readline()
|
||||
if len(line) > 0:
|
||||
print(line, end = '')
|
||||
except Exception as e:
|
||||
print('build_pb stdout error:' + e)
|
||||
|
||||
def printp_stderr(p):
|
||||
try:
|
||||
while is_terminated():
|
||||
line = p.stderr.readline()
|
||||
if len(line) > 0:
|
||||
print(line, end = '')
|
||||
except Exception as e:
|
||||
print('build_pb stderr error:' + e)
|
||||
|
||||
def need_rebuild(pb_files):
|
||||
for proto_name in pb_files:
|
||||
if not os.path.isfile(proto_name + '.pb.cc'):
|
||||
return True
|
||||
s1 = os.stat(proto_name + '.pb.cc')
|
||||
s2 = os.stat('../tools/protobuild/' + proto_name + '.proto')
|
||||
if s1.st_mtime < s2.st_mtime:
|
||||
return True
|
||||
return False
|
||||
|
||||
def rebuild(cpp_out, python_out, pb_files):
|
||||
def genParams():
|
||||
cpp_param = ''
|
||||
py_param = ''
|
||||
for pb_file in pb_files:
|
||||
if cpp_out != '':
|
||||
cpp_param += 'protoc --proto_path=../tools/protobuild --cpp_out=%s ../tools/protobuild/%s.proto && ' % (cpp_out, pb_file)
|
||||
if python_out != '':
|
||||
py_param += '../../third_party/tools/bin/protoc --proto_path=../tools/protobuild --python_out=%s ../tools/protobuild/%s.proto && ' % (python_out, pb_file)
|
||||
return cpp_param + py_param + ' echo ""'
|
||||
global g_is_terminated
|
||||
try:
|
||||
# print(genParams())
|
||||
p = subprocess.Popen(
|
||||
genParams(),
|
||||
stdin = subprocess.PIPE,
|
||||
stdout = subprocess.PIPE,
|
||||
stderr = None,
|
||||
shell = True)
|
||||
t1 = threading.Thread(target = printp_stdout, args=(p, ))
|
||||
t2 = threading.Thread(target = printp_stderr, args=(p, ))
|
||||
t1.start()
|
||||
t2.start()
|
||||
p.wait()
|
||||
g_is_terminated = True
|
||||
t1.join()
|
||||
t2.join()
|
||||
sys.exit(p.returncode)
|
||||
except Exception as e:
|
||||
print('build_protocol rebuild error:' + str(e))
|
||||
|
||||
def repair_githooks():
|
||||
os.system('/bin/bash ../tools/scripts/githooks/install.sh')
|
||||
|
||||
parser = OptionParser(usage="%prog [options]")
|
||||
parser.add_option(
|
||||
"-n",
|
||||
"--nohooks",
|
||||
dest = "nohooks",
|
||||
help = "no repair git hooks",
|
||||
)
|
||||
parser.add_option(
|
||||
"",
|
||||
"--cpp_out",
|
||||
dest = "cpp_out",
|
||||
default = True,
|
||||
help = "",
|
||||
)
|
||||
parser.add_option(
|
||||
"",
|
||||
"--python_out",
|
||||
dest = "python_out",
|
||||
default = True,
|
||||
help = "",
|
||||
)
|
||||
parser.add_option(
|
||||
"",
|
||||
"--pb_files",
|
||||
dest = "pb_files",
|
||||
help = "",
|
||||
)
|
||||
(options, args) = parser.parse_args()
|
||||
#if not options.nohooks:
|
||||
# repair_githooks()
|
||||
|
||||
if need_rebuild(options.pb_files.split(',')):
|
||||
rebuild(options.cpp_out, options.python_out, options.pb_files.split(','))
|
||||
else:
|
||||
print('pb files already is the latest')
|
61
scripts/construct/build_script.py
Normal file
61
scripts/construct/build_script.py
Normal file
@ -0,0 +1,61 @@
|
||||
#coding utf8
|
||||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
import subprocess
|
||||
|
||||
g_is_terminated = False
|
||||
def is_terminated():
|
||||
return g_is_terminated
|
||||
|
||||
def printp_stdout(p):
|
||||
try:
|
||||
while not is_terminated():
|
||||
line = p.stdout.readline()
|
||||
if len(line) > 0:
|
||||
print(line, end = '')
|
||||
except Exception as e:
|
||||
print('build_script stdout error:' + e)
|
||||
|
||||
def printp_stderr(p):
|
||||
try:
|
||||
while is_terminated():
|
||||
line = p.stderr.readline()
|
||||
if len(line) > 0:
|
||||
print(line, end = '')
|
||||
except Exception as e:
|
||||
print('build_script stderr error:' + e)
|
||||
|
||||
def need_rebuild():
|
||||
if not os.path.isfile('game_wrap.cxx'):
|
||||
return True
|
||||
s1 = os.stat('game_wrap.cxx')
|
||||
s2 = os.stat('game.i')
|
||||
return s1.st_mtime < s2.st_mtime
|
||||
|
||||
def rebuild():
|
||||
global g_is_terminated
|
||||
try:
|
||||
p = subprocess.Popen('swig -builtin -c++ -python -o game_wrap.cxx game.i',
|
||||
stdin = subprocess.PIPE,
|
||||
stdout = subprocess.PIPE,
|
||||
stderr = None,
|
||||
shell = True)
|
||||
t1 = threading.Thread(target = printp_stdout, args=(p, ))
|
||||
t2 = threading.Thread(target = printp_stderr, args=(p, ))
|
||||
t1.start()
|
||||
t2.start()
|
||||
p.wait()
|
||||
g_is_terminated = True
|
||||
t1.join()
|
||||
t2.join()
|
||||
sys.exit(p.returncode)
|
||||
except Exception as e:
|
||||
print('build_script rebuild error:' + str(e))
|
||||
|
||||
if need_rebuild():
|
||||
rebuild()
|
||||
else:
|
||||
print('script files already is the latest')
|
Loading…
x
Reference in New Issue
Block a user