tmp: update build scripts.

dev
Apex Liu 2020-07-15 05:03:04 +08:00
parent 7bf682af0f
commit 74c4d08071
4 changed files with 238 additions and 219 deletions

View File

@ -164,10 +164,10 @@ def do_opt(opt):
script = 'build-server.py'
arg = '%s %s server' % (ctx.target_path, opt['bits'])
elif 'installer' == opt['name']:
elif 'server-installer' == opt['name']:
script = 'build-installer.py'
# arg = 'installer'
arg = '%s %s installer' % (ctx.dist, opt['bits'])
arg = '%s %s server-installer' % (ctx.dist, opt['bits'])
elif 'client' == opt['name']:
script = 'build-assist.py'
@ -229,44 +229,54 @@ def add_split(title=None):
def make_options():
if ctx.host_os in ['windows']:
add_split('common')
add_option('x86', 'ver', 'Update version setting')
add_split('client side')
add_split('prepare for client [build once]')
# add_option('x86', 'external', '[OBSOLETE] Build external dependency')
add_option('x86', 'ext-client', 'Build external libraries for client')
add_split('prepare for server [build once]')
add_option('x86', 'pysrt', 'Make Python-Runtime for python%s-x86' % env.py_ver_str)
add_option('x86', 'ext-server', 'Build external libraries for server')
add_split('version [build every release]')
add_option('x86', 'ver', 'Update version setting')
add_split('client side')
# add_option('x86', 'assist-exe', '[OBSOLETE] Assist Execute [%s]' % ctx.target_path)
add_option('x86', 'client', 'Build client applications [%s]' % ctx.target_path)
# add_option('x86', 'assist-rdp', 'Teleport RDP [%s]' % ctx.target_path)
# add_option('x86', 'assist-installer', '[OBSOLETE] Assist Installer')
add_option('x86', 'client-installer', 'Make client installer')
add_option('x86', 'clear-ext-client', 'Clear external libraries for client')
add_split('server side')
add_option('x86', 'pysrt', 'Make Python-Runtime for python%s-x86' % env.py_ver_str)
add_option('x86', 'ext-server', 'Build external libraries for server')
add_option('x86', 'server', 'Teleport Server [%s]' % ctx.target_path)
# add_option('x86', 'installer', '[OBSOLETE] Teleport Installer for %s' % ctx.host_os)
# add_option('x86', 'server', 'Teleport Server [%s]' % ctx.target_path)
add_option('x86', 'server-installer', 'Teleport Installer for %s' % ctx.host_os)
# add_option('x86', 'installer', '[OBSOLETE] Teleport Installer for %s' % ctx.host_os)
add_split('clear')
add_option('x86', 'clear-ext-client', 'Clear external libraries for client')
add_option('x86', 'clear-ext-server', 'Clear external libraries for server')
elif ctx.host_os == 'macos':
add_split('prepare for client [build once]')
add_option('x64', 'ext-client', 'Build external libraries for client')
add_split('version [build every release]')
add_option('x64', 'ver', 'Update version setting')
add_option('x86', 'ext-client', 'Build external libraries for client')
add_split('client side')
add_option('x64', 'assist-exe', 'Assist Execute [%s]' % ctx.target_path)
add_option('x64', 'assist-installer', 'Assist Installer')
add_split()
add_split('clear')
add_option('x86', 'clear-ext-client', 'Clear external libraries for client')
else:
add_option('x64', 'ver', 'Update version setting')
add_split()
add_split('prepare for server [build once]')
add_option('x64', 'pysrt', 'Make Python-Runtime for python%s-x64' % env.py_ver_str)
# add_option('x64', 'external', '[OBSOLETE] Build external dependency')
# add_option('x86', 'ext-client', 'Build external libraries for client')
add_option('x86', 'ext-server', 'Build external libraries for server')
add_option('x64', 'ext-server', 'Build external libraries for server')
add_split('version [build every release]')
add_option('x64', 'ver', 'Update version setting')
add_split('server side')
add_option('x64', 'server', 'Build server applications [%s]' % ctx.target_path)
# add_option('x64', 'installer', '[OBSOLETE] Make server installer for %s' % ctx.host_os)
add_option('x86', 'server-installer', 'Make server installer for %s' % ctx.host_os)
add_split()
add_option('x86', 'clear-ext-client', 'Clear external libraries for client')
add_option('x86', 'clear-ext-server', 'Clear external libraries for server')
add_option('x64', 'server-installer', 'Make server installer for %s' % ctx.host_os)
add_split('clear')
# add_option('x64', 'clear-ext-client', 'Clear external libraries for client')
add_option('x64', 'clear-ext-server', 'Clear external libraries for server')
def get_input(msg, log_func=cc.w):

View File

@ -1,201 +1,201 @@
# -*- coding: utf-8 -*-
import shutil
from core import colorconsole as cc
from core import makepyo
from core import utils
from core.env import env
from core.context import *
from core.ver import *
ctx = BuildContext()
with_rdp = os.path.exists(os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'rdp'))
with_telnet = os.path.exists(os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'telnet'))
class BuilderBase:
def __init__(self):
self.out_dir = ''
def build_installer(self):
pass
def _build_web(self, base_path, dist, target_path):
cc.n('make Teleport Web package...')
src_path = os.path.join(env.root_path, 'server', 'www')
pkg_path = os.path.join(src_path, 'packages')
tmp_path = os.path.join(base_path, '_tmp_web_')
if os.path.exists(tmp_path):
utils.remove(tmp_path)
shutil.copytree(os.path.join(src_path, 'teleport'), os.path.join(tmp_path, 'teleport'))
utils.remove(os.path.join(tmp_path, 'teleport', '.idea'))
cc.n(' - copy packages...')
# utils.copy_ex(pkg_path, os.path.join(tmp_path, 'packages'), 'packages-common')
utils.copy_ex(os.path.join(pkg_path, 'packages-{}'.format(dist)), os.path.join(tmp_path, 'packages', 'packages-{}'.format(dist)), ctx.bits_path)
self._remove_py_cache(os.path.join(tmp_path, 'packages'))
makepyo.remove_cache(tmp_path)
shutil.copytree(tmp_path, os.path.join(target_path, 'www'))
utils.remove(tmp_path)
def _remove_py_cache(self, path):
for parent, dir_list, _ in os.walk(path):
for d in dir_list:
d = d.lower()
if d == '__pycache__':
utils.remove(os.path.join(parent, d))
continue
self._remove_py_cache(os.path.join(parent, d))
class BuilderWin(BuilderBase):
def __init__(self):
super().__init__()
self.name = 'teleport-server-windows-{}-{}'.format(ctx.bits_path, VER_TP_SERVER)
self._final_file = os.path.join(env.root_path, 'out', 'installer', '{}.zip'.format(self.name))
self.dist_path = os.path.join(env.root_path, 'dist', 'server')
self.base_path = os.path.join(env.root_path, 'out', 'installer')
self.base_tmp = os.path.join(self.base_path, '_tmp_')
self.path_tmp = os.path.join(self.base_tmp, self.name)
self.path_tmp_data = os.path.join(self.path_tmp, 'data')
def build_installer(self):
cc.n('make teleport installer package...')
if os.path.exists(self.base_tmp):
utils.remove(self.base_tmp)
self._build_web(self.base_path, 'windows', self.path_tmp_data)
utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('web.ini.in', 'web.ini'))
utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('core.ini.in', 'core.ini'))
utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), 'tp_ssh_server.key')
out_path = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path)
bin_path = os.path.join(self.path_tmp_data, 'bin')
utils.copy_ex(out_path, bin_path, 'tp_web.exe')
utils.copy_ex(out_path, bin_path, 'tp_core.exe')
utils.copy_ex(out_path, bin_path, 'tpssh.dll')
utils.copy_ex(out_path, bin_path, 'tptelnet.dll')
if with_rdp:
utils.copy_ex(out_path, bin_path, 'tprdp.dll')
utils.copy_ex(os.path.join(env.root_path, 'out', 'pysrt'), bin_path, (ctx.dist_path, 'pysrt'))
# 复制安装所需的脚本
utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'setup.bat')
utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'script')
if os.path.exists(self._final_file):
utils.remove(self._final_file)
utils.make_zip(self.path_tmp, self._final_file)
# utils.remove(self.base_tmp)
class BuilderLinux(BuilderBase):
def __init__(self):
super().__init__()
self.name = 'teleport-server-linux-{}-{}'.format(ctx.bits_path, VER_TP_SERVER)
self._final_file = os.path.join(env.root_path, 'out', 'installer', '{}.tar.gz'.format(self.name))
self.dist_path = os.path.join(env.root_path, 'dist', 'server')
self.base_path = os.path.join(env.root_path, 'out', 'installer')
self.base_tmp = os.path.join(self.base_path, '_tmp_')
self.path_tmp = os.path.join(self.base_tmp, self.name)
self.path_tmp_data = os.path.join(self.path_tmp, 'data')
def build_installer(self):
cc.n('make teleport installer package...')
if os.path.exists(self.base_tmp):
utils.remove(self.base_tmp)
self._build_web(self.base_path, 'linux', self.path_tmp_data)
utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('web.ini.in', 'web.ini'))
utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('core.ini.in', 'core.ini'))
utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), 'tp_ssh_server.key')
# fix new line flag
utils.fix_new_line_flag(os.path.join(self.path_tmp_data, 'tmp', 'etc', 'web.ini'))
utils.fix_new_line_flag(os.path.join(self.path_tmp_data, 'tmp', 'etc', 'core.ini'))
out_path = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, 'bin')
bin_path = os.path.join(self.path_tmp_data, 'bin')
utils.copy_ex(out_path, bin_path, 'tp_web')
utils.copy_ex(out_path, bin_path, 'tp_core')
utils.copy_ex(out_path, bin_path, 'libtpssh.so')
utils.copy_ex(out_path, bin_path, 'libtptelnet.so')
if with_rdp:
utils.copy_ex(out_path, bin_path, 'libtprdp.so')
utils.copy_ex(os.path.join(env.root_path, 'out', 'pysrt'), bin_path, (ctx.dist_path, 'pysrt'))
# 复制安装所需的脚本
utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'setup.sh')
utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'script')
utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'daemon')
if os.path.exists(self._final_file):
utils.remove(self._final_file)
utils.make_targz(self.base_tmp, self.name, self._final_file)
# utils.remove(self.base_tmp)
def gen_builder(dist):
if dist == 'windows':
builder = BuilderWin()
elif dist == 'linux':
builder = BuilderLinux()
else:
raise RuntimeError('unsupported platform.')
ctx.set_dist(dist)
return builder
def main():
if not env.init():
return
builder = None
argv = sys.argv[1:]
for i in range(len(argv)):
if 'debug' == argv[i]:
ctx.set_target(TARGET_DEBUG)
elif 'x86' == argv[i]:
ctx.set_bits(BITS_32)
elif 'x64' == argv[i]:
ctx.set_bits(BITS_64)
elif argv[i] in ctx.dist_all:
builder = gen_builder(argv[i])
if builder is None:
builder = gen_builder(ctx.host_os)
if 'installer' in argv:
builder.build_installer()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
except RuntimeError as e:
cc.e(e.__str__())
except:
cc.f('got exception.')
# -*- coding: utf-8 -*-
import shutil
from core import colorconsole as cc
from core import makepyo
from core import utils
from core.env import env
from core.context import *
from core.ver import *
ctx = BuildContext()
with_rdp = os.path.exists(os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'rdp'))
with_telnet = os.path.exists(os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'telnet'))
class BuilderBase:
def __init__(self):
self.out_dir = ''
def build_installer(self):
pass
def _build_web(self, base_path, dist, target_path):
cc.n('make Teleport Web package...')
src_path = os.path.join(env.root_path, 'server', 'www')
pkg_path = os.path.join(src_path, 'packages')
tmp_path = os.path.join(base_path, '_tmp_web_')
if os.path.exists(tmp_path):
utils.remove(tmp_path)
shutil.copytree(os.path.join(src_path, 'teleport'), os.path.join(tmp_path, 'teleport'))
utils.remove(os.path.join(tmp_path, 'teleport', '.idea'))
cc.n(' - copy packages...')
# utils.copy_ex(pkg_path, os.path.join(tmp_path, 'packages'), 'packages-common')
utils.copy_ex(os.path.join(pkg_path, 'packages-{}'.format(dist)), os.path.join(tmp_path, 'packages', 'packages-{}'.format(dist)), ctx.bits_path)
self._remove_py_cache(os.path.join(tmp_path, 'packages'))
makepyo.remove_cache(tmp_path)
shutil.copytree(tmp_path, os.path.join(target_path, 'www'))
utils.remove(tmp_path)
def _remove_py_cache(self, path):
for parent, dir_list, _ in os.walk(path):
for d in dir_list:
d = d.lower()
if d == '__pycache__':
utils.remove(os.path.join(parent, d))
continue
self._remove_py_cache(os.path.join(parent, d))
class BuilderWin(BuilderBase):
def __init__(self):
super().__init__()
self.name = 'teleport-server-windows-{}-{}'.format(ctx.bits_path, VER_TP_SERVER)
self._final_file = os.path.join(env.root_path, 'out', 'installer', '{}.zip'.format(self.name))
self.dist_path = os.path.join(env.root_path, 'dist', 'server')
self.base_path = os.path.join(env.root_path, 'out', 'installer')
self.base_tmp = os.path.join(self.base_path, '_tmp_')
self.path_tmp = os.path.join(self.base_tmp, self.name)
self.path_tmp_data = os.path.join(self.path_tmp, 'data')
def build_installer(self):
cc.n('make teleport installer package...')
if os.path.exists(self.base_tmp):
utils.remove(self.base_tmp)
self._build_web(self.base_path, 'windows', self.path_tmp_data)
utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('web.ini.in', 'web.ini'))
utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('core.ini.in', 'core.ini'))
utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), 'tp_ssh_server.key')
out_path = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path)
bin_path = os.path.join(self.path_tmp_data, 'bin')
utils.copy_ex(out_path, bin_path, 'tp_web.exe')
utils.copy_ex(out_path, bin_path, 'tp_core.exe')
utils.copy_ex(out_path, bin_path, 'tpssh.dll')
utils.copy_ex(out_path, bin_path, 'tptelnet.dll')
if with_rdp:
utils.copy_ex(out_path, bin_path, 'tprdp.dll')
utils.copy_ex(os.path.join(env.root_path, 'out', 'pysrt'), bin_path, (ctx.dist_path, 'pysrt'))
# copy scripts
utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'setup.bat')
utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'script')
if os.path.exists(self._final_file):
utils.remove(self._final_file)
utils.make_zip(self.path_tmp, self._final_file)
# utils.remove(self.base_tmp)
class BuilderLinux(BuilderBase):
def __init__(self):
super().__init__()
self.name = 'teleport-server-linux-{}-{}'.format(ctx.bits_path, VER_TP_SERVER)
self._final_file = os.path.join(env.root_path, 'out', 'installer', '{}.tar.gz'.format(self.name))
self.dist_path = os.path.join(env.root_path, 'dist', 'server')
self.base_path = os.path.join(env.root_path, 'out', 'installer')
self.base_tmp = os.path.join(self.base_path, '_tmp_')
self.path_tmp = os.path.join(self.base_tmp, self.name)
self.path_tmp_data = os.path.join(self.path_tmp, 'data')
def build_installer(self):
cc.n('make teleport installer package...')
if os.path.exists(self.base_tmp):
utils.remove(self.base_tmp)
self._build_web(self.base_path, 'linux', self.path_tmp_data)
utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('web.ini.in', 'web.ini'))
utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('core.ini.in', 'core.ini'))
utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), 'tp_ssh_server.key')
# fix new line flag
utils.fix_new_line_flag(os.path.join(self.path_tmp_data, 'tmp', 'etc', 'web.ini'))
utils.fix_new_line_flag(os.path.join(self.path_tmp_data, 'tmp', 'etc', 'core.ini'))
out_path = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, 'bin')
bin_path = os.path.join(self.path_tmp_data, 'bin')
utils.copy_ex(out_path, bin_path, 'tp_web')
utils.copy_ex(out_path, bin_path, 'tp_core')
utils.copy_ex(out_path, bin_path, 'libtpssh.so')
utils.copy_ex(out_path, bin_path, 'libtptelnet.so')
if with_rdp:
utils.copy_ex(out_path, bin_path, 'libtprdp.so')
utils.copy_ex(os.path.join(env.root_path, 'out', 'pysrt'), bin_path, (ctx.dist_path, 'pysrt'))
# copy scripts
utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'setup.sh')
utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'script')
utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'daemon')
if os.path.exists(self._final_file):
utils.remove(self._final_file)
utils.make_targz(self.base_tmp, self.name, self._final_file)
# utils.remove(self.base_tmp)
def gen_builder(dist):
if dist == 'windows':
builder = BuilderWin()
elif dist == 'linux':
builder = BuilderLinux()
else:
raise RuntimeError('unsupported platform.')
ctx.set_dist(dist)
return builder
def main():
if not env.init():
return
builder = None
argv = sys.argv[1:]
for i in range(len(argv)):
if 'debug' == argv[i]:
ctx.set_target(TARGET_DEBUG)
elif 'x86' == argv[i]:
ctx.set_bits(BITS_32)
elif 'x64' == argv[i]:
ctx.set_bits(BITS_64)
elif argv[i] in ctx.dist_all:
builder = gen_builder(argv[i])
if builder is None:
builder = gen_builder(ctx.host_os)
if 'server-installer' in argv:
builder.build_installer()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
except RuntimeError as e:
cc.e(e.__str__())
except:
cc.f('got exception.')

View File

@ -91,8 +91,17 @@ class BuilderLinux(BuilderBase):
utils.makedirs(out_path)
utils.cmake(os.path.join(env.root_path, 'cmake-build'), ctx.target_path, False)
build_path = os.path.join(env.root_path, 'cmake-build')
if not os.path.exists(build_path):
utils.makedirs(build_path)
old_p = os.getcwd()
os.chdir(build_path)
utils.cmake(build_path, ctx.target_path, False)
os.chdir(build_path)
utils.sys_exec('make')
# utils.strip(out_file)
os.chdir(old_p)
for f in out_files:
if os.path.exists(f):

0
make.sh Normal file → Executable file
View File