2019-11-06 11:39:42 +08:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import copy
|
|
|
|
import glob
|
|
|
|
import shutil
|
|
|
|
import platform
|
|
|
|
import fnmatch
|
|
|
|
|
|
|
|
BIN_DIR = 'bin'
|
|
|
|
EXE_NAME = 'demoui'
|
|
|
|
ASSETS_DIR = 'assets'
|
|
|
|
OUTPUT_DIR = 'release'
|
2019-11-06 14:30:43 +08:00
|
|
|
CWD = os.getcwd()
|
2020-04-29 09:01:47 +08:00
|
|
|
OS_NAME = platform.system();
|
|
|
|
if OS_NAME == 'Darwin':
|
|
|
|
AWTK_DLL='libawtk.dylib'
|
|
|
|
elif OS_NAME == 'Linux':
|
|
|
|
AWTK_DLL='libawtk.so'
|
|
|
|
elif OS_NAME == 'Windows':
|
|
|
|
AWTK_DLL='awtk.dll'
|
2019-11-06 11:39:42 +08:00
|
|
|
|
2019-11-06 13:53:04 +08:00
|
|
|
|
2019-11-06 14:30:43 +08:00
|
|
|
def init(exe, assets_root, bin_root):
|
2019-11-06 11:39:42 +08:00
|
|
|
global BIN_DIR
|
|
|
|
global EXE_NAME
|
|
|
|
global ASSETS_DIR
|
|
|
|
global OUTPUT_DIR
|
|
|
|
|
|
|
|
EXE_NAME = exe
|
2019-11-06 14:30:43 +08:00
|
|
|
BIN_DIR = joinPath(bin_root, 'bin')
|
|
|
|
OUTPUT_DIR = joinPath(CWD, 'release')
|
2020-08-18 10:04:27 +08:00
|
|
|
ASSETS_DIR = joinPath(assets_root, 'res/assets')
|
2019-11-06 14:47:58 +08:00
|
|
|
|
2019-11-06 14:19:49 +08:00
|
|
|
if not os.path.exists(BIN_DIR):
|
2019-11-06 14:30:43 +08:00
|
|
|
BIN_DIR = joinPath(bin_root, 'build/bin')
|
2019-11-06 14:19:49 +08:00
|
|
|
|
2019-11-06 11:39:42 +08:00
|
|
|
if not os.path.exists(ASSETS_DIR):
|
2020-08-18 10:04:27 +08:00
|
|
|
ASSETS_DIR = joinPath(assets_root, 'assets')
|
2019-11-06 14:19:49 +08:00
|
|
|
if not os.path.exists(ASSETS_DIR):
|
2020-08-18 10:04:27 +08:00
|
|
|
ASSETS_DIR = joinPath(assets_root, '../awtk/res/assets')
|
2019-11-06 11:39:42 +08:00
|
|
|
if not os.path.exists(ASSETS_DIR):
|
2019-11-06 13:53:04 +08:00
|
|
|
print(ASSETS_DIR + ' not exist.')
|
|
|
|
sys.exit()
|
2019-11-06 11:39:42 +08:00
|
|
|
|
|
|
|
if os.path.exists(OUTPUT_DIR):
|
2019-11-06 13:53:04 +08:00
|
|
|
shutil.rmtree(OUTPUT_DIR)
|
2019-11-06 11:39:42 +08:00
|
|
|
|
2019-11-06 14:47:58 +08:00
|
|
|
print('==================================================')
|
2019-11-06 14:44:06 +08:00
|
|
|
print('EXE_NAME:' + EXE_NAME)
|
2019-11-06 11:39:42 +08:00
|
|
|
print('ASSETS_DIR:' + ASSETS_DIR)
|
|
|
|
print('OUTPUT_DIR:' + OUTPUT_DIR)
|
|
|
|
print('BIN_DIR:' + BIN_DIR)
|
2019-11-06 14:47:58 +08:00
|
|
|
print('==================================================')
|
2019-11-06 11:39:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
def joinPath(root, subdir):
|
|
|
|
return os.path.normpath(os.path.join(root, subdir))
|
|
|
|
|
|
|
|
|
|
|
|
def copyFile(src_root_dir, src, dst_root_dir, dst):
|
|
|
|
s = joinPath(src_root_dir, src)
|
|
|
|
d = joinPath(dst_root_dir, dst)
|
|
|
|
print(s + '->' + d)
|
|
|
|
if os.path.exists(s):
|
|
|
|
dir = os.path.dirname(d)
|
|
|
|
if os.path.exists(dir):
|
|
|
|
shutil.copyfile(s, d)
|
|
|
|
else:
|
|
|
|
os.makedirs(dir)
|
|
|
|
shutil.copyfile(s, d)
|
|
|
|
else:
|
|
|
|
print('!!! copyFile src NOT EXISTS: ' + s)
|
|
|
|
|
|
|
|
|
|
|
|
def ignore_patterns_list(patterns_list):
|
|
|
|
def _ignore_patterns(path, names):
|
|
|
|
ignored_names = []
|
|
|
|
for pattern in patterns_list:
|
|
|
|
ignored_names.extend(fnmatch.filter(names, pattern))
|
|
|
|
return set(ignored_names)
|
|
|
|
return _ignore_patterns
|
|
|
|
|
|
|
|
|
|
|
|
def copyFiles(src_root_dir, src, dst_root_dir, dst, ignore_files=[]):
|
|
|
|
s = joinPath(src_root_dir, src)
|
|
|
|
d = joinPath(dst_root_dir, dst)
|
|
|
|
print(s + '->' + d)
|
|
|
|
if os.path.exists(s):
|
|
|
|
shutil.rmtree(d, True)
|
|
|
|
ignore_files.append('*.o')
|
|
|
|
ignore_files.append('*.obj')
|
|
|
|
ignore_files.append('*.res')
|
|
|
|
ignore_files.append('*.xml')
|
|
|
|
ignore_files.append('*.inc')
|
|
|
|
shutil.copytree(s, d, ignore=ignore_patterns_list(ignore_files))
|
|
|
|
else:
|
|
|
|
print('!!! copyFiles src NOT EXISTS: ' + s)
|
|
|
|
|
|
|
|
|
|
|
|
def copyExe():
|
2019-11-06 13:53:04 +08:00
|
|
|
output_bin_dir = joinPath(OUTPUT_DIR, 'bin')
|
|
|
|
copyFile(BIN_DIR, EXE_NAME, output_bin_dir, EXE_NAME)
|
2020-04-29 09:01:47 +08:00
|
|
|
copyFile(BIN_DIR, AWTK_DLL, output_bin_dir, AWTK_DLL)
|
|
|
|
|
2019-11-06 13:53:04 +08:00
|
|
|
os.chmod(joinPath(output_bin_dir, EXE_NAME), 0o755)
|
2019-11-06 11:39:42 +08:00
|
|
|
|
|
|
|
def copyAssets():
|
2020-05-18 16:14:44 +08:00
|
|
|
copyFiles(ASSETS_DIR, '', OUTPUT_DIR, 'assets/')
|
2019-11-06 11:39:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
def release():
|
|
|
|
copyExe()
|
|
|
|
copyAssets()
|