1 Star 0 Fork 11

DengSir/rpc-repo

forked from Plato/rpc-repo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
lua_driver.py 8.86 KB
一键复制 编辑 原始数据 按行查看 历史
dennis-kk 提交于 2022-03-13 17:12 . FIX BUG
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import shutil
import json
import platform
import sys
import subprocess
import glob
from driver import Initializer
from driver import Builder
from util import *
from option import Options
class Initializer_lua(Initializer):
def __init__(self, options, version, proj_root):
Initializer.__init__(self, options, version, proj_root)
def check(self):
if not os.path.exists("repo.init"):
print("Base repo. uninitialized.")
return False
if not os.path.exists("repo.init.lua"):
return self.init()
else:
return True
def build_frontend(self):
pass
def build_backend(self):
pass
def init(self):
os.chdir("tmp")
if os.path.exists('rpc-backend-lua'):
os.chdir("rpc-backend-lua")
os.system('git pull --no-rebase "origin" ' + self.get_version())
os.chdir('..')
else:
if os.system('git clone -b '+self.get_version()+' https://gitee.com/dennis-kk/rpc-backend-lua') != 0:
print('git clone -b '+self.get_version()+' https://gitee.com/dennis-kk/rpc-backend-lua')
return False
shutil.copyfile("rpc-backend-lua/luagen.py", "../bin/luagen.py")
if os.path.exists('rpc-backend-lua/luagen_sdk.py'):
shutil.copyfile("rpc-backend-lua/luagen_sdk.py", "../bin/luagen_sdk.py")
if not os.path.exists("../src/idl/lua/sdk"):
os.makedirs("../src/idl/lua/sdk")
shutil.copyfile("rpc-backend-lua/sdk.lua", "../src/idl/lua/sdk/sdk.lua")
shutil.copyfile("rpc-backend-lua/const.lua", "../src/idl/lua/sdk/const.lua")
shutil.copyfile("rpc-backend-lua/coder.lua", "../src/idl/lua/sdk/coder.lua")
os.chdir("..")
open("repo.init.lua", "w").close()
return True
def checkEnv(self):
os.system("protoc --version")
os.system("git --version")
os.system("cmake --version")
if platform.system() == "Linux":
if os.system("gcc --version") != 0:
os.system("clang --version")
else:
print("Visual Studio 16 2019")
class Builder_lua(Builder):
def __init__(self, options, version, proj_root):
Builder.__init__(self, options, version, proj_root)
self.cwd = os.getcwd().replace('\\', '/')
def build_idl(self, name, sname = None, type = None, make_service_type=None,version=""):
pass
def build_sdk(self, name, sname=None, build_type="all"):
if os.path.exists("bin/luagen_sdk.py"):
if os.path.exists('src/idl/lua/sdk/proxy.lua'):
shutil.copyfile('src/idl/lua/sdk/proxy.lua', 'pub/sdk/lua/proxy.lua')
if os.path.exists('src/idl/lua/sdk/stub.lua'):
shutil.copyfile('src/idl/lua/sdk/stub.lua', 'pub/sdk/lua/stub.lua')
if os.path.exists('src/idl/lua/sdk/mapper.lua'):
shutil.copyfile('src/idl/lua/sdk/mapper.lua', 'pub/sdk/lua/mapper.lua')
def addIdl2Repo(self, file_name, sname = None, add=True):
if not add:
file_name = "src/idl/" + file_name
if not os.path.exists(file_name):
print(file_name + " not found")
return
file_name = self.check_idl_name(file_name)
if add:
shutil.copyfile(file_name, "src/idl/" + os.path.basename(file_name))
os.chdir("src/idl/")
cmd = subprocess.Popen(["../../bin/rpc-frontend", "-f", os.path.basename(file_name)], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, encoding='utf-8')
ret = cmd.communicate()
if cmd.returncode != 0:
print("exec frontend error ", "".join(ret))
return
for file in glob.glob('*.cpp.json'):
cmd = subprocess.Popen(["python", "../../bin/luagen.py", file, '--proxy-only'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
ret = cmd.communicate()
if cmd.returncode != 0:
print("luagen.py failed for "+file)
print("".join(ret))
return
if os.path.exists("../../bin/luagen_sdk.py"):
if os.path.exists('./lua/sdk/proxy.lua'):
os.remove('./lua/sdk/proxy.lua')
if os.path.exists('./lua/sdk/stub.lua'):
os.remove('./lua/sdk/stub.lua')
if os.path.exists('./lua/sdk/mapper.lua'):
os.remove('./lua/sdk/mapper.lua')
for file in glob.glob('*.cpp.json'):
if os.path.exists("../../bin/luagen_sdk.py"):
cmd = subprocess.Popen(["python", "../../bin/luagen_sdk.py", file], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
ret = cmd.communicate()
if cmd.returncode != 0:
print("luagen_sdk.py failed for "+file)
print("".join(ret))
return
(base_name, _) = os.path.splitext(os.path.basename(file_name))
json_str = json.load(open(base_name + ".idl.cpp.json"))
if json_has_attr(json_str, "services"):
for service in json_str["services"]:
if sname is not None:
if sname != service['name']:
continue
is_lua = False
if not ("notations" in service.keys()):
continue
for notation in service["notations"]:
if "script_type" in notation.keys():
for script_type in notation["script_type"]:
if script_type == "lua":
is_lua = True
if not is_lua:
continue
cmd = subprocess.Popen(["python", "../../bin/luagen.py", base_name + ".idl.cpp.json"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
ret = cmd.communicate()
if cmd.returncode != 0:
print("luagen.py failed for "+base_name + ".idl.cpp.json")
print("".join(ret))
return
if not os.path.exists(self.proj_root+"/usr/lua/" + base_name +'/' + service['name'] + "/stub"):
os.makedirs(self.proj_root+"/usr/lua/" + base_name+'/' + service['name'] + "/stub")
if not os.path.exists(self.proj_root+"/usr/lua/" + base_name+'/' + service['name'] + "/script"):
os.makedirs(self.proj_root+"/usr/lua/" + base_name+'/'+ service['name'] + "/script")
if not os.path.exists(self.proj_root+"/usr/lua/lua_proxy"):
os.makedirs(self.proj_root+"/usr/lua/lua_proxy")
if not os.path.exists(self.proj_root+"/usr/lua/proto"):
os.makedirs(self.proj_root+"/usr/lua/proto")
if not os.path.exists(self.proj_root+"/usr/lua/json"):
os.makedirs(self.proj_root+"/usr/lua/json")
if not os.path.exists(self.proj_root+"/usr/lua/" + base_name+'/'+ service['name'] + "/script/main.lua") and os.path.exists(service['name'] + "/script/main.lua"):
shutil.copyfile(service['name'] + "/script/main.lua", self.proj_root+"/usr/lua/" + base_name+'/'+ service['name'] + "/script/main.lua")
if os.path.exists(service['name'] + "/stub/stub.lua"):
shutil.copyfile(service['name'] + "/stub/stub.lua", self.proj_root+"/usr/lua/" + base_name+'/'+ service['name'] + "/stub/stub.lua")
for file in glob.glob("lua_proxy/*.lua"):
shutil.copy(file, self.proj_root+"/usr/lua/lua_proxy")
for file in glob.glob("*.cpp.json"):
shutil.copy(file, self.proj_root+"/usr/lua/json")
for file in glob.glob("*.proto"):
shutil.copy(file, self.proj_root+"/usr/lua/proto")
os.chdir("../../")
def updateRoot(self):
initializer = Initializer_lua(Options(), self.get_version(), self.proj_root)
os.chdir("tmp/rpc-frontend/")
os.system('git pull origin')
os.chdir("..")
initializer.build_frontend()
os.chdir("..")
os.chdir("tmp/rpc-backend-lua/")
os.system('git pull --no-rebase "origin" ' + self.get_version())
shutil.copyfile("luagen.py", "../../bin/luagen.py")
if os.path.exists('luagen_sdk.py'):
shutil.copyfile("luagen_sdk.py", "../../bin/luagen_sdk.py")
if not os.path.exists("../../src/idl/lua/sdk"):
os.makedirs("../../src/idl/lua/sdk")
shutil.copyfile("sdk.lua", "../../src/idl/lua/sdk/sdk.lua")
shutil.copyfile("const.lua", "../../src/idl/lua/sdk/const.lua")
shutil.copyfile("coder.lua", "../../src/idl/lua/sdk/coder.lua")
os.chdir("..")
initializer.build_backend()
os.chdir("../../")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/DengSir/rpc-repo.git
[email protected]:DengSir/rpc-repo.git
DengSir
rpc-repo
rpc-repo
v0.3.0-alpha

搜索帮助