mirror of https://github.com/tp4a/teleport
temp.
parent
83e9b9439e
commit
35569651a3
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import getopt
|
||||
|
@ -7,47 +6,27 @@ import os
|
|||
import platform
|
||||
import sys
|
||||
|
||||
THIS_PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
ROOT_PATH = os.path.abspath(os.path.join(THIS_PATH, '..'))
|
||||
BUILDER_PATH = os.path.join(THIS_PATH, 'builder')
|
||||
from builder.core.env import env
|
||||
import builder.core.colorconsole as cc
|
||||
import builder.core.utils as utils
|
||||
from builder.core.context import *
|
||||
|
||||
sys.path.append(os.path.join(BUILDER_PATH))
|
||||
|
||||
try:
|
||||
import core.colorconsole as cc
|
||||
except ImportError:
|
||||
print('can not import color console module.')
|
||||
sys.exit(1)
|
||||
|
||||
import core.utils as utils
|
||||
|
||||
try:
|
||||
from core.context import *
|
||||
except ImportError:
|
||||
cc.e('can not import core context module.')
|
||||
sys.exit(1)
|
||||
|
||||
ctx = BuildContext()
|
||||
|
||||
if ctx.is_py2:
|
||||
if env.is_py2:
|
||||
_input = raw_input
|
||||
else:
|
||||
_input = input
|
||||
|
||||
if ctx.host_os == 'windows':
|
||||
try:
|
||||
import win32api, win32con
|
||||
except:
|
||||
cc.e('can not import module `win32api`.')
|
||||
sys.exit(1)
|
||||
|
||||
options = list()
|
||||
options_idx = 0
|
||||
ctx = BuildContext()
|
||||
|
||||
|
||||
def main():
|
||||
cc.set_default(sep='', end='\n')
|
||||
|
||||
if not env.init():
|
||||
return
|
||||
|
||||
action = None
|
||||
argv = sys.argv[1:]
|
||||
if len(argv) >= 1:
|
||||
|
@ -151,7 +130,7 @@ def do_opt(opt):
|
|||
return
|
||||
|
||||
# cmd = '"%s" -B "%s" %s' % (utils.cfg.py_exec, os.path.join(BUILDER_PATH, script), arg)
|
||||
cmd = '%s -B %s %s' % (utils.cfg.py_exec, os.path.join(BUILDER_PATH, script), arg)
|
||||
cmd = '%s -B %s %s' % (utils.cfg.py_exec, os.path.join(env.builder_path, script), arg)
|
||||
os.system(cmd)
|
||||
|
||||
|
||||
|
@ -193,14 +172,15 @@ def add_split():
|
|||
|
||||
|
||||
def make_options():
|
||||
global options, options_idx, cfg
|
||||
|
||||
options = list()
|
||||
options_idx = 0
|
||||
# global options, options_idx
|
||||
#
|
||||
# options = list()
|
||||
# options_idx = 0
|
||||
|
||||
if ctx.host_os == 'windows':
|
||||
add_option('x86', 'ver', 'Update version setting')
|
||||
add_option('x86', 'pysrt', 'Make Python-Runtime for python%s-x86' % (utils.cfg.py_ver_str))
|
||||
add_option('x86', 'pysrt', 'Make Python-Runtime for python%s-x86' % env.py_ver_str)
|
||||
add_option('x64', 'external', 'Build external dependency')
|
||||
add_split()
|
||||
add_option('x86', 'assist-exe', 'Assist Execute [%s]' % ctx.target_path)
|
||||
# add_option('x86', 'assist-rdp', 'Teleport RDP [%s]' % ctx.target_path)
|
||||
|
@ -211,8 +191,8 @@ def make_options():
|
|||
add_option('x86', 'installer', 'Teleport Installer for %s' % ctx.host_os)
|
||||
else:
|
||||
add_option('x64', 'ver', 'Update version setting')
|
||||
add_option('x64', 'pysrt', 'Make Python-Runtime for python%s-x64' % (utils.cfg.py_ver_str))
|
||||
add_option('x64', 'external', 'Build external for Teleport-Server')
|
||||
add_option('x64', 'pysrt', 'Make Python-Runtime for python%s-x64' % env.py_ver_str)
|
||||
add_option('x64', 'external', 'Build external dependency')
|
||||
add_split()
|
||||
add_option('x64', 'server', 'Build server app [%s]' % ctx.target_path)
|
||||
add_split()
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
#!/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import codecs
|
||||
|
@ -8,6 +7,8 @@ from core import colorconsole as cc
|
|||
from core import utils
|
||||
from core.context import *
|
||||
|
||||
from core.env import env
|
||||
|
||||
ctx = BuildContext()
|
||||
|
||||
ROOT_PATH = utils.cfg.ROOT_PATH
|
||||
|
@ -23,7 +24,6 @@ JSONCPP_VER = utils.cfg.ver.jsoncpp
|
|||
MONGOOSE_VER = utils.cfg.ver.mongoose
|
||||
|
||||
|
||||
|
||||
class BuilderBase:
|
||||
def __init__(self):
|
||||
self.out_dir = ''
|
||||
|
@ -37,7 +37,7 @@ class BuilderBase:
|
|||
|
||||
def build_jsoncpp(self):
|
||||
file_name = 'jsoncpp-{}.zip'.format(JSONCPP_VER)
|
||||
if not self._download_file('jsoncpp source tarball', 'https://github.com/open-source-parsers/jsoncpp/archive/{}.zip'.format(JSONCPP_VER), file_name):
|
||||
if not utils.download_file('jsoncpp source tarball', 'https://github.com/open-source-parsers/jsoncpp/archive/{}.zip'.format(JSONCPP_VER), PATH_DOWNLOAD, file_name):
|
||||
return
|
||||
self._build_jsoncpp(file_name)
|
||||
|
||||
|
@ -46,7 +46,7 @@ class BuilderBase:
|
|||
|
||||
def build_mongoose(self):
|
||||
file_name = 'mongoose-{}.zip'.format(MONGOOSE_VER)
|
||||
if not self._download_file('mongoose source tarball', 'https://github.com/cesanta/mongoose/archive/{}.zip'.format(MONGOOSE_VER), file_name):
|
||||
if not utils.download_file('mongoose source tarball', 'https://github.com/cesanta/mongoose/archive/{}.zip'.format(MONGOOSE_VER), PATH_DOWNLOAD, file_name):
|
||||
return
|
||||
self._build_mongoose(file_name)
|
||||
|
||||
|
@ -54,8 +54,11 @@ class BuilderBase:
|
|||
cc.e("this is a pure-virtual function.")
|
||||
|
||||
def build_openssl(self):
|
||||
file_name = 'openssl-{}.tar.gz'.format(OPENSSL_VER)
|
||||
if not self._download_file('openssl source tarball', 'https://www.openssl.org/source/{}'.format(file_name), file_name):
|
||||
file_name = 'openssl-{}.zip'.format(OPENSSL_VER)
|
||||
_alt_ver = '_'.join(OPENSSL_VER.split('.'))
|
||||
#https://github.com/openssl/openssl/archive/OpenSSL_1_1_0e.zip
|
||||
# if not utils.download_file('openssl source tarball', 'https://www.openssl.org/source/{}'.format(file_name), PATH_DOWNLOAD, file_name):
|
||||
if not utils.download_file('openssl source tarball', 'https://github.com/openssl/openssl/archive/OpenSSL_{}.zip'.format(_alt_ver), PATH_DOWNLOAD, file_name):
|
||||
return
|
||||
self._build_openssl(file_name)
|
||||
|
||||
|
@ -64,7 +67,7 @@ class BuilderBase:
|
|||
|
||||
def build_libuv(self):
|
||||
file_name = 'libuv-{}.zip'.format(LIBUV_VER)
|
||||
if not self._download_file('libuv source tarball', 'https://github.com/libuv/libuv/archive/v{}.zip'.format(LIBUV_VER), file_name):
|
||||
if not utils.download_file('libuv source tarball', 'https://github.com/libuv/libuv/archive/v{}.zip'.format(LIBUV_VER), PATH_DOWNLOAD, file_name):
|
||||
return
|
||||
self._build_libuv(file_name)
|
||||
|
||||
|
@ -73,7 +76,7 @@ class BuilderBase:
|
|||
|
||||
def build_mbedtls(self):
|
||||
file_name = 'mbedtls-mbedtls-{}.zip'.format(MBEDTLS_VER)
|
||||
if not self._download_file('mbedtls source tarball', 'https://github.com/ARMmbed/mbedtls/archive/mbedtls-{}.zip'.format(MBEDTLS_VER), file_name):
|
||||
if not utils.download_file('mbedtls source tarball', 'https://github.com/ARMmbed/mbedtls/archive/mbedtls-{}.zip'.format(MBEDTLS_VER), PATH_DOWNLOAD, file_name):
|
||||
return
|
||||
self._build_mbedtls(file_name)
|
||||
|
||||
|
@ -82,7 +85,7 @@ class BuilderBase:
|
|||
|
||||
def build_libssh(self):
|
||||
file_name = 'libssh-{}.zip'.format(LIBSSH_VER)
|
||||
if not self._download_file('libssh source tarball', 'https://git.libssh.org/projects/libssh.git/snapshot/libssh-{}.zip'.format(LIBSSH_VER), file_name):
|
||||
if not utils.download_file('libssh source tarball', 'https://git.libssh.org/projects/libssh.git/snapshot/libssh-{}.zip'.format(LIBSSH_VER), PATH_DOWNLOAD, file_name):
|
||||
return
|
||||
self._build_libssh(file_name)
|
||||
|
||||
|
@ -91,26 +94,26 @@ class BuilderBase:
|
|||
|
||||
def build_sqlite(self):
|
||||
file_name = 'sqlite-autoconf-{}.tar.gz'.format(SQLITE_VER)
|
||||
if not self._download_file('sqlite source tarball', 'http://sqlite.org/2016/{}'.format(file_name), file_name):
|
||||
if not utils.download_file('sqlite source tarball', 'http://sqlite.org/2016/{}'.format(file_name), PATH_DOWNLOAD, file_name):
|
||||
return
|
||||
self._build_sqlite(file_name)
|
||||
|
||||
def _build_sqlite(self, file_name):
|
||||
cc.e("this is a pure-virtual function.")
|
||||
|
||||
def _download_file(self, desc, url, file_name):
|
||||
cc.n('downloading {} ...'.format(desc))
|
||||
if os.path.exists(os.path.join(PATH_DOWNLOAD, file_name)):
|
||||
cc.w('already exists, skip.')
|
||||
return True
|
||||
|
||||
os.system('wget --no-check-certificate {} -O "{}/{}"'.format(url, PATH_DOWNLOAD, file_name))
|
||||
|
||||
if not os.path.exists(os.path.join(PATH_DOWNLOAD, file_name)):
|
||||
cc.e('downloading {} from {} failed.'.format(desc, url))
|
||||
return True
|
||||
|
||||
return True
|
||||
# def _download_file(self, desc, url, file_name):
|
||||
# cc.n('downloading {} ...'.format(desc))
|
||||
# if os.path.exists(os.path.join(PATH_DOWNLOAD, file_name)):
|
||||
# cc.w('already exists, skip.')
|
||||
# return True
|
||||
#
|
||||
# os.system('wget --no-check-certificate {} -O "{}/{}"'.format(url, PATH_DOWNLOAD, file_name))
|
||||
#
|
||||
# if not os.path.exists(os.path.join(PATH_DOWNLOAD, file_name)):
|
||||
# cc.e('downloading {} from {} failed.'.format(desc, url))
|
||||
# return True
|
||||
#
|
||||
# return True
|
||||
|
||||
def fix_output(self):
|
||||
pass
|
||||
|
@ -126,6 +129,10 @@ class BuilderWin(BuilderBase):
|
|||
def _build_openssl(self, file_name):
|
||||
cc.e('build openssl-static for Windows...not supported yet.')
|
||||
|
||||
def build_sqlite(self):
|
||||
cc.w('sqlite not need for Windows, skip.')
|
||||
pass
|
||||
|
||||
def fix_output(self):
|
||||
pass
|
||||
|
||||
|
@ -166,21 +173,23 @@ class BuilderLinux(BuilderBase):
|
|||
cc.w('already exists, skip.')
|
||||
|
||||
def _build_openssl(self, file_name):
|
||||
if not os.path.exists(self.OPENSSL_PATH_SRC):
|
||||
os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP))
|
||||
pass # we do not need build openssl anymore, because first time run build.sh we built Python, it include openssl.
|
||||
|
||||
cc.n('build openssl static...')
|
||||
if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssl.a')):
|
||||
cc.w('already exists, skip.')
|
||||
return
|
||||
|
||||
old_p = os.getcwd()
|
||||
os.chdir(self.OPENSSL_PATH_SRC)
|
||||
#os.system('./config --prefix={} --openssldir={}/openssl no-zlib no-shared'.format(self.PATH_RELEASE, self.PATH_RELEASE))
|
||||
os.system('./config --prefix={} --openssldir={}/openssl -fPIC no-zlib no-shared'.format(self.PATH_RELEASE, self.PATH_RELEASE))
|
||||
os.system('make')
|
||||
os.system('make install')
|
||||
os.chdir(old_p)
|
||||
# if not os.path.exists(self.OPENSSL_PATH_SRC):
|
||||
# os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP))
|
||||
#
|
||||
# cc.n('build openssl static...')
|
||||
# if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssl.a')):
|
||||
# cc.w('already exists, skip.')
|
||||
# return
|
||||
#
|
||||
# old_p = os.getcwd()
|
||||
# os.chdir(self.OPENSSL_PATH_SRC)
|
||||
# #os.system('./config --prefix={} --openssldir={}/openssl no-zlib no-shared'.format(self.PATH_RELEASE, self.PATH_RELEASE))
|
||||
# os.system('./config --prefix={} --openssldir={}/openssl -fPIC no-zlib no-shared'.format(self.PATH_RELEASE, self.PATH_RELEASE))
|
||||
# os.system('make')
|
||||
# os.system('make install')
|
||||
# os.chdir(old_p)
|
||||
|
||||
def _build_libuv(self, file_name):
|
||||
if not os.path.exists(self.LIBUV_PATH_SRC):
|
||||
|
@ -328,26 +337,21 @@ class BuilderLinux(BuilderBase):
|
|||
# os.chdir(old_p)
|
||||
|
||||
cmake_define = ' -DCMAKE_INSTALL_PREFIX={}' \
|
||||
' -D_OPENSSL_VERSION={}' \
|
||||
' -DOPENSSL_INCLUDE_DIR={}/include' \
|
||||
' -DOPENSSL_LIBRARIES={}/lib' \
|
||||
' -DWITH_GSSAPI=OFF' \
|
||||
' -DWITH_ZLIB=OFF' \
|
||||
' -DWITH_STATIC_LIB=ON' \
|
||||
' -DWITH_PCAP=OFF' \
|
||||
' -DWITH_TESTING=OFF' \
|
||||
' -DWITH_CLIENT_TESTING=OFF' \
|
||||
' -DWITH_EXAMPLES=OFF' \
|
||||
' -DWITH_BENCHMARKS=OFF' \
|
||||
' -DWITH_NACL=OFF' \
|
||||
' ..'.format(self.PATH_RELEASE, OPENSSL_VER, self.PATH_RELEASE, self.PATH_RELEASE)
|
||||
' -D_OPENSSL_VERSION={}' \
|
||||
' -DOPENSSL_INCLUDE_DIR={}/include' \
|
||||
' -DOPENSSL_LIBRARIES={}/lib' \
|
||||
' -DWITH_GSSAPI=OFF' \
|
||||
' -DWITH_ZLIB=OFF' \
|
||||
' -DWITH_STATIC_LIB=ON' \
|
||||
' -DWITH_PCAP=OFF' \
|
||||
' -DWITH_TESTING=OFF' \
|
||||
' -DWITH_CLIENT_TESTING=OFF' \
|
||||
' -DWITH_EXAMPLES=OFF' \
|
||||
' -DWITH_BENCHMARKS=OFF' \
|
||||
' -DWITH_NACL=OFF' \
|
||||
' ..'.format(self.PATH_RELEASE, OPENSSL_VER, self.PATH_RELEASE, self.PATH_RELEASE)
|
||||
|
||||
# libssh always try to build shared library we do not care, but it may fail.
|
||||
# so catch the except, we will check the final output file `libssh.a` ourselves.
|
||||
try:
|
||||
utils.cmake(build_path, 'Release', False, cmake_define)
|
||||
except:
|
||||
pass
|
||||
utils.cmake(build_path, 'Release', False, cmake_define)
|
||||
|
||||
# because make install will fail because we can not disable ssh_shared target,
|
||||
# so we copy necessary files ourselves.
|
||||
|
@ -393,6 +397,9 @@ def gen_builder(dist):
|
|||
|
||||
|
||||
def main():
|
||||
if not env.init():
|
||||
return
|
||||
|
||||
builder = None
|
||||
|
||||
argv = sys.argv[1:]
|
||||
|
@ -413,7 +420,7 @@ def main():
|
|||
builder.build_jsoncpp()
|
||||
builder.build_mongoose()
|
||||
|
||||
# builder.build_openssl()
|
||||
builder.build_openssl()
|
||||
####builder.build_libuv()
|
||||
builder.build_mbedtls()
|
||||
builder.build_libssh()
|
||||
|
|
|
@ -59,9 +59,6 @@ COLORS = {
|
|||
}
|
||||
|
||||
|
||||
# env = eomcore.env.get_env()
|
||||
|
||||
|
||||
class ColorConsole:
|
||||
"""
|
||||
:type _win_color : Win32ColorConsole
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf8 -*-
|
||||
|
||||
import os
|
||||
|
|
|
@ -0,0 +1,178 @@
|
|||
# -*- coding: utf8 -*-
|
||||
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
import configparser
|
||||
|
||||
from . import colorconsole as cc
|
||||
|
||||
|
||||
class Env(object):
|
||||
BITS_32 = 32
|
||||
BITS_64 = 64
|
||||
|
||||
def __init__(self):
|
||||
_this_path = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
self.root_path = os.path.abspath(os.path.join(_this_path, '..', '..', '..'))
|
||||
self.build_path = os.path.abspath(os.path.join(_this_path, '..', '..'))
|
||||
self.builder_path = os.path.join(self.build_path, 'builder')
|
||||
self.win32_tools_path = os.path.join(self.build_path, 'tools', 'win32')
|
||||
|
||||
self.is_py2 = sys.version_info[0] == 2
|
||||
self.is_py3 = sys.version_info[0] == 3
|
||||
|
||||
self.py_ver = platform.python_version_tuple()
|
||||
self.py_ver_str = '%s%s' % (self.py_ver[0], self.py_ver[1])
|
||||
self.py_exec = sys.executable
|
||||
|
||||
self.bits = self.BITS_32
|
||||
self.bits_str = 'x86'
|
||||
|
||||
_bits = platform.architecture()[0]
|
||||
if _bits == '64bit':
|
||||
self.bits = self.BITS_64
|
||||
self.bits_str = 'x64'
|
||||
|
||||
self.is_win = False
|
||||
self.is_win_x64 = False
|
||||
self.is_linux = False
|
||||
self.is_macos = False
|
||||
|
||||
_os = platform.system().lower()
|
||||
self.plat = ''
|
||||
if _os == 'windows':
|
||||
self.is_win = True
|
||||
self.plat = 'windows'
|
||||
self.is_win_x64 = 'PROGRAMFILES(X86)' in os.environ
|
||||
elif _os == 'linux':
|
||||
self.is_linux = True
|
||||
self.plat = 'linux'
|
||||
elif _os == 'darwin':
|
||||
self.is_macos = True
|
||||
self.plat = 'macos'
|
||||
|
||||
def init(self):
|
||||
if not self._load_config():
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def _load_config(self):
|
||||
_cfg_file = os.path.join(self.root_path, 'config.ini')
|
||||
if not os.path.exists(_cfg_file):
|
||||
cc.e('can not load configuration.\n\nplease copy `config.ini.in` into `config.ini` and modify it to fit your condition and try again.')
|
||||
return False
|
||||
|
||||
_cfg = configparser.ConfigParser()
|
||||
_cfg.read(_cfg_file)
|
||||
if 'external_ver' not in _cfg.sections() or 'toolchain' not in _cfg.sections():
|
||||
cc.e('invalid configuration file: need `external_ver` and `toolchain` section.')
|
||||
return False
|
||||
|
||||
_tmp = _cfg['external_ver']
|
||||
try:
|
||||
self.ver_openssl = _tmp['openssl']
|
||||
self.ver_libuv = _tmp['libuv']
|
||||
self.ver_mbedtls = _tmp['mbedtls']
|
||||
self.ver_sqlite = _tmp['sqlite']
|
||||
self.ver_libssh = _tmp['libssh']
|
||||
self.ver_jsoncpp = _tmp['jsoncpp']
|
||||
self.ver_mongoose = _tmp['mongoose']
|
||||
except IndexError:
|
||||
cc.e('invalid configuration file: not all necessary external version are set.')
|
||||
return False
|
||||
|
||||
_tmp = _cfg['toolchain']
|
||||
if self.is_win:
|
||||
if 'wget' in _tmp:
|
||||
self.wget = _tmp['wget']
|
||||
else:
|
||||
self.wget = None
|
||||
if self.wget is None or not os.path.exists(self.wget):
|
||||
cc.w(' - can not find `wget.exe`, you can get it at https://eternallybored.org/misc/wget/')
|
||||
|
||||
if '7z' in _tmp:
|
||||
self.zip7 = _tmp['7z']
|
||||
else:
|
||||
self.zip7 = None
|
||||
if self.zip7 is None or not os.path.exists(self.zip7):
|
||||
cc.w(' - can not find `7z.exe`, you can get it at http://www.7-zip.org')
|
||||
|
||||
if 'msbuild' in _tmp:
|
||||
self.msbuild = _tmp['msbuild']
|
||||
else:
|
||||
self.msbuild = self._get_msbuild()
|
||||
|
||||
if self.msbuild is None or not os.path.exists(self.msbuild):
|
||||
cc.w(' - can not locate `MSBuild`, so I can build nothing.')
|
||||
|
||||
if 'nsis' in _tmp:
|
||||
self.nsis = _tmp['nsis']
|
||||
else:
|
||||
self.nsis = self._get_nsis()
|
||||
|
||||
if self.nsis is None or not os.path.exists(self.nsis):
|
||||
cc.w(' - can not locate `nsis`, so I can not make installer.')
|
||||
|
||||
elif self.is_linux:
|
||||
if 'cmake' in _tmp:
|
||||
self.cmake = _tmp['cmake']
|
||||
else:
|
||||
self.cmake = '/usr/bin/cmake'
|
||||
|
||||
if not os.path.exists(self.cmake):
|
||||
cc.e(' - can not locate `cmake`, so I can not build binary from source.')
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def _get_msbuild(self):
|
||||
# 14.0 = VS2015
|
||||
# 12.0 = VS2012
|
||||
# 4.0 = VS2008
|
||||
chk = ['14.0', '4.0', '12.0']
|
||||
|
||||
msp = None
|
||||
for c in chk:
|
||||
msp = self._winreg_read("SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\{}".format(c), 'MSBuildToolsPath')
|
||||
if msp is not None:
|
||||
break
|
||||
|
||||
if msp is None:
|
||||
return None
|
||||
|
||||
return os.path.join(msp[0], 'MSBuild.exe')
|
||||
|
||||
def _get_nsis(self):
|
||||
p = self._winreg_read_wow64_32(r'SOFTWARE\NSIS\Unicode', '')
|
||||
if p is None:
|
||||
return None
|
||||
|
||||
return os.path.join(p[0], 'makensis.exe')
|
||||
|
||||
def _winreg_read(self, path, key):
|
||||
try:
|
||||
import winreg
|
||||
hkey = winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, path, 0, winreg.KEY_READ)
|
||||
value = winreg.QueryValueEx(hkey, key)
|
||||
return value
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
def _winreg_read_wow64_32(self, path, key):
|
||||
try:
|
||||
import winreg
|
||||
hkey = winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, path, 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
|
||||
value = winreg.QueryValueEx(hkey, key)
|
||||
return value
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
|
||||
env = Env()
|
||||
del Env
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf8 -*-
|
||||
|
||||
import os
|
||||
|
@ -9,6 +8,8 @@ import sys
|
|||
import time
|
||||
|
||||
from . import colorconsole as cc
|
||||
from .env import env
|
||||
|
||||
|
||||
from .configs import cfg
|
||||
|
||||
|
@ -29,6 +30,32 @@ elif cfg.is_py3:
|
|||
if sys.platform == 'win32':
|
||||
import winreg
|
||||
|
||||
THIS_PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
ROOT_PATH = os.path.abspath(os.path.join(THIS_PATH, '..'))
|
||||
|
||||
|
||||
def download_file(desc, url, target_path, file_name):
|
||||
cc.n('downloading {} ...'.format(desc))
|
||||
|
||||
local_file_name = os.path.join(target_path, file_name)
|
||||
if os.path.exists(local_file_name):
|
||||
cc.w('already exists, skip.')
|
||||
return True
|
||||
|
||||
if env.is_win:
|
||||
cmd = '"{}" --no-check-certificate {} -O "{}"'.format(env.wget, url, local_file_name)
|
||||
sys_exec(cmd, True)
|
||||
elif env.is_linux:
|
||||
os.system('wget --no-check-certificate {} -O "{}"'.format(url, local_file_name))
|
||||
else:
|
||||
return False
|
||||
|
||||
if not os.path.exists(local_file_name):
|
||||
cc.e('downloading {} from {} failed.'.format(desc, url))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def extension_suffixes():
|
||||
# imp.get_suffixes()
|
||||
|
@ -57,7 +84,6 @@ def extension_suffixes():
|
|||
elif cfg.dist == 'macos':
|
||||
raise RuntimeError('not support MacOS now.')
|
||||
|
||||
# cc.v(EXTENSION_SUFFIXES)
|
||||
return EXTENSION_SUFFIXES
|
||||
|
||||
|
||||
|
@ -282,16 +308,16 @@ def winreg_read_wow64_32(path, key):
|
|||
|
||||
|
||||
def sys_exec(cmd, direct_output=False, output_codec=None):
|
||||
# 注意:output_codec在windows默认为gb2312,其他平台默认utf8
|
||||
_os = platform.system().lower()
|
||||
cc.v(cmd)
|
||||
# _os = platform.system().lower()
|
||||
if output_codec is None:
|
||||
if _os == 'windows':
|
||||
if env.is_win:
|
||||
output_codec = 'gb2312'
|
||||
else:
|
||||
output_codec = 'utf8'
|
||||
|
||||
p = None
|
||||
if _os == 'windows':
|
||||
if env.is_win:
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, shell=True)
|
||||
|
||||
else:
|
||||
|
@ -305,8 +331,6 @@ def sys_exec(cmd, direct_output=False, output_codec=None):
|
|||
break
|
||||
|
||||
if direct_output:
|
||||
# cc.v(line.decode(output_codec))
|
||||
# cc.d(line, end='')
|
||||
cc.o((cc.CR_GRAY, line), end='')
|
||||
|
||||
output += line
|
||||
|
@ -316,18 +340,18 @@ def sys_exec(cmd, direct_output=False, output_codec=None):
|
|||
return (ret, output)
|
||||
|
||||
|
||||
def msvc_build(sln_file, proj_name, target, platform, force_rebuild):
|
||||
msbuild = msbuild_path()
|
||||
|
||||
if force_rebuild:
|
||||
cmd = '"{}" "{}" "/target:clean" "/property:Configuration={};Platform={}"'.format(msbuild, sln_file, target, platform)
|
||||
ret, _ = sys_exec(cmd, direct_output=True)
|
||||
cc.v('ret:', ret)
|
||||
|
||||
cmd = '"{}" "{}" "/target:{}" "/property:Configuration={};Platform={}"'.format(msbuild, sln_file, proj_name, target, platform)
|
||||
ret, _ = sys_exec(cmd, direct_output=True)
|
||||
if ret != 0:
|
||||
raise RuntimeError('build MSVC project `{}` failed.'.format(proj_name))
|
||||
# def msvc_build(sln_file, proj_name, target, platform, force_rebuild):
|
||||
# msbuild = msbuild_path()
|
||||
#
|
||||
# if force_rebuild:
|
||||
# cmd = '"{}" "{}" "/target:clean" "/property:Configuration={};Platform={}"'.format(msbuild, sln_file, target, platform)
|
||||
# ret, _ = sys_exec(cmd, direct_output=True)
|
||||
# cc.v('ret:', ret)
|
||||
#
|
||||
# cmd = '"{}" "{}" "/target:{}" "/property:Configuration={};Platform={}"'.format(msbuild, sln_file, proj_name, target, platform)
|
||||
# ret, _ = sys_exec(cmd, direct_output=True)
|
||||
# if ret != 0:
|
||||
# raise RuntimeError('build MSVC project `{}` failed.'.format(proj_name))
|
||||
|
||||
|
||||
def nsis_build(nsi_file, _define=''):
|
||||
|
@ -405,37 +429,6 @@ def make_targz(work_path, folder, to_file):
|
|||
os.chdir(old_p)
|
||||
|
||||
|
||||
def fix_extension_files(s_path, t_path):
|
||||
cc.n('\nfix extension files...')
|
||||
# 遍历s_path目录下的所有Python扩展文件(动态库),并将其移动到t_path目录下,同时改名。
|
||||
# 例如, s_path/abc/def.pyd -> t_path/abc.def.pyd
|
||||
|
||||
s_path = os.path.abspath(s_path)
|
||||
t_path = os.path.abspath(t_path)
|
||||
|
||||
ext = extension_suffixes()
|
||||
s_path_len = len(s_path)
|
||||
|
||||
def _fix_(s_path, t_path, sub_path):
|
||||
for parent, dir_list, file_list in os.walk(sub_path):
|
||||
for d in dir_list:
|
||||
_fix_(s_path, t_path, os.path.join(parent, d))
|
||||
|
||||
for filename in file_list:
|
||||
_, e = os.path.splitext(filename)
|
||||
if e in ext:
|
||||
f_from = os.path.join(parent, filename)
|
||||
f_to = f_from[s_path_len + 1:]
|
||||
f_to = f_to.replace('\\', '.')
|
||||
f_to = f_to.replace('/', '.')
|
||||
f_to = os.path.join(t_path, f_to)
|
||||
|
||||
cc.v('move: ', f_from, '\n -> ', f_to)
|
||||
shutil.move(f_from, f_to)
|
||||
|
||||
_fix_(s_path, t_path, s_path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# test()
|
||||
pass
|
||||
|
|
|
@ -3,6 +3,12 @@
|
|||
# for windows
|
||||
#============================================
|
||||
|
||||
# Need wget to download necessary dependency files.
|
||||
wget = C:\Program Files (x86)\wget\wget.exe
|
||||
|
||||
# Need 7z to unzip downloaded files.
|
||||
7z = C:\Program Files (x86)\7zip\7z.exe
|
||||
|
||||
# if not set nsis path, default to get it by register.
|
||||
#nsis = C:\Program Files (x86)\NSIS\Unicode\makensis.exe
|
||||
|
||||
|
|
Loading…
Reference in New Issue