pull/32/merge
apexliu 2017-03-09 04:04:01 +08:00
parent 83e9b9439e
commit 35569651a3
8 changed files with 312 additions and 150 deletions

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import getopt import getopt
@ -7,47 +6,27 @@ import os
import platform import platform
import sys import sys
THIS_PATH = os.path.abspath(os.path.dirname(__file__)) from builder.core.env import env
ROOT_PATH = os.path.abspath(os.path.join(THIS_PATH, '..')) import builder.core.colorconsole as cc
BUILDER_PATH = os.path.join(THIS_PATH, 'builder') import builder.core.utils as utils
from builder.core.context import *
sys.path.append(os.path.join(BUILDER_PATH)) if env.is_py2:
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:
_input = raw_input _input = raw_input
else: else:
_input = input _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 = list()
options_idx = 0 options_idx = 0
ctx = BuildContext()
def main(): def main():
cc.set_default(sep='', end='\n') cc.set_default(sep='', end='\n')
if not env.init():
return
action = None action = None
argv = sys.argv[1:] argv = sys.argv[1:]
if len(argv) >= 1: if len(argv) >= 1:
@ -151,7 +130,7 @@ def do_opt(opt):
return 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(BUILDER_PATH, script), arg) cmd = '%s -B %s %s' % (utils.cfg.py_exec, os.path.join(env.builder_path, script), arg)
os.system(cmd) os.system(cmd)
@ -193,14 +172,15 @@ def add_split():
def make_options(): def make_options():
global options, options_idx, cfg # global options, options_idx
#
options = list() # options = list()
options_idx = 0 # options_idx = 0
if ctx.host_os == 'windows': if ctx.host_os == 'windows':
add_option('x86', 'ver', 'Update version setting') 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_split()
add_option('x86', 'assist-exe', 'Assist Execute [%s]' % ctx.target_path) add_option('x86', 'assist-exe', 'Assist Execute [%s]' % ctx.target_path)
# add_option('x86', 'assist-rdp', 'Teleport RDP [%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) add_option('x86', 'installer', 'Teleport Installer for %s' % ctx.host_os)
else: else:
add_option('x64', 'ver', 'Update version setting') 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', 'pysrt', 'Make Python-Runtime for python%s-x64' % env.py_ver_str)
add_option('x64', 'external', 'Build external for Teleport-Server') add_option('x64', 'external', 'Build external dependency')
add_split() add_split()
add_option('x64', 'server', 'Build server app [%s]' % ctx.target_path) add_option('x64', 'server', 'Build server app [%s]' % ctx.target_path)
add_split() add_split()

View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

View File

@ -1,4 +1,3 @@
#!/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import codecs import codecs
@ -8,6 +7,8 @@ from core import colorconsole as cc
from core import utils from core import utils
from core.context import * from core.context import *
from core.env import env
ctx = BuildContext() ctx = BuildContext()
ROOT_PATH = utils.cfg.ROOT_PATH ROOT_PATH = utils.cfg.ROOT_PATH
@ -23,7 +24,6 @@ JSONCPP_VER = utils.cfg.ver.jsoncpp
MONGOOSE_VER = utils.cfg.ver.mongoose MONGOOSE_VER = utils.cfg.ver.mongoose
class BuilderBase: class BuilderBase:
def __init__(self): def __init__(self):
self.out_dir = '' self.out_dir = ''
@ -37,7 +37,7 @@ class BuilderBase:
def build_jsoncpp(self): def build_jsoncpp(self):
file_name = 'jsoncpp-{}.zip'.format(JSONCPP_VER) 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 return
self._build_jsoncpp(file_name) self._build_jsoncpp(file_name)
@ -46,7 +46,7 @@ class BuilderBase:
def build_mongoose(self): def build_mongoose(self):
file_name = 'mongoose-{}.zip'.format(MONGOOSE_VER) 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 return
self._build_mongoose(file_name) self._build_mongoose(file_name)
@ -54,8 +54,11 @@ class BuilderBase:
cc.e("this is a pure-virtual function.") cc.e("this is a pure-virtual function.")
def build_openssl(self): def build_openssl(self):
file_name = 'openssl-{}.tar.gz'.format(OPENSSL_VER) file_name = 'openssl-{}.zip'.format(OPENSSL_VER)
if not self._download_file('openssl source tarball', 'https://www.openssl.org/source/{}'.format(file_name), file_name): _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 return
self._build_openssl(file_name) self._build_openssl(file_name)
@ -64,7 +67,7 @@ class BuilderBase:
def build_libuv(self): def build_libuv(self):
file_name = 'libuv-{}.zip'.format(LIBUV_VER) 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 return
self._build_libuv(file_name) self._build_libuv(file_name)
@ -73,7 +76,7 @@ class BuilderBase:
def build_mbedtls(self): def build_mbedtls(self):
file_name = 'mbedtls-mbedtls-{}.zip'.format(MBEDTLS_VER) 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 return
self._build_mbedtls(file_name) self._build_mbedtls(file_name)
@ -82,7 +85,7 @@ class BuilderBase:
def build_libssh(self): def build_libssh(self):
file_name = 'libssh-{}.zip'.format(LIBSSH_VER) 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 return
self._build_libssh(file_name) self._build_libssh(file_name)
@ -91,26 +94,26 @@ class BuilderBase:
def build_sqlite(self): def build_sqlite(self):
file_name = 'sqlite-autoconf-{}.tar.gz'.format(SQLITE_VER) 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 return
self._build_sqlite(file_name) self._build_sqlite(file_name)
def _build_sqlite(self, file_name): def _build_sqlite(self, file_name):
cc.e("this is a pure-virtual function.") cc.e("this is a pure-virtual function.")
def _download_file(self, desc, url, file_name): # def _download_file(self, desc, url, file_name):
cc.n('downloading {} ...'.format(desc)) # cc.n('downloading {} ...'.format(desc))
if os.path.exists(os.path.join(PATH_DOWNLOAD, file_name)): # if os.path.exists(os.path.join(PATH_DOWNLOAD, file_name)):
cc.w('already exists, skip.') # cc.w('already exists, skip.')
return True # return True
#
os.system('wget --no-check-certificate {} -O "{}/{}"'.format(url, PATH_DOWNLOAD, file_name)) # 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)): # if not os.path.exists(os.path.join(PATH_DOWNLOAD, file_name)):
cc.e('downloading {} from {} failed.'.format(desc, url)) # cc.e('downloading {} from {} failed.'.format(desc, url))
return True # return True
#
return True # return True
def fix_output(self): def fix_output(self):
pass pass
@ -126,6 +129,10 @@ class BuilderWin(BuilderBase):
def _build_openssl(self, file_name): def _build_openssl(self, file_name):
cc.e('build openssl-static for Windows...not supported yet.') 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): def fix_output(self):
pass pass
@ -166,21 +173,23 @@ class BuilderLinux(BuilderBase):
cc.w('already exists, skip.') cc.w('already exists, skip.')
def _build_openssl(self, file_name): def _build_openssl(self, file_name):
if not os.path.exists(self.OPENSSL_PATH_SRC): pass # we do not need build openssl anymore, because first time run build.sh we built Python, it include openssl.
os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP))
cc.n('build openssl static...') # if not os.path.exists(self.OPENSSL_PATH_SRC):
if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssl.a')): # os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP))
cc.w('already exists, skip.') #
return # cc.n('build openssl static...')
# if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssl.a')):
old_p = os.getcwd() # cc.w('already exists, skip.')
os.chdir(self.OPENSSL_PATH_SRC) # return
#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)) # old_p = os.getcwd()
os.system('make') # os.chdir(self.OPENSSL_PATH_SRC)
os.system('make install') # #os.system('./config --prefix={} --openssldir={}/openssl no-zlib no-shared'.format(self.PATH_RELEASE, self.PATH_RELEASE))
os.chdir(old_p) # 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): def _build_libuv(self, file_name):
if not os.path.exists(self.LIBUV_PATH_SRC): if not os.path.exists(self.LIBUV_PATH_SRC):
@ -328,26 +337,21 @@ class BuilderLinux(BuilderBase):
# os.chdir(old_p) # os.chdir(old_p)
cmake_define = ' -DCMAKE_INSTALL_PREFIX={}' \ cmake_define = ' -DCMAKE_INSTALL_PREFIX={}' \
' -D_OPENSSL_VERSION={}' \ ' -D_OPENSSL_VERSION={}' \
' -DOPENSSL_INCLUDE_DIR={}/include' \ ' -DOPENSSL_INCLUDE_DIR={}/include' \
' -DOPENSSL_LIBRARIES={}/lib' \ ' -DOPENSSL_LIBRARIES={}/lib' \
' -DWITH_GSSAPI=OFF' \ ' -DWITH_GSSAPI=OFF' \
' -DWITH_ZLIB=OFF' \ ' -DWITH_ZLIB=OFF' \
' -DWITH_STATIC_LIB=ON' \ ' -DWITH_STATIC_LIB=ON' \
' -DWITH_PCAP=OFF' \ ' -DWITH_PCAP=OFF' \
' -DWITH_TESTING=OFF' \ ' -DWITH_TESTING=OFF' \
' -DWITH_CLIENT_TESTING=OFF' \ ' -DWITH_CLIENT_TESTING=OFF' \
' -DWITH_EXAMPLES=OFF' \ ' -DWITH_EXAMPLES=OFF' \
' -DWITH_BENCHMARKS=OFF' \ ' -DWITH_BENCHMARKS=OFF' \
' -DWITH_NACL=OFF' \ ' -DWITH_NACL=OFF' \
' ..'.format(self.PATH_RELEASE, OPENSSL_VER, self.PATH_RELEASE, self.PATH_RELEASE) ' ..'.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. utils.cmake(build_path, 'Release', False, cmake_define)
# 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
# because make install will fail because we can not disable ssh_shared target, # because make install will fail because we can not disable ssh_shared target,
# so we copy necessary files ourselves. # so we copy necessary files ourselves.
@ -393,6 +397,9 @@ def gen_builder(dist):
def main(): def main():
if not env.init():
return
builder = None builder = None
argv = sys.argv[1:] argv = sys.argv[1:]
@ -413,7 +420,7 @@ def main():
builder.build_jsoncpp() builder.build_jsoncpp()
builder.build_mongoose() builder.build_mongoose()
# builder.build_openssl() builder.build_openssl()
####builder.build_libuv() ####builder.build_libuv()
builder.build_mbedtls() builder.build_mbedtls()
builder.build_libssh() builder.build_libssh()

View File

@ -59,9 +59,6 @@ COLORS = {
} }
# env = eomcore.env.get_env()
class ColorConsole: class ColorConsole:
""" """
:type _win_color : Win32ColorConsole :type _win_color : Win32ColorConsole

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
import os import os

178
build/builder/core/env.py Normal file
View File

@ -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

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
import os import os
@ -9,6 +8,8 @@ import sys
import time import time
from . import colorconsole as cc from . import colorconsole as cc
from .env import env
from .configs import cfg from .configs import cfg
@ -29,6 +30,32 @@ elif cfg.is_py3:
if sys.platform == 'win32': if sys.platform == 'win32':
import winreg 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(): def extension_suffixes():
# imp.get_suffixes() # imp.get_suffixes()
@ -57,7 +84,6 @@ def extension_suffixes():
elif cfg.dist == 'macos': elif cfg.dist == 'macos':
raise RuntimeError('not support MacOS now.') raise RuntimeError('not support MacOS now.')
# cc.v(EXTENSION_SUFFIXES)
return 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): def sys_exec(cmd, direct_output=False, output_codec=None):
# 注意output_codec在windows默认为gb2312其他平台默认utf8 cc.v(cmd)
_os = platform.system().lower() # _os = platform.system().lower()
if output_codec is None: if output_codec is None:
if _os == 'windows': if env.is_win:
output_codec = 'gb2312' output_codec = 'gb2312'
else: else:
output_codec = 'utf8' output_codec = 'utf8'
p = None p = None
if _os == 'windows': if env.is_win:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, shell=True) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, shell=True)
else: else:
@ -305,8 +331,6 @@ def sys_exec(cmd, direct_output=False, output_codec=None):
break break
if direct_output: if direct_output:
# cc.v(line.decode(output_codec))
# cc.d(line, end='')
cc.o((cc.CR_GRAY, line), end='') cc.o((cc.CR_GRAY, line), end='')
output += line output += line
@ -316,18 +340,18 @@ def sys_exec(cmd, direct_output=False, output_codec=None):
return (ret, output) return (ret, output)
def msvc_build(sln_file, proj_name, target, platform, force_rebuild): # def msvc_build(sln_file, proj_name, target, platform, force_rebuild):
msbuild = msbuild_path() # msbuild = msbuild_path()
#
if force_rebuild: # if force_rebuild:
cmd = '"{}" "{}" "/target:clean" "/property:Configuration={};Platform={}"'.format(msbuild, sln_file, target, platform) # cmd = '"{}" "{}" "/target:clean" "/property:Configuration={};Platform={}"'.format(msbuild, sln_file, target, platform)
ret, _ = sys_exec(cmd, direct_output=True) # ret, _ = sys_exec(cmd, direct_output=True)
cc.v('ret:', ret) # cc.v('ret:', ret)
#
cmd = '"{}" "{}" "/target:{}" "/property:Configuration={};Platform={}"'.format(msbuild, sln_file, proj_name, target, platform) # cmd = '"{}" "{}" "/target:{}" "/property:Configuration={};Platform={}"'.format(msbuild, sln_file, proj_name, target, platform)
ret, _ = sys_exec(cmd, direct_output=True) # ret, _ = sys_exec(cmd, direct_output=True)
if ret != 0: # if ret != 0:
raise RuntimeError('build MSVC project `{}` failed.'.format(proj_name)) # raise RuntimeError('build MSVC project `{}` failed.'.format(proj_name))
def nsis_build(nsi_file, _define=''): def nsis_build(nsi_file, _define=''):
@ -405,37 +429,6 @@ def make_targz(work_path, folder, to_file):
os.chdir(old_p) 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__': if __name__ == '__main__':
# test() # test()
pass pass

View File

@ -3,6 +3,12 @@
# for windows # 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. # if not set nsis path, default to get it by register.
#nsis = C:\Program Files (x86)\NSIS\Unicode\makensis.exe #nsis = C:\Program Files (x86)\NSIS\Unicode\makensis.exe