teleport/build/builder/build-server.py

138 lines
4.1 KiB
Python
Raw Normal View History

2017-01-11 12:04:11 +00:00
# -*- coding: utf-8 -*-
# import codecs
# import shutil
# import time
2017-01-11 12:04:11 +00:00
from core import colorconsole as cc
from core import utils
from core.context import *
2017-03-15 17:59:41 +00:00
from core.env import env
2017-01-11 12:04:11 +00:00
ctx = BuildContext()
class BuilderBase:
def __init__(self):
self.out_dir = ''
def build_server(self):
pass
class BuilderWin(BuilderBase):
def __init__(self):
super().__init__()
def build_server(self):
2017-01-16 13:28:13 +00:00
cc.n('build web server ...')
sln_file = os.path.join(env.root_path, 'server', 'tp_web', 'src', 'tp_web.vs2015.sln')
out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tp_web.exe')
2017-01-11 12:04:11 +00:00
if os.path.exists(out_file):
utils.remove(out_file)
2017-01-16 13:28:13 +00:00
utils.msvc_build(sln_file, 'tp_web', ctx.target_path, ctx.bits_path, False)
2017-01-11 12:04:11 +00:00
utils.ensure_file_exists(out_file)
2017-01-16 13:28:13 +00:00
cc.n('build core server ...')
sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'core', 'tp_core.vs2015.sln')
out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tp_core.exe')
2017-01-16 13:28:13 +00:00
if os.path.exists(out_file):
utils.remove(out_file)
utils.msvc_build(sln_file, 'tp_core', ctx.target_path, ctx.bits_path, False)
utils.ensure_file_exists(out_file)
cc.n('build SSH protocol ...')
sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'ssh', 'tpssh.vs2015.sln')
out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tpssh.dll')
2017-01-16 13:28:13 +00:00
if os.path.exists(out_file):
utils.remove(out_file)
utils.msvc_build(sln_file, 'tpssh', ctx.target_path, ctx.bits_path, False)
utils.ensure_file_exists(out_file)
2017-01-11 12:04:11 +00:00
#
# s = os.path.join(env.root_path, 'out', 'console', ctx.bits_path, ctx.target_path, 'console.exe')
# t = os.path.join(env.root_path, 'out', 'eom_agent', ctx.target_path, ctx.dist_path, 'eom_agent.com')
2017-01-11 12:04:11 +00:00
# shutil.copy(s, t)
# utils.ensure_file_exists(t)
class BuilderLinux(BuilderBase):
def __init__(self):
super().__init__()
def build_server(self):
2017-03-15 17:59:41 +00:00
cc.n('build server app (tp_core/libtpssh/tp_web)...')
2017-01-11 12:04:11 +00:00
out_path = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, 'bin')
2017-03-15 17:59:41 +00:00
out_files = [os.path.join(out_path, 'tp_core'), os.path.join(out_path, 'libtpssh.so'),
os.path.join(out_path, 'tp_web')]
2017-01-11 12:04:11 +00:00
2017-03-15 17:59:41 +00:00
for f in out_files:
if os.path.exists(f):
utils.remove(f)
2017-01-11 12:04:11 +00:00
utils.makedirs(out_path)
utils.cmake(os.path.join(env.root_path, 'server', 'cmake-build'), ctx.target_path, False)
2017-03-15 17:59:41 +00:00
# utils.strip(out_file)
2017-01-11 12:04:11 +00:00
2017-03-15 17:59:41 +00:00
for f in out_files:
if os.path.exists(f):
utils.ensure_file_exists(f)
2017-01-11 12:04:11 +00:00
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
2017-01-11 12:04:11 +00:00
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' in argv:
builder.build_server()
2017-03-15 17:59:41 +00:00
# if 'app' in argv:
# builder.build_app()
2017-01-11 12:04:11 +00:00
2017-03-15 17:59:41 +00:00
# if 'installer' in argv:
# builder.build_installer()
2017-01-11 12:04:11 +00:00
2017-03-15 17:59:41 +00:00
# if 'runtime' in argv:
# builder.build_runtime()
2017-01-11 12:04:11 +00:00
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
except RuntimeError as e:
cc.e(e.__str__())
except:
cc.f('got exception.')