awtk/scripts/release_common.py

140 lines
3.7 KiB
Python
Raw Permalink Normal View History

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();
2019-11-06 11:39:42 +08:00
2021-06-07 11:51:26 +08:00
def getShareLibExt():
if OS_NAME == 'Darwin':
return 'dylib'
elif OS_NAME == 'Windows':
return 'dll'
else:
return 'so'
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)
2021-07-05 16:22:51 +08:00
def copySharedLib(src, dst):
if not os.path.exists(src):
print('copy shared lib: ' + src + ' is not exists.')
else:
files = os.listdir(src)
for file in files:
srcFilename = joinPath(src, file)
dstFilename = joinPath(dst, file)
if os.path.isdir(srcFilename):
if not os.path.exists(dstFilename):
os.makedirs(dstFilename)
copySharedLib(srcFilename, dstFilename)
else:
ext = '.' + getShareLibExt()
if file.endswith(ext):
print('copy shared lib: ' + srcFilename + ' ==> ' + dstFilename)
shutil.copy(srcFilename, dst)
os.chmod(dstFilename, 0o755)
2019-11-06 11:39:42 +08:00
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)
2021-07-05 16:22:51 +08:00
copySharedLib(BIN_DIR, output_bin_dir)
2019-11-06 11:39:42 +08:00
2021-07-05 16:22:51 +08:00
os.chmod(joinPath(output_bin_dir, EXE_NAME), 0o755)
2021-06-07 11:51:26 +08:00
2019-11-06 11:39:42 +08:00
def copyAssets():
2021-07-05 16:22:51 +08:00
copyFiles(ASSETS_DIR, '', OUTPUT_DIR, 'assets/')
2019-11-06 11:39:42 +08:00
2021-01-15 10:39:00 +08:00
def cleanFiles():
d = joinPath(OUTPUT_DIR, 'assets/default/inc')
shutil.rmtree(d, True)
2019-11-06 11:39:42 +08:00
def release():
copyExe()
copyAssets()
2021-01-15 10:39:00 +08:00
cleanFiles()