Compare commits
12 Commits
v0.1.0-dev
...
master
Author | SHA1 | Date | |
---|---|---|---|
f5cd8f27f3 | |||
573c32cd65 | |||
88c25c6077 | |||
36da572a87 | |||
0209016824 | |||
dc09f8fd99 | |||
6923e908e8 | |||
a2651f7fb1 | |||
2223c96ba2 | |||
b259cb77f7 | |||
ea9ef7c75a | |||
33f7ad547f |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,4 @@
|
||||
*.pyc
|
||||
*.o
|
||||
kconfig-frontends/.sconsign.dblite
|
||||
kconfig-frontends/kconfig-mconf
|
||||
|
55
building.py
55
building.py
@@ -24,6 +24,7 @@
|
||||
# group definition.
|
||||
#
|
||||
|
||||
from math import fabs
|
||||
import os
|
||||
import sys
|
||||
import string
|
||||
@@ -143,13 +144,14 @@ def GenCconfigFile(env, BuildOptions):
|
||||
# add HAVE_CCONFIG_H definition
|
||||
env.AppendUnique(CPPDEFINES = ['HAVE_CCONFIG_H'])
|
||||
|
||||
def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [], rtt_cfg = 'rtconfig.h'):
|
||||
def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [], rtt_cfg = 'rtconfig.h', rtt_tools = ''):
|
||||
import rtconfig
|
||||
|
||||
global BuildOptions
|
||||
global Projects
|
||||
global Env
|
||||
global Rtt_Root
|
||||
global Rtt_Tool
|
||||
|
||||
# ===== Add option to SCons =====
|
||||
AddOption('--dist',
|
||||
@@ -241,7 +243,12 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
||||
# set BSP_ROOT in ENV
|
||||
Env['BSP_ROOT'] = Dir('#').abspath
|
||||
|
||||
sys.path = sys.path + [os.path.join(Rtt_Root, 'tools')]
|
||||
if rtt_tools == '':
|
||||
Rtt_Tool = os.path.join(Rtt_Root, '..', 'rtt_tools')
|
||||
else:
|
||||
Rtt_Tool = rtt_tools
|
||||
|
||||
sys.path = sys.path + [Rtt_Tool]
|
||||
|
||||
# {target_name:(CROSS_TOOL, PLATFORM)}
|
||||
tgt_dict = {'mdk':('keil', 'armcc'),
|
||||
@@ -329,9 +336,12 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
||||
|
||||
# parse rtconfig.h to get used component
|
||||
PreProcessor = PatchedPreProcessor()
|
||||
f = open(rtt_cfg, 'r')
|
||||
contents = f.read()
|
||||
f.close()
|
||||
contents = ''
|
||||
if os.path.isfile(rtt_cfg):
|
||||
f = open(rtt_cfg, 'r')
|
||||
contents = f.read()
|
||||
f.close()
|
||||
|
||||
PreProcessor.process_contents(contents)
|
||||
BuildOptions = PreProcessor.cpp_namespace
|
||||
|
||||
@@ -379,7 +389,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
||||
help = 'make menuconfig for RT-Thread BSP')
|
||||
if GetOption('menuconfig'):
|
||||
from menuconfig import menuconfig
|
||||
menuconfig(Rtt_Root)
|
||||
menuconfig(Rtt_Tool, rtt_cfg)
|
||||
exit(0)
|
||||
|
||||
AddOption('--pyconfig',
|
||||
@@ -396,18 +406,18 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
||||
if GetOption('pyconfig_silent'):
|
||||
from menuconfig import guiconfig_silent
|
||||
|
||||
guiconfig_silent(Rtt_Root)
|
||||
guiconfig_silent(Rtt_Tool, rtt_cfg)
|
||||
exit(0)
|
||||
elif GetOption('pyconfig'):
|
||||
from menuconfig import guiconfig
|
||||
|
||||
guiconfig(Rtt_Root)
|
||||
guiconfig(Rtt_Tool, rtt_cfg)
|
||||
exit(0)
|
||||
|
||||
configfn = GetOption('useconfig')
|
||||
if configfn:
|
||||
from menuconfig import mk_rtconfig
|
||||
mk_rtconfig(configfn)
|
||||
mk_rtconfig(configfn, rtt_cfg)
|
||||
exit(0)
|
||||
|
||||
|
||||
@@ -709,16 +719,20 @@ def GroupLibFullName(name, env):
|
||||
return env['LIBPREFIX'] + name + env['LIBSUFFIX']
|
||||
|
||||
def BuildLibInstallAction(target, source, env):
|
||||
import rtconfig
|
||||
lib_name = GetOption('buildlib')
|
||||
for Group in Projects:
|
||||
if Group['name'] == lib_name:
|
||||
lib_name = GroupLibFullName(Group['name'], env)
|
||||
dst_name = os.path.join(Group['path'], lib_name)
|
||||
dst_name = os.path.join(rtconfig.SHARE_LIB_PATH, Group['name'], lib_name)
|
||||
print('Copy '+lib_name+' => ' + dst_name)
|
||||
do_copy_file(lib_name, dst_name)
|
||||
break
|
||||
|
||||
def DoBuilding(target, objects, is_rtt = False):
|
||||
def DoBuildingLib(lib, objects):
|
||||
DoBuilding(lib, objects, build_lib=True)
|
||||
|
||||
def DoBuilding(target, objects, is_rtt = False, build_lib = False):
|
||||
|
||||
# merge all objects into one list
|
||||
def one_list(l):
|
||||
@@ -751,6 +765,7 @@ def DoBuilding(target, objects, is_rtt = False):
|
||||
program = None
|
||||
# check whether special buildlib option
|
||||
lib_name = GetOption('buildlib')
|
||||
|
||||
if lib_name:
|
||||
objects = [] # remove all of objects
|
||||
# build library with special component
|
||||
@@ -777,12 +792,18 @@ def DoBuilding(target, objects, is_rtt = False):
|
||||
# re-add the source files to the objects
|
||||
for group in Projects:
|
||||
local_group(group, objects)
|
||||
|
||||
program = Env.Program(target, objects)
|
||||
|
||||
if build_lib:
|
||||
program = Env.Library(target, objects)
|
||||
# add library copy action
|
||||
Env.BuildLib(target, program)
|
||||
else:
|
||||
program = Env.Program(target, objects)
|
||||
|
||||
EndBuilding(target, program, is_rtt)
|
||||
|
||||
def GenTargetProject(program = None):
|
||||
need_exit = True
|
||||
|
||||
if GetOption('target') == 'mdk':
|
||||
from keil import MDKProject
|
||||
@@ -858,6 +879,8 @@ def GenTargetProject(program = None):
|
||||
if GetOption('target') == 'cmake' or GetOption('target') == 'cmake-armclang':
|
||||
from cmake import CMakeProject
|
||||
CMakeProject(Env,Projects)
|
||||
|
||||
return need_exit
|
||||
|
||||
|
||||
def EndBuilding(target, program = None, is_rtt = False):
|
||||
@@ -880,11 +903,11 @@ def EndBuilding(target, program = None, is_rtt = False):
|
||||
Clean(target, 'rtua.py')
|
||||
Clean(target, 'rtua.pyc')
|
||||
if is_rtt:
|
||||
Clean(target, 'gen_ports/gen_ports.c')
|
||||
Clean(target, 'gen_ports/gen_ports.cpp')
|
||||
Clean(target, 'gen_ports/gen_ports_c.c')
|
||||
Clean(target, 'gen_ports/gen_ports_cpp.cpp')
|
||||
|
||||
if GetOption('target'):
|
||||
GenTargetProject(program)
|
||||
need_exit = GenTargetProject(program)
|
||||
|
||||
BSP_ROOT = Dir('#').abspath
|
||||
if GetOption('make-dist') and program != None:
|
||||
|
18
examples/ShareLibRootSconscript
Normal file
18
examples/ShareLibRootSconscript
Normal file
@@ -0,0 +1,18 @@
|
||||
# for package compiling
|
||||
import os
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
CPPPATH = [cwd]
|
||||
Import('SHARE_LIB_HANDLE')
|
||||
|
||||
for d in list:
|
||||
if SHARE_LIB_HANDLE.is_this_lib(d):
|
||||
continue
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(d, 'SConscript'))
|
||||
|
||||
Return('objs')
|
@@ -40,14 +40,14 @@ def is_pkg_special_config(config_str):
|
||||
return True
|
||||
return False
|
||||
|
||||
def mk_rtconfig(filename):
|
||||
def mk_rtconfig(filename, cfg_head = 'rtconfig.h'):
|
||||
try:
|
||||
config = open(filename, 'r')
|
||||
except:
|
||||
print('open config:%s failed' % filename)
|
||||
return
|
||||
|
||||
rtconfig = open('rtconfig.h', 'w')
|
||||
rtconfig = open(cfg_head, 'w')
|
||||
rtconfig.write('#ifndef RT_CONFIG_H__\n')
|
||||
rtconfig.write('#define RT_CONFIG_H__\n\n')
|
||||
|
||||
@@ -233,12 +233,12 @@ def exclude_utestcases(RTT_ROOT):
|
||||
f.write(line)
|
||||
|
||||
# menuconfig for Linux
|
||||
def menuconfig(RTT_ROOT):
|
||||
def menuconfig(RTT_TOOLS, cfg_head):
|
||||
|
||||
# Exclude utestcases
|
||||
exclude_utestcases(RTT_ROOT)
|
||||
exclude_utestcases(RTT_TOOLS)
|
||||
|
||||
kconfig_dir = os.path.join(RTT_ROOT, 'tools', 'kconfig-frontends')
|
||||
kconfig_dir = os.path.join(RTT_TOOLS, 'kconfig-frontends')
|
||||
os.system('scons -C ' + kconfig_dir)
|
||||
|
||||
touch_env()
|
||||
@@ -249,7 +249,7 @@ def menuconfig(RTT_ROOT):
|
||||
fn = '.config'
|
||||
fn_old = '.config.old'
|
||||
|
||||
kconfig_cmd = os.path.join(RTT_ROOT, 'tools', 'kconfig-frontends', 'kconfig-mconf')
|
||||
kconfig_cmd = os.path.join(RTT_TOOLS, 'kconfig-frontends', 'kconfig-mconf')
|
||||
os.system(kconfig_cmd + ' Kconfig')
|
||||
|
||||
if os.path.isfile(fn):
|
||||
@@ -263,14 +263,14 @@ def menuconfig(RTT_ROOT):
|
||||
# make rtconfig.h
|
||||
if diff_eq == False:
|
||||
shutil.copyfile(fn, fn_old)
|
||||
mk_rtconfig(fn)
|
||||
mk_rtconfig(fn, cfg_head)
|
||||
|
||||
# guiconfig for windows and linux
|
||||
def guiconfig(RTT_ROOT):
|
||||
def guiconfig(RTT_TOOLS, cfg_head):
|
||||
import pyguiconfig
|
||||
|
||||
# Exclude utestcases
|
||||
exclude_utestcases(RTT_ROOT)
|
||||
exclude_utestcases(RTT_TOOLS)
|
||||
|
||||
if sys.platform != 'win32':
|
||||
touch_env()
|
||||
@@ -296,15 +296,15 @@ def guiconfig(RTT_ROOT):
|
||||
# make rtconfig.h
|
||||
if diff_eq == False:
|
||||
shutil.copyfile(fn, fn_old)
|
||||
mk_rtconfig(fn)
|
||||
mk_rtconfig(fn, cfg_head)
|
||||
|
||||
|
||||
# guiconfig for windows and linux
|
||||
def guiconfig_silent(RTT_ROOT):
|
||||
def guiconfig_silent(RTT_TOOLS, cfg_head):
|
||||
import defconfig
|
||||
|
||||
# Exclude utestcases
|
||||
exclude_utestcases(RTT_ROOT)
|
||||
exclude_utestcases(RTT_TOOLS)
|
||||
|
||||
if sys.platform != 'win32':
|
||||
touch_env()
|
||||
@@ -319,4 +319,4 @@ def guiconfig_silent(RTT_ROOT):
|
||||
defconfig.main()
|
||||
|
||||
# silent mode, force to make rtconfig.h
|
||||
mk_rtconfig(fn)
|
||||
mk_rtconfig(fn, cfg_head)
|
||||
|
@@ -137,6 +137,9 @@ class Folder(object):
|
||||
body_li = []
|
||||
payload_li = []
|
||||
for c in self._children:
|
||||
if c.name == '.gitkeep':
|
||||
continue
|
||||
|
||||
entry_size = c.entry_size
|
||||
if isinstance(c, File):
|
||||
tp = 'ROMFS_DIRENT_FILE'
|
||||
|
86
sharelib.py
86
sharelib.py
@@ -24,6 +24,28 @@ Return('group')
|
||||
|
||||
'''
|
||||
|
||||
SharelibMainSconscript = '''
|
||||
# for package compiling
|
||||
import os
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
CPPPATH = [cwd]
|
||||
Import('SHARE_LIB_HANDLE')
|
||||
|
||||
for d in list:
|
||||
if SHARE_LIB_HANDLE.is_this_lib(d):
|
||||
continue
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(d, 'SConscript'))
|
||||
|
||||
Return('objs')
|
||||
|
||||
'''
|
||||
|
||||
class SharelibItem:
|
||||
'''
|
||||
share lib handler
|
||||
@@ -48,19 +70,7 @@ class SharelibHandler:
|
||||
def __export_lib(self, dist_path, path, libs):
|
||||
|
||||
for lib in libs:
|
||||
libFile = path +'/lib' + lib + '.a'
|
||||
libExist = False
|
||||
if os.path.isfile(libFile):
|
||||
shutil.copy(libFile, dist_path)
|
||||
libExist = True
|
||||
|
||||
libFile = path +'/lib' + lib + '.lib'
|
||||
if os.path.isfile(libFile):
|
||||
shutil.copy(libFile, dist_path)
|
||||
libExist = True
|
||||
|
||||
if libExist:
|
||||
self._LIB_LIST.append(lib)
|
||||
self._LIB_LIST.append(lib)
|
||||
|
||||
def __export_headers(self, dist_path, group, path, headers, all, need_path = True):
|
||||
dst = os.path.join(dist_path, group)
|
||||
@@ -128,14 +138,11 @@ class SharelibHandler:
|
||||
kcfg.writelines(['endmenu\n'])
|
||||
kcfg.close()
|
||||
|
||||
def __gen_ports(self, share_lib_path):
|
||||
if self._lib_name != "rt-thread":
|
||||
return False
|
||||
|
||||
def gen_ports(self, share_lib_path):
|
||||
import json
|
||||
|
||||
init_c_path = os.path.join(os.getcwd(), "gen_ports/gen_ports.c")
|
||||
init_cpp_path = init_c_path + "pp"
|
||||
init_c_path = os.path.join(os.getcwd(), "gen_ports", "gen_ports_c.c")
|
||||
init_cpp_path = os.path.join(os.getcwd(), "gen_ports", "gen_ports_cpp.cpp")
|
||||
|
||||
finit_c = open(init_c_path, 'w+')
|
||||
finit_cpp = open(init_cpp_path, 'w+')
|
||||
@@ -144,7 +151,7 @@ class SharelibHandler:
|
||||
exit(1)
|
||||
|
||||
file_head = ['/**\n',
|
||||
' * @file: gen_ports.c/cpp\n',
|
||||
' * @file: gen_ports_c.c/_cpp.cpp\n',
|
||||
' * \n',
|
||||
' * @warn: auto generated init ports file; DO NOT EDIT.',
|
||||
' */\n\n',
|
||||
@@ -187,13 +194,39 @@ class SharelibHandler:
|
||||
|
||||
finit_c.close()
|
||||
finit_cpp.close()
|
||||
def __init_sconscipt(self, share_lib_path):
|
||||
|
||||
port_file = os.path.join(share_lib_path, "SConscript")
|
||||
if os.path.isfile(port_file):
|
||||
return False
|
||||
|
||||
with open(port_file, 'w+') as pf:
|
||||
pf.write(SharelibMainSconscript)
|
||||
|
||||
def export(self, share_lib_path, gen_ports = False):
|
||||
reserved_subdir = ['.git',
|
||||
'README.md', '.gitignore', '.gitmodules', '.gitattributes',
|
||||
'.drone.yml']
|
||||
|
||||
self.__init_sconscipt(share_lib_path)
|
||||
|
||||
def export(self, share_lib_path):
|
||||
dist_path = share_lib_path + '/' + self._lib_name
|
||||
if os.path.exists(dist_path):
|
||||
shutil.rmtree(dist_path)
|
||||
for d in os.listdir(dist_path):
|
||||
if d in reserved_subdir:
|
||||
continue
|
||||
|
||||
os.mkdir(dist_path)
|
||||
if d.endswith('.a') or d.endswith('.lib'):
|
||||
continue
|
||||
|
||||
pth = os.path.join(dist_path, d)
|
||||
if os.path.isfile(pth):
|
||||
os.remove(pth)
|
||||
continue
|
||||
|
||||
shutil.rmtree(pth)
|
||||
|
||||
print("dist_path: " + dist_path)
|
||||
|
||||
for item in self._items:
|
||||
if item._group == '':
|
||||
@@ -233,9 +266,10 @@ class SharelibHandler:
|
||||
'lib_name': self._lib_name}
|
||||
import json
|
||||
with open(dist_path + '/package.json','w+') as f:
|
||||
json.dump(data,f)
|
||||
|
||||
self.__gen_ports(share_lib_path)
|
||||
json.dump(data,f, sort_keys=True, indent=4, separators=(',', ': '))
|
||||
|
||||
if gen_ports:
|
||||
self.gen_ports(share_lib_path)
|
||||
|
||||
self.update_sharelib(share_lib_path)
|
||||
|
||||
|
Reference in New Issue
Block a user