2017-01-11 12:04:11 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import getopt
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import sys
|
|
|
|
|
2017-03-08 20:04:01 +00:00
|
|
|
from builder.core.env import env
|
|
|
|
import builder.core.colorconsole as cc
|
|
|
|
import builder.core.utils as utils
|
|
|
|
from builder.core.context import *
|
2017-01-11 12:04:11 +00:00
|
|
|
|
|
|
|
options = list()
|
|
|
|
options_idx = 0
|
2017-03-08 20:04:01 +00:00
|
|
|
ctx = BuildContext()
|
2017-01-11 12:04:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
cc.set_default(sep='', end='\n')
|
|
|
|
|
2017-03-09 09:33:41 +00:00
|
|
|
if not env.init(warn_miss_tool=True):
|
2017-03-08 20:04:01 +00:00
|
|
|
return
|
|
|
|
|
2017-01-11 12:04:11 +00:00
|
|
|
action = None
|
|
|
|
argv = sys.argv[1:]
|
|
|
|
if len(argv) >= 1:
|
|
|
|
for i in range(len(argv)):
|
|
|
|
if 'debug' == argv[i]:
|
|
|
|
ctx.set_target(TARGET_DEBUG)
|
|
|
|
elif 'release' == argv[i]:
|
|
|
|
ctx.set_target(TARGET_RELEASE)
|
|
|
|
elif argv[i] in ctx.dist_all:
|
|
|
|
ctx.set_dist(argv[i])
|
|
|
|
else:
|
|
|
|
action = argv[i]
|
|
|
|
|
|
|
|
make_options()
|
|
|
|
|
|
|
|
if action is not None:
|
2020-12-04 17:33:47 +00:00
|
|
|
if action == '-h' or action == '--help':
|
|
|
|
max_name_len = 0
|
|
|
|
for x in options:
|
|
|
|
if x['id'] != '--SPLIT-LINE--':
|
|
|
|
max_name_len = max(len(x['name']), max_name_len)
|
|
|
|
max_name_len += 4
|
|
|
|
|
|
|
|
for x in options:
|
|
|
|
if x['id'] != '--SPLIT-LINE--':
|
|
|
|
name_pad = max_name_len - len(x['name'])
|
|
|
|
cc.o((cc.CR_INFO, x['name']), (cc.CR_VERBOSE, ' ' * name_pad), (cc.CR_VERBOSE, x['disp']))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
# cc.v(action)
|
2017-01-11 12:04:11 +00:00
|
|
|
opt = select_option_by_name(action)
|
|
|
|
if opt is None:
|
|
|
|
cc.e('unknown config: ', action)
|
|
|
|
return
|
|
|
|
|
|
|
|
do_opt(opt)
|
|
|
|
return
|
|
|
|
|
|
|
|
show_logo()
|
|
|
|
while True:
|
|
|
|
x = show_menu()
|
|
|
|
if x == 'q':
|
|
|
|
break
|
|
|
|
|
|
|
|
try:
|
|
|
|
x = int(x)
|
|
|
|
except:
|
|
|
|
cc.e('invalid input.')
|
|
|
|
continue
|
|
|
|
|
|
|
|
opt = select_option_by_id(int(x))
|
2020-07-12 18:47:40 +00:00
|
|
|
# if 'config' == opt['name']:
|
|
|
|
# if make_config():
|
|
|
|
# make_options()
|
|
|
|
# continue
|
2017-01-11 12:04:11 +00:00
|
|
|
|
|
|
|
if opt is None:
|
|
|
|
cc.e('unknown selection: ', x)
|
|
|
|
continue
|
|
|
|
|
|
|
|
do_opt(opt)
|
|
|
|
|
|
|
|
cc.w('\ntask finished, press Enter to continue or Q to quit...', end='')
|
|
|
|
try:
|
2020-12-04 17:33:47 +00:00
|
|
|
x = input()
|
2017-01-11 12:04:11 +00:00
|
|
|
except EOFError:
|
|
|
|
x = 'q'
|
|
|
|
if x == 'q':
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
def clean_all():
|
2017-04-17 09:40:17 +00:00
|
|
|
# cc.e('sorry, clean not implemented yet.')
|
|
|
|
utils.remove(os.path.join(env.root_path, 'out'))
|
|
|
|
|
|
|
|
|
|
|
|
def clean_everything():
|
|
|
|
utils.remove(os.path.join(env.root_path, 'out'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'jsoncpp'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'libuv'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'mbedtls'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'mongoose'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'openssl'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'python'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'libssh-win-static', 'lib'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'libssh-win-static', 'src'))
|
2017-04-17 10:21:47 +00:00
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'tmp'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libmbedcrypto.a'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libmbedtls.a'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libmbedx509.a'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libsqlite3.a'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libssh.a'))
|
2017-12-13 15:22:42 +00:00
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libssh_threads.a'))
|
2017-04-17 10:21:47 +00:00
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libuv.a'))
|
2017-01-11 12:04:11 +00:00
|
|
|
|
|
|
|
|
2019-11-19 12:09:08 +00:00
|
|
|
def clean_external():
|
2020-12-04 17:33:47 +00:00
|
|
|
# utils.remove(os.path.join(env.root_path, 'out'))
|
2019-11-19 12:09:08 +00:00
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'jsoncpp'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'libuv'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'mbedtls'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'mongoose'))
|
2020-12-04 17:33:47 +00:00
|
|
|
# utils.remove(os.path.join(env.root_path, 'external', 'openssl'))
|
|
|
|
# utils.remove(os.path.join(env.root_path, 'external', 'python'))
|
|
|
|
# utils.remove(os.path.join(env.root_path, 'external', 'libssh-win-static', 'lib'))
|
|
|
|
# utils.remove(os.path.join(env.root_path, 'external', 'libssh-win-static', 'src'))
|
|
|
|
# utils.remove(os.path.join(env.root_path, 'external', 'linux', 'tmp'))
|
2019-11-19 12:09:08 +00:00
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libmbedcrypto.a'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libmbedtls.a'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libmbedx509.a'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libsqlite3.a'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libssh.a'))
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libssh_threads.a'))
|
|
|
|
|
|
|
|
utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libuv.a'))
|
|
|
|
|
|
|
|
|
2017-01-11 12:04:11 +00:00
|
|
|
def do_opt(opt):
|
|
|
|
arg = ''
|
|
|
|
|
|
|
|
if 'ver' == opt['name']:
|
|
|
|
script = 'build-version.py'
|
|
|
|
|
|
|
|
elif 'pysrt' == opt['name']:
|
|
|
|
script = 'build-pysrt.py'
|
|
|
|
|
2020-07-12 18:47:40 +00:00
|
|
|
elif opt['name'] in ['ext-client', 'ext-server', 'clear-ext-client', 'clear-ext-server']:
|
2017-01-11 12:04:11 +00:00
|
|
|
script = 'build-external.py'
|
2020-07-12 18:47:40 +00:00
|
|
|
arg = '%s %s %s' % (opt['name'], ctx.target_path, opt['bits'])
|
2017-01-11 12:04:11 +00:00
|
|
|
|
|
|
|
elif 'server' == opt['name']:
|
|
|
|
script = 'build-server.py'
|
|
|
|
arg = '%s %s server' % (ctx.target_path, opt['bits'])
|
|
|
|
|
2020-07-14 21:03:04 +00:00
|
|
|
elif 'server-installer' == opt['name']:
|
2017-01-11 12:04:11 +00:00
|
|
|
script = 'build-installer.py'
|
2020-07-14 21:03:04 +00:00
|
|
|
arg = '%s %s server-installer' % (ctx.dist, opt['bits'])
|
2017-01-11 12:04:11 +00:00
|
|
|
|
2020-07-12 18:47:40 +00:00
|
|
|
elif 'client' == opt['name']:
|
2017-01-11 12:04:11 +00:00
|
|
|
script = 'build-assist.py'
|
|
|
|
arg = '%s %s exe' % (ctx.target_path, opt['bits'])
|
2020-12-04 17:33:47 +00:00
|
|
|
|
2020-07-12 18:47:40 +00:00
|
|
|
elif 'client-installer' == opt['name']:
|
2017-01-11 12:04:11 +00:00
|
|
|
script = 'build-assist.py'
|
|
|
|
arg = '%s %s installer' % (ctx.dist, opt['bits'])
|
|
|
|
|
|
|
|
else:
|
|
|
|
cc.e('unknown option: ', opt['name'])
|
|
|
|
return
|
|
|
|
|
2017-03-16 10:45:31 +00:00
|
|
|
cmd = '%s -B %s %s' % (env.py_exec, os.path.join(env.builder_path, script), arg)
|
2017-01-11 12:04:11 +00:00
|
|
|
os.system(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
def select_option_by_name(name):
|
2020-12-04 17:33:47 +00:00
|
|
|
for x in options:
|
|
|
|
if x['id'] != '--SPLIT-LINE--':
|
|
|
|
if name == x['name']:
|
|
|
|
return x
|
2017-01-11 12:04:11 +00:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2017-01-16 13:28:13 +00:00
|
|
|
def select_option_by_id(_id):
|
2020-12-04 17:33:47 +00:00
|
|
|
for x in options:
|
|
|
|
if x['id'] == _id:
|
|
|
|
return x
|
2017-01-11 12:04:11 +00:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def add_option(bits, name, disp):
|
|
|
|
global options, options_idx
|
|
|
|
options_idx += 1
|
|
|
|
options.append({'id': options_idx, 'name': name, 'disp': disp, 'bits': bits})
|
|
|
|
|
|
|
|
|
2020-07-12 18:47:40 +00:00
|
|
|
def add_split(title=None):
|
2017-01-11 12:04:11 +00:00
|
|
|
global options
|
2020-07-12 18:47:40 +00:00
|
|
|
options.append({'id': '--SPLIT-LINE--', 'title': title})
|
2017-01-11 12:04:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def make_options():
|
2020-06-06 13:36:00 +00:00
|
|
|
if ctx.host_os in ['windows']:
|
2020-08-12 15:48:12 +00:00
|
|
|
add_split('prepare external [build once]')
|
2020-07-12 18:47:40 +00:00
|
|
|
# add_option('x86', 'external', '[OBSOLETE] Build external dependency')
|
2020-08-12 15:48:12 +00:00
|
|
|
add_option('x86', 'ext-client', '[client] Build external libraries for client')
|
|
|
|
# add_split('prepare for server [build once]')
|
|
|
|
add_option('x86', 'pysrt', '[server] Make Python-Runtime for python%s-x86' % env.py_ver_str)
|
|
|
|
add_option('x86', 'ext-server', '[server] Build external libraries for server')
|
2020-07-14 21:03:04 +00:00
|
|
|
add_split('version [build every release]')
|
|
|
|
add_option('x86', 'ver', 'Update version setting')
|
|
|
|
add_split('client side')
|
2020-07-12 18:47:40 +00:00
|
|
|
# add_option('x86', 'assist-exe', '[OBSOLETE] Assist Execute [%s]' % ctx.target_path)
|
|
|
|
add_option('x86', 'client', 'Build client applications [%s]' % ctx.target_path)
|
2017-01-11 12:04:11 +00:00
|
|
|
# add_option('x86', 'assist-rdp', 'Teleport RDP [%s]' % ctx.target_path)
|
2020-07-12 18:47:40 +00:00
|
|
|
# add_option('x86', 'assist-installer', '[OBSOLETE] Assist Installer')
|
|
|
|
add_option('x86', 'client-installer', 'Make client installer')
|
|
|
|
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')
|
2020-07-14 21:03:04 +00:00
|
|
|
# add_option('x86', 'server', 'Teleport Server [%s]' % ctx.target_path)
|
2020-07-12 18:47:40 +00:00
|
|
|
add_option('x86', 'server-installer', 'Teleport Installer for %s' % ctx.host_os)
|
2020-07-14 21:03:04 +00:00
|
|
|
# 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')
|
2020-07-12 18:47:40 +00:00
|
|
|
add_option('x86', 'clear-ext-server', 'Clear external libraries for server')
|
2020-06-06 13:36:00 +00:00
|
|
|
elif ctx.host_os == 'macos':
|
2020-07-14 21:03:04 +00:00
|
|
|
add_split('client side')
|
2020-08-12 15:48:12 +00:00
|
|
|
add_option('x64', 'ext-client', 'build external libraries for client')
|
|
|
|
add_option('x64', 'client', 'build client applications [%s]' % ctx.target_path)
|
|
|
|
add_option('x64', 'client-installer', 'make client installer')
|
|
|
|
add_split('server side')
|
2020-12-04 17:33:47 +00:00
|
|
|
add_option('x64', 'ext-server', '(DEV-ONLY) build external libraries for server')
|
|
|
|
add_option('x64', 'server', '(DEV-ONLY) build server applications for MacOS [%s]' % ctx.target_path)
|
2020-07-14 21:03:04 +00:00
|
|
|
add_split('clear')
|
2020-08-12 15:48:12 +00:00
|
|
|
add_option('x64', 'clear-ext-client', 'clear external libraries for client')
|
|
|
|
add_option('x64', 'clear-ext-server', 'clear external libraries for server')
|
|
|
|
add_split('misc')
|
|
|
|
add_option('x64', 'ver', 'update version setting')
|
2017-01-11 12:04:11 +00:00
|
|
|
else:
|
2020-07-14 21:03:04 +00:00
|
|
|
add_split('prepare for server [build once]')
|
2020-07-12 18:47:40 +00:00
|
|
|
add_option('x64', 'pysrt', 'Make Python-Runtime for python%s-x64' % env.py_ver_str)
|
2020-07-14 21:03:04 +00:00
|
|
|
add_split('server side')
|
2020-08-12 15:48:12 +00:00
|
|
|
add_option('x64', 'ext-server', 'build external libraries for server')
|
|
|
|
add_option('x64', 'server', 'build server applications [%s]' % ctx.target_path)
|
|
|
|
add_option('x64', 'server-installer', 'make server installer for %s' % ctx.host_os)
|
2020-07-14 21:03:04 +00:00
|
|
|
add_split('clear')
|
|
|
|
# add_option('x64', 'clear-ext-client', 'Clear external libraries for client')
|
2020-08-12 15:48:12 +00:00
|
|
|
add_option('x64', 'clear-ext-server', 'clear external libraries for server')
|
|
|
|
add_split('misc')
|
|
|
|
add_option('x64', 'ver', 'update version setting')
|
2017-01-11 12:04:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_input(msg, log_func=cc.w):
|
|
|
|
log_func(msg, end=' ')
|
|
|
|
try:
|
2020-12-04 17:33:47 +00:00
|
|
|
return input()
|
2017-01-11 12:04:11 +00:00
|
|
|
except EOFError:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
|
|
|
|
def show_logo():
|
2020-07-12 18:47:40 +00:00
|
|
|
cc.v('[]==========================================================[]')
|
2020-12-04 17:33:47 +00:00
|
|
|
cc.v(' | Teleport Projects Builder v2.0 |')
|
2020-07-12 18:47:40 +00:00
|
|
|
cc.v(' | auth: apex.liu@qq.com |')
|
|
|
|
cc.v('[]==========================================================[]')
|
2017-01-11 12:04:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def show_menu():
|
2020-07-12 18:47:40 +00:00
|
|
|
cc.v('\n=====================[ MENU ]===============================')
|
2020-12-04 17:33:47 +00:00
|
|
|
for o in options:
|
|
|
|
if o['id'] == '--SPLIT-LINE--':
|
|
|
|
if o['title'] is not None:
|
|
|
|
cc.w('\n {}:'.format(o['title']))
|
2020-07-12 18:47:40 +00:00
|
|
|
else:
|
|
|
|
cc.v('\n ----------------------------------------------------------')
|
2017-01-11 12:04:11 +00:00
|
|
|
continue
|
2020-07-12 18:47:40 +00:00
|
|
|
|
2020-12-04 17:33:47 +00:00
|
|
|
cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, '%2d' % o['id']), (cc.CR_NORMAL, '] ', o['disp']))
|
2017-01-11 12:04:11 +00:00
|
|
|
|
2020-07-12 18:47:40 +00:00
|
|
|
cc.v('\n ----------------------------------------------------------')
|
2017-01-11 12:04:11 +00:00
|
|
|
cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, ' Q'), (cc.CR_NORMAL, '] exit'))
|
|
|
|
|
|
|
|
cc.w('\nselect action: ', end='')
|
|
|
|
try:
|
2020-12-04 17:33:47 +00:00
|
|
|
x = input()
|
2017-01-11 12:04:11 +00:00
|
|
|
except EOFError:
|
|
|
|
x = 'q'
|
|
|
|
|
|
|
|
cc.n('')
|
|
|
|
return x.lower()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
try:
|
|
|
|
main()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
except RuntimeError as e:
|
|
|
|
cc.e(e.__str__())
|
|
|
|
except:
|
2020-12-04 17:33:47 +00:00
|
|
|
cc.f('got an exception.')
|