awtk/scripts/app_helper_base.py

763 lines
32 KiB
Python
Raw Normal View History

2020-08-14 16:43:12 +08:00
import os
import sys
import json
2023-08-25 17:10:16 +08:00
import atexit
2020-08-14 16:43:12 +08:00
import shutil
import platform
2023-08-25 17:10:16 +08:00
import res_config
import compile_config
2023-09-14 07:13:35 +08:00
from SCons import Script, Environment
2020-08-14 16:43:12 +08:00
2020-11-24 09:28:40 +08:00
PLATFORM = platform.system()
2023-08-25 17:10:16 +08:00
SRT_SCONS_CONFIG_FUN = 'get_scons_config'
SRT_SCONS_CONFIG_SCRIPT = 'SCONS_CONFIG_SCRIPT'
SRT_SCONS_CONFIG_SCRIPT_ARGV = 'SCONS_CONFIG_SCRIPT_ARGV'
COMPILE_CONFIG = {
2024-01-13 17:16:47 +08:00
'AWTK_ROOT' : { 'value' : None, 'type' : str.__name__, 'desc' : ['awtk root'], 'help_info' : 'set link awtk root, AWTK_ROOT=XXXXX'},
'LINUX_FB' : { 'value' : False, 'type' : bool.__name__, 'desc' : ['use linux\'s building'], 'help_info' : 'use linux\'s compile tools prefix building, value is true or false'},
'MVVM_ROOT' : { 'value' : None, 'type' : str.__name__, 'desc' : ['awtk\'s mvvm root'], 'help_info' : 'set link awtk\'s mvvm root, MVVM_ROOT=XXXXX'},
'WITH_MVVM' : { 'value' : False, 'type' : bool.__name__, 'desc' : ['use mvvm'], 'help_info' : 'use mvvm\'s lib, value is true or false'},
'WITH_JERRYSCRIPT' : { 'value' : False, 'type' : bool.__name__, 'desc' : ['use mvvm\'s js'], 'help_info' : 'use mvvm js\'s lib, value is true or false'},
'WITH_IOTJS' : { 'value' : False, 'type' : bool.__name__, 'desc' : ['use mvvm\'s iotjs'], 'help_info' : 'use mvvm iotjs\'s lib, value is true or false'},
'AWFLOW_ROOT' : { 'value' : None, 'type' : str.__name__, 'desc' : ['awtk\'s awflow root'], 'help_info' : 'set link awtk\'s awflow root, AWFLOW_ROOT=XXXXX'},
'WITH_AWFLOW' : { 'value' : False, 'type' : bool.__name__, 'desc' : ['use awflow'], 'help_info' : 'use awflow\'s lib, value is true or false'},
SRT_SCONS_CONFIG_SCRIPT : { 'value' : None, 'type' : str.__name__, 'save_file' : False, 'desc' : ['set script file path, this is script has {0}(COMPILE_CONFIG, ARGUMENTS, argv) function'.format(SRT_SCONS_CONFIG_FUN)], 'help_info' : 'set res config file path, this is script must has {0}(COMPILE_CONFIG, ARGUMENTS, argv) function, {0}\'s function return compile_config\'s class, CONFIG_SCRIPT=XXXXX'.format(SRT_SCONS_CONFIG_FUN)},
SRT_SCONS_CONFIG_SCRIPT_ARGV : { 'value' : None, 'type' : str.__name__, 'save_file' : False, 'desc' : ['value is {0}\s argv for script file '.format(SRT_SCONS_CONFIG_FUN)], 'help_info' : 'value is {0}\s argv for script file\'s {0}, SCONS_CONFIG_SCRIPT_ARGV=XXXXX'.format(SRT_SCONS_CONFIG_FUN)},
'BUILD_DIR' : { 'value' : None, 'type' : str.__name__, 'desc' : ['build dir, compile temp file dir'], 'help_info' : 'set build dir, save compile temp file dir or *.obj/.*o dir, BUILD_DIR=XXXXX'},
# 'APP_BIN_DIR' : { 'value' : None, 'type' : str.__name__, 'desc' : ['build bin dir'], 'help_info' : 'set build bin dir, APP_BIN_DIR=XXXXX'},
# 'APP_LIB_DIR' : { 'value' : None, 'type' : str.__name__, 'desc' : ['build lib dir'], 'help_info' : 'set build lib dir, APP_LIB_DIR=XXXXX'},
'DEBUG' : { 'value' : None, 'type' : bool.__name__, 'desc' : ['awtk\'s compile is debug'], 'help_info' : 'awtk\'s compile is debug, value is true or false' },
'PDB' : { 'value' : True, 'type' : bool.__name__, 'desc' : ['export pdb file'], 'help_info' : 'export pdb file, value is true or false' },
'FLAGS' : { 'value' : None, 'type' : str.__name__, 'desc' : ['compile flags'], 'help_info' : 'set compile\'s flags, so care of system and compile tools'},
'LIBS' : { 'value' : [], 'type' : list.__name__, 'desc' : ['compile libs'], 'help_info' : 'set compile\'s libs, so care of system and compile tools, use \',\' split muliple libraries '},
'LIBPATH' : { 'value' : [], 'type' : list.__name__, 'desc' : ['compile lib paths'], 'help_info' : 'set compile\'s lib paths, so care of system and compile tools, use \',\' split muliple librarie\'s paths '},
'CPPPATH' : { 'value' : [], 'type' : list.__name__, 'desc' : ['compile include paths'], 'help_info' : 'set compile\'s include paths, so care of system and compile tools, use \',\' split muliple include path '},
'SHARED' : { 'value' : True, 'type' : bool.__name__, 'desc' : ['compile is SharedLibrary'], 'help_info' : 'app\'s compile is Shared Library, value is true or false' },
'IDL_DEF' : { 'value' : True, 'type' : bool.__name__, 'desc' : ['compile build idl def file'], 'help_info' : 'app\'s compile build idl def file, value is true or false' },
'LCD' : { 'value' : None, 'type' : str.__name__, 'save_file' : False, 'desc' : ['app\'s lcd\'s size'], 'help_info' : 'app\'s lcd\'s size, value is [lcd_width]_[lcd_height], example is LCD=320_480' },
'LANGUAGE' : { 'value' : None, 'type' : str.__name__, 'save_file' : False, 'desc' : ['app\'s language'], 'help_info' : 'app\'s language, value is [country]_[language], example is LANGUAGE=zh_CH' },
'FONT' : { 'value' : None, 'type' : str.__name__, 'save_file' : False, 'desc' : ['app\'s font\'s name'], 'help_info' : 'app\'s font\'s name, FONT=XXXXX ' },
'THEME' : { 'value' : None, 'type' : str.__name__, 'save_file' : False, 'desc' : ['app\'s default\'s theme\'s name'], 'help_info' : 'app\'s default\'s theme\'s name, THEME=XXXXX ' },
'RES_ROOT' : { 'value' : None, 'type' : str.__name__, 'save_file' : False, 'desc' : ['app\'s res root'], 'help_info' : 'app\'s res root, RES_ROOT=XXXXX ' },
'WIN32_RES' : { 'value' : None, 'type' : str.__name__, 'desc' : ['app\'s win32 res path'], 'help_info' : 'app\'s win32 res path, WIN32_RES=XXXXX, value\'s default=\'awtk/win32_res/awtk.res\' ' },
2023-08-25 17:10:16 +08:00
}
def set_compile_config(config) :
global COMPILE_CONFIG
COMPILE_CONFIG = config
2021-12-02 09:32:06 +08:00
def getTkcOnly():
env = os.environ
if 'TKC_ONLY' in env:
return env['TKC_ONLY'] == 'True'
else:
return False
2020-11-24 09:28:40 +08:00
def join_path(root, sub):
return os.path.abspath(os.path.join(root, sub))
2020-08-14 16:43:12 +08:00
def mkdir_if_not_exist(fullpath):
if os.path.exists(fullpath):
print(fullpath+' exist.')
else:
os.makedirs(fullpath)
2020-11-24 09:28:40 +08:00
2023-08-25 17:10:16 +08:00
def load_project_json(root, filename):
content = None
config_json = join_path(root, filename)
if not os.path.exists(config_json) or filename == '':
config_json = join_path(root, 'project.json')
if not os.path.exists(config_json) :
print(config_json + ' is not exists.')
return
content = res_config.res_config()
content.load_file(config_json)
return content
2020-08-30 09:01:13 +08:00
2020-08-14 16:43:12 +08:00
class AppHelperBase:
def set_deps(self, DEPENDS_LIBS):
self.DEPENDS_LIBS = DEPENDS_LIBS
return self
2020-11-24 09:28:40 +08:00
2020-10-13 17:43:19 +08:00
def set_src_dir(self, SRC_DIR):
self.SRC_DIR = SRC_DIR
return self
2020-08-14 16:43:12 +08:00
2020-10-14 18:16:22 +08:00
def set_tkc_only(self):
self.AWTK_LIBS = ['tkc']
2020-10-21 14:14:56 +08:00
self.TKC_ONLY = True
2020-10-14 18:16:22 +08:00
return self
2020-08-14 16:43:12 +08:00
def set_libs(self, APP_LIBS):
self.APP_LIBS = APP_LIBS
return self
def set_dll_def(self, DEF_FILE):
self.DEF_FILE = DEF_FILE
return self
def set_dll_def_processor(self, processor):
self.DEF_FILE_PROCESSOR = processor
return self
def set_ccflags(self, APP_CCFLAGS):
self.APP_CCFLAGS = APP_CCFLAGS
return self
def set_cxxflags(self, APP_CXXFLAGS):
self.APP_CXXFLAGS = APP_CXXFLAGS
return self
def add_deps(self, DEPENDS_LIBS):
self.DEPENDS_LIBS += DEPENDS_LIBS
return self
def add_libs(self, APP_LIBS):
self.APP_LIBS += APP_LIBS
return self
2020-11-24 09:28:40 +08:00
2020-10-22 09:02:51 +08:00
def add_platform_libs(self, plat, PLATFORM_LIBS):
if plat == PLATFORM:
self.PLATFORM_LIBS += PLATFORM_LIBS
2020-09-02 16:19:53 +08:00
return self
2020-08-15 11:55:22 +08:00
def add_libpath(self, APP_LIBPATH):
self.APP_LIBPATH += APP_LIBPATH
return self
2020-11-24 09:28:40 +08:00
2020-09-02 16:19:53 +08:00
def add_platform_libpath(self, plat, APP_LIBPATH):
2020-10-22 09:02:51 +08:00
if plat == PLATFORM:
2020-09-02 16:19:53 +08:00
self.APP_LIBPATH += APP_LIBPATH
return self
2020-08-14 16:43:12 +08:00
def add_cpppath(self, APP_CPPPATH):
self.APP_CPPPATH += APP_CPPPATH
return self
2020-11-24 09:28:40 +08:00
2020-09-02 16:19:53 +08:00
def add_platform_cpppath(self, plat, APP_CPPPATH):
2020-10-22 09:02:51 +08:00
if plat == PLATFORM:
2020-09-02 16:19:53 +08:00
self.APP_CPPPATH += APP_CPPPATH
return self
2020-08-14 16:43:12 +08:00
def add_ccflags(self, APP_CCFLAGS):
self.APP_CCFLAGS += APP_CCFLAGS
return self
2020-11-24 09:28:40 +08:00
2020-09-28 07:40:57 +08:00
def add_cflags(self, APP_CFLAGS):
self.APP_CFLAGS += APP_CFLAGS
return self
2020-08-14 16:43:12 +08:00
2020-09-02 16:19:53 +08:00
def add_platform_ccflags(self, plat, APP_CCFLAGS):
2020-10-22 09:02:51 +08:00
if plat == PLATFORM:
2020-09-02 16:19:53 +08:00
self.APP_CCFLAGS += APP_CCFLAGS
return self
2021-02-24 17:43:01 +08:00
def use_std_cxx(self, VERSION):
if platform.system() == 'Windows':
self.APP_CXXFLAGS += ' /std:c++'+str(VERSION)+' '
else:
self.APP_CXXFLAGS += ' -std=c++'+str(VERSION)+' '
2020-08-14 16:43:12 +08:00
def add_cxxflags(self, APP_CXXFLAGS):
self.APP_CXXFLAGS += APP_CXXFLAGS
return self
2020-11-24 09:28:40 +08:00
2020-09-02 16:19:53 +08:00
def add_platform_cxxflags(self, plat, APP_CXXFLAGS):
2020-10-22 09:02:51 +08:00
if plat == PLATFORM:
2020-09-02 16:19:53 +08:00
self.APP_CXXFLAGS += APP_CXXFLAGS
return self
2020-08-14 16:43:12 +08:00
def add_linkflags(self, APP_LINKFLAGS):
self.APP_LINKFLAGS += APP_LINKFLAGS
return self
2020-09-02 16:19:53 +08:00
def add_platform_linkflags(self, plat, APP_LINKFLAGS):
2020-10-22 09:02:51 +08:00
if plat == PLATFORM:
2020-09-02 16:19:53 +08:00
self.APP_LINKFLAGS += APP_LINKFLAGS
return self
2024-01-06 07:33:14 +08:00
2023-06-09 18:07:31 +08:00
def root_get_scons_db_files(self, root):
scons_db_files = []
scons_db_filename = ".sconsign.dblite"
for f in os.listdir(root):
full_path = join_path(root, f)
if os.path.isfile(full_path) and f == scons_db_filename:
scons_db_files.append(full_path)
elif os.path.isdir(full_path) and f != "." and f != "..":
self.root_get_scons_db_files(full_path)
return scons_db_files
def check_and_remove_scons_db(self, root):
scons_db_files = []
scons_db_files = self.root_get_scons_db_files(root)
if sys.version_info.major == 2:
import cPickle as pickle
else:
import pickle
for f in scons_db_files:
try:
with open(f, "rb") as fs:
pickle.load(fs)
fs.close()
2024-01-06 07:33:14 +08:00
except Exception as e :
2023-06-09 18:07:31 +08:00
fs.close()
2024-01-06 07:33:14 +08:00
print(e)
try:
os.remove(f)
except Exception as e :
print(e)
2023-06-09 18:07:31 +08:00
2021-06-28 15:52:16 +08:00
def SConscript(self, SConscriptFiles):
if not self.BUILD_DIR:
Script.SConscript(SConscriptFiles)
else:
2023-09-14 07:13:35 +08:00
env = Environment.Environment()
env.Default(self.BUILD_DIR)
2021-06-28 15:52:16 +08:00
for sc in SConscriptFiles:
dir = os.path.dirname(sc)
build_dir = os.path.join(self.BUILD_DIR, dir)
Script.SConscript(sc, variant_dir=build_dir, duplicate=False)
2020-09-02 16:19:53 +08:00
2023-08-25 17:10:16 +08:00
def get_curr_config(self) :
return compile_config.get_curr_config()
def get_complie_helper_by_script(self, ARGUMENTS, script_path, script_argv) :
global COMPILE_CONFIG
script_path = os.path.abspath(script_path)
if os.path.exists(script_path) :
import importlib
script_dir = os.path.dirname(script_path)
file_name = os.path.basename(script_path)
module_name, ext = os.path.splitext(file_name)
sys.path.insert(0, script_dir)
script = importlib.import_module(module_name)
sys.path.remove(script_dir)
if hasattr(script, SRT_SCONS_CONFIG_FUN) :
return script.get_scons_config(COMPILE_CONFIG, ARGUMENTS, script_argv)
else :
sys.exit(script_path + ' script not found get_res_config function')
else :
sys.exit('res_config_file sopt not found :' + script_path)
2020-08-14 16:43:12 +08:00
def __init__(self, ARGUMENTS):
2023-08-25 17:10:16 +08:00
global COMPILE_CONFIG
global SRT_SCONS_CONFIG_SCRIPT
global SRT_SCONS_CONFIG_SCRIPT_ARGV
if SRT_SCONS_CONFIG_SCRIPT in ARGUMENTS :
self.complie_helper = self.get_complie_helper_by_script(ARGUMENTS, ARGUMENTS[SRT_SCONS_CONFIG_SCRIPT], ARGUMENTS.get(SRT_SCONS_CONFIG_SCRIPT_ARGV, ''))
else :
self.complie_helper = compile_config.complie_helper()
self.complie_helper.set_compile_config(COMPILE_CONFIG)
self.complie_helper.scons_user_sopt(ARGUMENTS)
compile_config.set_curr_config(self.complie_helper)
2024-07-22 17:53:36 +08:00
APP_ROOT = compile_config.get_curr_app_root()
if len(APP_ROOT) == 0:
APP_ROOT = os.path.normpath(os.getcwd())
compile_config.set_curr_app_root(APP_ROOT)
2020-08-14 16:43:12 +08:00
2020-10-13 17:43:19 +08:00
self.SRC_DIR = 'src'
2021-12-02 09:32:06 +08:00
self.TKC_ONLY = getTkcOnly();
2020-09-18 11:31:59 +08:00
self.ARGUMENTS = ARGUMENTS
2020-08-14 16:43:12 +08:00
self.DEF_FILE = None
self.DEF_FILE_PROCESSOR = None
self.DEPENDS_LIBS = []
self.GEN_IDL_DEF = True
self.BUILD_SHARED = True
2023-09-27 18:45:03 +08:00
self.LINUX_FB = self.complie_helper.get_value('LINUX_FB', False)
2020-08-14 16:43:12 +08:00
self.AWTK_ROOT = self.getAwtkRoot()
2020-09-18 11:31:59 +08:00
self.awtk = self.getAwtkConfig()
self.AWTK_LIBS = self.awtk.LIBS
2020-09-28 07:40:57 +08:00
self.AWTK_CFLAGS = self.awtk.CFLAGS
2020-09-18 11:31:59 +08:00
self.AWTK_CCFLAGS = self.awtk.CCFLAGS
self.APP_ROOT = APP_ROOT
2023-11-23 22:12:29 +08:00
self.BUILD_DIR = self.complie_helper.get_value('BUILD_DIR', '')
2021-06-28 15:52:16 +08:00
self.BIN_DIR = os.path.join(self.BUILD_DIR, 'bin')
self.LIB_DIR = os.path.join(self.BUILD_DIR, 'lib')
self.APP_BIN_DIR = os.path.join(APP_ROOT, self.BIN_DIR)
self.APP_LIB_DIR = os.path.join(APP_ROOT, self.LIB_DIR)
2020-08-14 16:43:12 +08:00
self.APP_SRC = os.path.join(APP_ROOT, 'src')
2020-08-17 08:43:23 +08:00
self.APP_RES = os.path.join(APP_ROOT, 'res')
2023-09-27 18:45:03 +08:00
self.APP_LIBS = self.complie_helper.get_value('LIBS', [])
2020-09-18 11:31:59 +08:00
self.APP_LINKFLAGS = ''
2020-10-22 09:02:51 +08:00
self.PLATFORM_LIBS = []
2024-07-19 18:20:35 +08:00
self.APP_TOOLS = ['default']
2021-04-17 21:15:08 +08:00
self.WITH_JERRYSCRIPT = False
2022-02-23 14:37:47 +08:00
self.WITH_IOTJS = False
2021-04-17 21:15:08 +08:00
self.MVVM_ROOT = None
self.AWFLOW_ROOT = None
2024-01-13 17:16:47 +08:00
if hasattr(self.awtk, 'OS_NAME') :
self.OS_NAME = self.awtk.OS_NAME;
else :
self.OS_NAME = None;
2024-01-11 18:04:45 +08:00
self.AWTK_OS_DEBUG = True
if hasattr(self.awtk, 'OS_DEBUG') :
self.AWTK_OS_DEBUG = self.awtk.OS_DEBUG
2023-09-26 17:48:53 +08:00
else :
2024-01-11 18:04:45 +08:00
self.AWTK_OS_DEBUG = self.DEBUG
self.DEBUG = self.complie_helper.get_value('DEBUG', self.AWTK_OS_DEBUG)
if isinstance(self.DEBUG, str) :
2024-01-13 17:16:47 +08:00
try :
from utils import strtobool
self.DEBUG = strtobool(self.DEBUG) == 1
except :
self.DEBUG == self.DEBUG.lower() == 'true';
2023-08-25 17:10:16 +08:00
self.parseArgs(self.awtk, ARGUMENTS)
2023-09-27 18:45:03 +08:00
self.APP_CPPPATH = [self.APP_SRC, self.APP_RES] + self.complie_helper.get_value('CPPPATH', [])
self.APP_LIBPATH = [self.APP_LIB_DIR, self.APP_BIN_DIR] + self.complie_helper.get_value('LIBPATH', [])
2020-09-18 11:31:59 +08:00
2020-11-24 09:28:40 +08:00
mkdir_if_not_exist(self.APP_BIN_DIR)
mkdir_if_not_exist(self.APP_LIB_DIR)
2020-08-14 16:43:12 +08:00
os.environ['APP_SRC'] = self.APP_SRC
os.environ['APP_ROOT'] = self.APP_ROOT
os.environ['BIN_DIR'] = self.APP_BIN_DIR
os.environ['LIB_DIR'] = self.APP_LIB_DIR
2020-09-28 07:40:57 +08:00
os.environ['LINUX_FB'] = 'false'
2021-06-28 15:52:16 +08:00
os.environ['BUILD_DIR'] = self.BUILD_DIR
2020-09-28 07:40:57 +08:00
if self.LINUX_FB:
2020-11-24 09:28:40 +08:00
os.environ['LINUX_FB'] = 'true'
2020-08-14 16:43:12 +08:00
2023-10-11 16:30:49 +08:00
self.WITH_JERRYSCRIPT = self.complie_helper.get_value('WITH_JERRYSCRIPT', False)
2023-09-27 18:45:03 +08:00
self.WITH_IOTJS = self.complie_helper.get_value('WITH_IOTJS', False)
2021-04-17 21:15:08 +08:00
2023-09-27 18:45:03 +08:00
WITH_MVVM = self.complie_helper.get_value('WITH_MVVM', False)
2023-11-23 22:12:29 +08:00
MVVM_ROOT = self.complie_helper.get_value('MVVM_ROOT', '')
2021-04-17 21:15:08 +08:00
if WITH_MVVM or os.path.exists(MVVM_ROOT):
os.environ['WITH_MVVM'] = 'true'
if not os.path.exists(MVVM_ROOT):
MVVM_ROOT = self.getMvvmRoot()
self.MVVM_ROOT = MVVM_ROOT
print("MVVM_ROOT: " + self.MVVM_ROOT)
2023-09-27 18:45:03 +08:00
WITH_AWFLOW = self.complie_helper.get_value('WITH_AWFLOW', False)
2023-11-23 22:12:29 +08:00
AWFLOW_ROOT = self.complie_helper.get_value('AWFLOW_ROOT', '')
2021-04-17 21:15:08 +08:00
print(WITH_AWFLOW)
if WITH_AWFLOW or os.path.exists(AWFLOW_ROOT):
os.environ['WITH_AWFLOW'] = 'true'
if not os.path.exists(AWFLOW_ROOT):
AWFLOW_ROOT = self.getAwflowRoot()
self.AWFLOW_ROOT = AWFLOW_ROOT
print("AWFLOW_ROOT: " + self.AWFLOW_ROOT)
2024-01-06 07:33:14 +08:00
2022-08-17 15:14:44 +08:00
if self.TKC_ONLY :
self.set_tkc_only()
2020-08-14 16:43:12 +08:00
2021-04-17 21:15:08 +08:00
print("AWTK_ROOT: " + self.AWTK_ROOT)
2021-12-02 09:32:06 +08:00
print("TKC_ONLY: " + str(self.TKC_ONLY))
2020-08-14 16:43:12 +08:00
print(ARGUMENTS)
2020-09-18 11:31:59 +08:00
def getAwtkConfig(self):
sys.path.insert(0, self.AWTK_ROOT)
2023-08-25 17:10:16 +08:00
os.chdir(self.AWTK_ROOT)
tmp_complie_helper = compile_config.get_curr_config()
2023-11-23 22:12:29 +08:00
compile_config.set_app_win32_res(tmp_complie_helper.get_value('WIN32_RES', None))
2023-08-25 17:10:16 +08:00
compile_config.set_curr_config(None)
2020-09-18 11:31:59 +08:00
import awtk_config as awtk
2024-07-22 17:53:36 +08:00
os.chdir(compile_config.get_curr_app_root())
2023-08-25 17:10:16 +08:00
compile_config.set_curr_config(tmp_complie_helper)
2020-09-18 11:31:59 +08:00
return awtk
2020-08-14 16:43:12 +08:00
def saveUsesSdkInfo(self):
awtk = self.awtk
release_id = ''
filename = os.path.join(self.AWTK_ROOT, 'component.json')
if os.path.exists(filename):
with open(filename, 'r') as f:
component_content = f.read()
if len(component_content) > 0:
component_json = json.loads(component_content)
if 'release_id' in component_json:
release_id = component_json['release_id']
if sys.version_info < (3, 0):
release_id = release_id.encode('ascii')
content = '{\n'
content += ' "compileSDK": {\n'
content += ' "awtk": {\n'
content += ' "path": "' + \
self.AWTK_ROOT.replace('\\', '/') + '",\n'
content += ' "release_id": "' + release_id + '",\n'
content += ' "nanovg_backend": "' + awtk.NANOVG_BACKEND + '"\n'
content += ' }\n'
content += ' }\n'
content += '}'
filename = os.path.join(self.APP_BIN_DIR, 'uses_sdk.json')
if sys.version_info < (3, 0):
with open(filename, 'w') as f:
f.write(content)
else:
with open(filename, 'w', encoding='utf8') as f:
f.write(content)
def isBuildShared(self):
2021-12-02 09:32:06 +08:00
return self.BUILD_SHARED
2020-08-14 16:43:12 +08:00
def copyAwtkSharedLib(self):
2020-10-21 14:14:56 +08:00
if self.TKC_ONLY:
self.awtk.copySharedLib(self.AWTK_ROOT, self.APP_BIN_DIR, 'tkc')
else:
self.awtk.copySharedLib(self.AWTK_ROOT, self.APP_BIN_DIR, 'awtk')
2020-08-14 16:43:12 +08:00
for iter in self.DEPENDS_LIBS:
for so in iter['shared_libs']:
2024-01-30 11:50:07 +08:00
self.awtk.copySharedLib(join_path(iter['root'], self.BUILD_DIR), self.BIN_DIR, so)
2020-08-14 16:43:12 +08:00
2022-09-20 17:53:32 +08:00
def cleanAwtkSharedLib(self):
if self.TKC_ONLY:
self.awtk.cleanSharedLib(self.APP_BIN_DIR, 'tkc')
else:
self.awtk.cleanSharedLib(self.APP_BIN_DIR, 'awtk')
for iter in self.DEPENDS_LIBS:
for so in iter['shared_libs']:
self.awtk.cleanSharedLib(self.APP_BIN_DIR, so)
2023-09-15 17:59:47 +08:00
shutil.rmtree(self.APP_BIN_DIR);
shutil.rmtree(self.APP_LIB_DIR);
2022-09-20 17:53:32 +08:00
2020-08-14 16:43:12 +08:00
def genIdlAndDef(self):
if self.DEF_FILE:
print(self.DEF_FILE)
else:
return
2022-02-23 14:35:34 +08:00
defDirlist = ''
if self.APP_ROOT != self.AWTK_ROOT:
defDirlist += os.path.abspath(self.AWTK_ROOT + '/tools/idl_gen/idl.json') + ';'
for defLib in self.DEPENDS_LIBS :
tmp_filename = os.path.abspath(defLib["root"] + '/idl/idl.json')
if not os.path.exists(tmp_filename) :
tmp_filename = os.path.abspath(defLib["root"] + '/idl.json')
defDirlist += tmp_filename + ';'
2020-08-14 16:43:12 +08:00
idl_gen_tools = os.path.join(self.AWTK_ROOT, 'tools/idl_gen/index.js')
dll_def_gen_tools = os.path.join(
self.AWTK_ROOT, 'tools/dll_def_gen/index.js')
2020-10-13 17:43:19 +08:00
cmd = 'node ' + '"' + idl_gen_tools + '"' + ' idl/idl.json ' + self.SRC_DIR
2022-02-23 14:35:34 +08:00
if defDirlist != '' :
cmd += ' "' + defDirlist + '" '
2020-08-14 16:43:12 +08:00
if os.system(cmd) != 0:
print('exe cmd: ' + cmd + ' failed.')
cmd = 'node ' + '"' + dll_def_gen_tools + '"' + \
' idl/idl.json ' + self.DEF_FILE
if os.system(cmd) != 0:
print('exe cmd: ' + cmd + ' failed.')
else:
if self.DEF_FILE_PROCESSOR != None:
self.DEF_FILE_PROCESSOR()
def parseArgs(self, awtk, ARGUMENTS):
2020-09-18 11:31:59 +08:00
APP_RES_ROOT = '../res'
APP_THEME = 'default'
2020-08-14 16:43:12 +08:00
LCD_WIDTH = '320'
LCD_HEIGHT = '480'
2022-04-14 11:52:48 +08:00
LCD_ORIENTATION = '0'
2020-08-14 16:43:12 +08:00
APP_DEFAULT_FONT = 'default'
APP_DEFAULT_LANGUAGE = 'zh'
APP_DEFAULT_COUNTRY = 'CN'
2023-07-05 16:59:38 +08:00
2023-08-25 17:10:16 +08:00
config = load_project_json(self.APP_ROOT, 'project.json')
if config != None:
APP_THEME = config.get_res_actived_theme()
LCD_WIDTH = config.get_res_w(APP_THEME)
LCD_HEIGHT = config.get_res_h(APP_THEME)
APP_DEFAULT_LANGUAGE = config.get_res_language()
APP_DEFAULT_COUNTRY = config.get_res_country()
APP_RES_ROOT = config.get_res_res_root()
LCD_ORIENTATION = config.get_res_lcd_orientation(APP_THEME)
2023-11-23 22:12:29 +08:00
LCD = self.complie_helper.get_value('LCD', '')
2020-08-14 16:43:12 +08:00
if len(LCD) > 0:
wh = LCD.split('_')
if len(wh) >= 1:
LCD_WIDTH = wh[0]
if len(wh) >= 2:
LCD_HEIGHT = wh[1]
2023-11-23 22:12:29 +08:00
FONT = self.complie_helper.get_value('FONT', '')
2020-08-14 16:43:12 +08:00
if len(FONT) > 0:
APP_DEFAULT_FONT = FONT
2023-08-25 17:10:16 +08:00
APP_THEME = self.complie_helper.get_value('THEME', APP_THEME)
2020-08-14 16:43:12 +08:00
2023-11-23 22:12:29 +08:00
LANGUAGE = self.complie_helper.get_value('LANGUAGE', '')
2020-08-14 16:43:12 +08:00
if len(LANGUAGE) > 0:
lan = LANGUAGE.split('_')
if len(lan) >= 1:
APP_DEFAULT_LANGUAGE = lan[0]
if len(lan) >= 2:
APP_DEFAULT_COUNTRY = lan[1]
2023-08-25 17:10:16 +08:00
APP_RES_ROOT = self.complie_helper.get_value('RES_ROOT', APP_RES_ROOT)
self.APP_RES = os.path.abspath(os.path.join(self.APP_BIN_DIR, APP_RES_ROOT))
2020-08-14 16:43:12 +08:00
2023-09-27 18:45:03 +08:00
self.BUILD_SHARED = self.complie_helper.get_value('SHARED', False)
self.GEN_IDL_DEF = self.complie_helper.get_value('IDL_DEF', True)
2024-01-06 07:33:14 +08:00
2024-07-31 17:49:13 +08:00
LCD_ORIENTATION = self.complie_helper.get_value('LCD_ORIENTATION', LCD_ORIENTATION)
2023-10-23 12:48:53 +08:00
if not self.LINUX_FB :
if LCD_ORIENTATION == '90' or LCD_ORIENTATION == '270' :
tmp = LCD_WIDTH;
LCD_WIDTH = LCD_HEIGHT;
LCD_HEIGHT = tmp;
2023-07-05 16:59:38 +08:00
2020-08-14 16:43:12 +08:00
APP_CCFLAGS = ' -DLCD_WIDTH=' + LCD_WIDTH + ' -DLCD_HEIGHT=' + LCD_HEIGHT + ' '
APP_CCFLAGS = APP_CCFLAGS + ' -DAPP_DEFAULT_FONT=\\\"' + APP_DEFAULT_FONT + '\\\" '
APP_CCFLAGS = APP_CCFLAGS + ' -DAPP_THEME=\\\"' + APP_THEME + '\\\" '
APP_CCFLAGS = APP_CCFLAGS + ' -DAPP_RES_ROOT=\"\\\"' + APP_RES_ROOT + '\\\"\" '
APP_CCFLAGS = APP_CCFLAGS + ' -DAPP_DEFAULT_LANGUAGE=\\\"' + \
APP_DEFAULT_LANGUAGE + '\\\" '
APP_CCFLAGS = APP_CCFLAGS + ' -DAPP_DEFAULT_COUNTRY=\\\"' + \
APP_DEFAULT_COUNTRY + '\\\" '
APP_CCFLAGS = APP_CCFLAGS + ' -DAPP_ROOT=\"\\\"' + \
2024-09-05 17:28:33 +08:00
self.APP_ROOT.replace('\\', '/') + '\\\"\" '
2023-08-25 17:10:16 +08:00
2023-11-23 22:12:29 +08:00
self.APP_CFLAGS = ''
self.APP_CCFLAGS = APP_CCFLAGS + self.complie_helper.get_value('FLAGS', '')
self.APP_CXXFLAGS = ''
2020-08-14 16:43:12 +08:00
2020-10-22 09:02:51 +08:00
if PLATFORM == 'Linux':
2020-09-18 11:31:59 +08:00
self.APP_LINKFLAGS += ' -Wl,-rpath=' + self.APP_BIN_DIR + ' '
2020-08-14 16:43:12 +08:00
if not self.isBuildShared() and hasattr(awtk, 'AWTK_CCFLAGS'):
2020-09-18 11:31:59 +08:00
self.AWTK_CCFLAGS = awtk.AWTK_CCFLAGS
2020-08-14 16:43:12 +08:00
if self.isBuildShared():
2022-08-17 15:14:44 +08:00
if not self.TKC_ONLY :
self.AWTK_LIBS = awtk.SHARED_LIBS
2020-09-18 11:31:59 +08:00
self.APP_LIBPATH = [self.APP_BIN_DIR, self.APP_LIB_DIR]
2020-08-14 16:43:12 +08:00
2023-01-05 18:05:49 +08:00
if hasattr(awtk, 'TOOLS_NAME') :
if awtk.TOOLS_NAME != '':
if awtk.TOOLS_NAME == 'mingw':
self.APP_TOOLS = ['mingw']
elif awtk.TOOLS_NAME == '' and PLATFORM == 'Windows':
APP_TOOLS = ['msvc', 'masm', 'mslink', "mslib"]
2020-08-14 16:43:12 +08:00
2020-09-18 11:31:59 +08:00
os.environ['BUILD_SHARED'] = str(self.isBuildShared())
2022-04-14 11:52:48 +08:00
if LCD_ORIENTATION == '90' or LCD_ORIENTATION == '270' :
print(LCD_HEIGHT, LCD_WIDTH, "orentation_" + LCD_ORIENTATION)
2022-08-17 15:14:44 +08:00
else :
print(LCD_WIDTH, LCD_HEIGHT, "orentation_" + LCD_ORIENTATION)
2020-09-18 11:31:59 +08:00
2020-08-14 16:43:12 +08:00
def prepare(self):
if self.GEN_IDL_DEF and not self.LINUX_FB:
self.genIdlAndDef()
if self.isBuildShared():
self.copyAwtkSharedLib()
self.saveUsesSdkInfo()
def getAwtkRoot(self):
2020-09-21 18:02:27 +08:00
AWTK_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if self.LINUX_FB:
2021-04-17 21:15:08 +08:00
AWTK_ROOT = os.path.join(os.path.dirname(AWTK_ROOT), 'awtk-linux-fb')
2020-09-21 18:02:27 +08:00
return AWTK_ROOT
2020-08-14 16:43:12 +08:00
2021-04-17 21:15:08 +08:00
def getMvvmRoot(self):
MVVM_ROOT = os.path.join(os.path.dirname(self.getAwtkRoot()), 'awtk-mvvm')
return MVVM_ROOT
def getAwflowRoot(self):
AWFLOW_ROOT = os.path.join(os.path.dirname(self.getAwtkRoot()), 'aw-flow')
return AWFLOW_ROOT
2020-08-14 16:43:12 +08:00
def call(self, DefaultEnvironment):
awtk = self.awtk
CPPPATH = awtk.CPPPATH + self.APP_CPPPATH
LINKFLAGS = awtk.LINKFLAGS + self.APP_LINKFLAGS
2020-12-03 10:04:47 +08:00
LIBS = self.AWTK_LIBS + self.PLATFORM_LIBS
2020-08-14 16:43:12 +08:00
LIBPATH = self.APP_LIBPATH + awtk.LIBPATH
2020-09-28 07:40:57 +08:00
CFLAGS = self.APP_CFLAGS + self.AWTK_CFLAGS
2020-08-14 16:43:12 +08:00
CCFLAGS = self.APP_CCFLAGS + self.AWTK_CCFLAGS
TARGET_ARCH = awtk.TARGET_ARCH
APP_TOOLS = self.APP_TOOLS
CXXFLAGS = self.APP_CXXFLAGS
2021-04-17 21:15:08 +08:00
DEPENDS_LIBS = []
2023-09-22 18:29:45 +08:00
if hasattr(awtk, 'BUILD_DEBUG_FLAG') :
BUILD_DEBUG_FLAG = awtk.BUILD_DEBUG_FLAG
else :
2024-01-13 17:16:47 +08:00
BUILD_DEBUG_FLAG = ' '
2023-08-25 17:10:16 +08:00
self.APP_BIN_DIR = self.complie_helper.get_value('APP_BIN_DIR', os.path.join(self.APP_ROOT, self.BIN_DIR))
self.APP_LIB_DIR = self.complie_helper.get_value('APP_LIB_DIR', os.path.join(self.APP_ROOT, self.LIB_DIR))
2021-04-17 21:15:08 +08:00
if self.MVVM_ROOT:
2022-02-23 14:37:47 +08:00
MVVM_3RD_ROOT = join_path(self.MVVM_ROOT, '3rd')
if self.WITH_IOTJS:
IOTJS_ROOT = os.path.join(MVVM_3RD_ROOT, 'iotjs')
DEPENDS_LIBS += [{
'cxxflags': '-DWITH_MVVM -DWITH_JERRYSCRIPT -DWITH_IOTJS',
'cflags': '-DWITH_MVVM -DWITH_JERRYSCRIPT -DWITH_IOTJS',
'ccflags': '-DWITH_MVVM -DWITH_JERRYSCRIPT -DWITH_IOTJS',
'root' : self.MVVM_ROOT,
'shared_libs': ['mvvm'],
'static_libs': ['']
}]
CPPPATH += [
join_path(IOTJS_ROOT, 'deps/jerry/jerry-ext/include'),
join_path(IOTJS_ROOT, 'deps/jerry/jerry-core/include')
]
elif self.WITH_JERRYSCRIPT:
2021-04-17 21:15:08 +08:00
DEPENDS_LIBS += [{
'cxxflags': '-DWITH_MVVM -DWITH_JERRYSCRIPT',
'cflags': '-DWITH_MVVM -DWITH_JERRYSCRIPT',
'ccflags': '-DWITH_MVVM -DWITH_JERRYSCRIPT',
'root' : self.MVVM_ROOT,
'shared_libs': ['mvvm'],
2021-06-28 15:52:16 +08:00
'static_libs': ['']
2021-04-17 21:15:08 +08:00
}]
2021-10-11 15:31:15 +08:00
CPPPATH += [
join_path(MVVM_3RD_ROOT, 'jerryscript/jerryscript/jerry-ext/include'),
2022-02-23 14:37:47 +08:00
join_path(MVVM_3RD_ROOT, 'jerryscript/jerryscript/jerry-core/include')
2021-10-11 15:31:15 +08:00
]
2021-04-17 21:15:08 +08:00
else:
DEPENDS_LIBS += [{
'cxxflags': '-DWITH_MVVM',
'cflags': '-DWITH_MVVM',
'ccflags': '-DWITH_MVVM',
'root' : self.MVVM_ROOT,
'shared_libs': ['mvvm'],
'static_libs': []
}]
if self.AWFLOW_ROOT:
DEPENDS_LIBS += [{
'cxxflags': '-DWITH_AWFLOW',
'cflags': '-DWITH_AWFLOW',
'ccflags': '-DWITH_AWFLOW',
'root' : self.AWFLOW_ROOT,
'shared_libs': ['awflow'],
'static_libs': []
}]
if self.isBuildShared():
src = join_path(self.AWFLOW_ROOT, 'bin/nodes')
dst = join_path(self.APP_ROOT, 'bin/nodes')
if os.path.exists(dst):
shutil.rmtree(dst)
print(src + '==>' + dst)
shutil.copytree(src, dst)
self.DEPENDS_LIBS = DEPENDS_LIBS + self.DEPENDS_LIBS
2023-06-09 18:07:31 +08:00
for depend in self.DEPENDS_LIBS:
self.check_and_remove_scons_db(depend['root'])
self.check_and_remove_scons_db(self.APP_ROOT)
2020-08-14 16:43:12 +08:00
if self.TKC_ONLY:
CCFLAGS += ' -DTKC_ONLY=1 '
2020-10-31 17:38:09 +08:00
else:
CCFLAGS += ' -DWITH_AWTK=1 '
2020-08-14 16:43:12 +08:00
for iter in self.DEPENDS_LIBS:
if 'shared_libs' in iter:
2020-08-18 15:22:36 +08:00
LIBS = iter['shared_libs'] + LIBS
2020-08-14 16:43:12 +08:00
if 'static_libs' in iter:
2020-08-18 15:22:36 +08:00
LIBS = iter['static_libs'] + LIBS
2020-11-24 09:28:40 +08:00
if 'cxxflags' in iter:
CXXFLAGS += " " + iter['cxxflags'] + " "
if 'cflags' in iter:
CFLAGS += " " + iter['cflags'] + " "
if 'ccflags' in iter:
CCFLAGS += " " + iter['ccflags'] + " "
if 'cpppath' in iter:
for f in iter['cpppath']:
CPPPATH = CPPPATH + [join_path(iter['root'], f)]
else:
CPPPATH += [join_path(iter['root'], 'src')]
if 'libpath' in iter:
for f in iter['libpath']:
LIBPATH = LIBPATH + [join_path(iter['root'], f)]
else:
2021-04-17 21:15:08 +08:00
if self.isBuildShared():
2024-01-30 11:50:07 +08:00
LIBPATH += [join_path(iter['root'], self.BIN_DIR)]
LIBPATH += [join_path(iter['root'], self.LIB_DIR)]
2020-12-03 10:04:47 +08:00
LIBS = self.APP_LIBS + LIBS
2020-08-14 16:43:12 +08:00
if hasattr(awtk, 'CC'):
2024-01-11 18:04:45 +08:00
if self.DEBUG :
CCFLAGS += ' -g -O0 '
2023-08-25 17:10:16 +08:00
else :
2024-01-11 18:04:45 +08:00
CCFLAGS += ' -Os '
if self.DEBUG == self.AWTK_OS_DEBUG:
2023-09-22 18:29:45 +08:00
CCFLAGS += BUILD_DEBUG_FLAG
2023-09-26 17:48:53 +08:00
2021-06-28 15:52:16 +08:00
env = DefaultEnvironment(
2022-08-17 16:13:36 +08:00
ENV = os.environ,
2020-08-14 16:43:12 +08:00
CC=awtk.CC,
CXX=awtk.CXX,
LD=awtk.LD,
AR=awtk.AR,
STRIP=awtk.STRIP,
2020-11-04 08:46:56 +08:00
RANLIB=awtk.RANLIB,
2020-08-14 16:43:12 +08:00
TOOLS=APP_TOOLS,
CPPPATH=CPPPATH,
LINKFLAGS=LINKFLAGS,
LIBS=LIBS,
LIBPATH=LIBPATH,
CCFLAGS=CCFLAGS,
2020-09-28 07:40:57 +08:00
CFLAGS=CFLAGS,
2020-08-14 16:43:12 +08:00
CXXFLAGS=CXXFLAGS,
2023-08-25 17:10:16 +08:00
TARGET_ARCH=TARGET_ARCH,
2020-08-14 16:43:12 +08:00
OS_SUBSYSTEM_CONSOLE=awtk.OS_SUBSYSTEM_CONSOLE,
OS_SUBSYSTEM_WINDOWS=awtk.OS_SUBSYSTEM_WINDOWS)
else:
2024-01-15 17:55:40 +08:00
is_msvc = True;
if hasattr(awtk, 'TOOLS_NAME') :
if awtk.TOOLS_NAME != '':
is_msvc = False
2024-01-11 18:04:45 +08:00
if self.DEBUG :
2024-01-15 17:55:40 +08:00
if self.OS_NAME == 'Windows' and is_msvc:
2024-01-13 17:16:47 +08:00
CCFLAGS += ' -D_DEBUG -DDEBUG /DEBUG /MDd /Od '
elif self.OS_NAME == 'Darwin' or self.OS_NAME == 'Linux' :
CCFLAGS += ' -g -O0 '
2023-08-25 17:10:16 +08:00
else :
2024-01-15 17:55:40 +08:00
if self.OS_NAME == 'Windows' and is_msvc:
2024-01-13 17:16:47 +08:00
CCFLAGS += ' -DNDEBUG /MD /O2 /Oi '
elif self.OS_NAME == 'Darwin' or self.OS_NAME == 'Linux' :
CCFLAGS += ' -Os '
2024-01-11 18:04:45 +08:00
2024-01-15 17:55:40 +08:00
if self.OS_NAME == 'Windows' and is_msvc and self.complie_helper.get_value('PDB', True) :
2024-01-11 18:04:45 +08:00
LINKFLAGS += ' /DEBUG '
if self.DEBUG == self.AWTK_OS_DEBUG:
2023-09-22 18:29:45 +08:00
CCFLAGS += BUILD_DEBUG_FLAG
2023-08-25 17:10:16 +08:00
LINKFLAGS += awtk.BUILD_DEBUG_LINKFLAGS
2021-06-28 15:52:16 +08:00
env = DefaultEnvironment(
2020-08-14 16:43:12 +08:00
TOOLS=APP_TOOLS,
CPPPATH=CPPPATH,
LINKFLAGS=LINKFLAGS,
LIBS=LIBS,
LIBPATH=LIBPATH,
2020-09-28 07:40:57 +08:00
CFLAGS=CFLAGS,
2020-08-14 16:43:12 +08:00
CCFLAGS=CCFLAGS,
CXXFLAGS=CXXFLAGS,
2023-08-25 17:10:16 +08:00
TARGET_ARCH=TARGET_ARCH,
2020-08-14 16:43:12 +08:00
OS_SUBSYSTEM_CONSOLE=awtk.OS_SUBSYSTEM_CONSOLE,
OS_SUBSYSTEM_WINDOWS=awtk.OS_SUBSYSTEM_WINDOWS)
2024-01-06 07:33:14 +08:00
2021-06-28 15:52:16 +08:00
def variant_SConscript(env, SConscriptFiles):
self.SConscript(SConscriptFiles)
env.AddMethod(variant_SConscript, "SConscript")
2024-01-06 07:33:14 +08:00
2022-05-25 15:50:39 +08:00
if not Script.GetOption('clean'):
self.prepare()
2022-09-20 17:53:32 +08:00
else:
self.cleanAwtkSharedLib()
2022-05-25 15:50:39 +08:00
2021-06-28 15:52:16 +08:00
return env