未验证 提交 acfb1c16 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #1634 from liangyongxiang/dist

[tools] rewrite "scons --dist/copy/copy-header"
...@@ -89,116 +89,65 @@ def walk_kconfig(RTT_ROOT, source_list): ...@@ -89,116 +89,65 @@ def walk_kconfig(RTT_ROOT, source_list):
pathfile = os.path.join(parent, 'KConfig') pathfile = os.path.join(parent, 'KConfig')
source_list.append(pathfile) source_list.append(pathfile)
def MakeCopy(program, BSP_ROOT, RTT_ROOT, Env): def bsp_update_sconstruct(dist_dir):
global source_list with open(os.path.join(dist_dir, 'SConstruct'), "r") as f:
data = f.readlines()
target_path = os.path.join(BSP_ROOT, 'rt-thread') with open(os.path.join(dist_dir, 'SConstruct'), "w") as f:
for line in data:
if target_path.startswith(RTT_ROOT): if line.find('RTT_ROOT') != -1:
print('please use scons --copy to copy rt-thread to local bsp') if line.find('sys.path') != -1:
return f.write('# set RTT_ROOT\n')
f.write("if not os.getenv('RTT_ROOT'): \n RTT_ROOT='rt-thread'\n\n")
for item in program: f.write(line)
walk_children(item)
source_list.sort()
# fill source file in RT-Thread
target_list = []
for src in source_list:
if Env['PLATFORM'] == 'win32':
src = src.lower()
if src.startswith(RTT_ROOT):
target_list.append(src)
source_list = target_list
# get source directory
src_dir = []
for src in source_list:
src = src.replace(RTT_ROOT, '')
if src[0] == os.sep or src[0] == '/':
src = src[1:]
path = os.path.dirname(src)
sub_path = path.split(os.sep)
full_path = RTT_ROOT
for item in sub_path:
full_path = os.path.join(full_path, item)
if full_path not in src_dir:
src_dir.append(full_path)
for item in src_dir:
source_list.append(os.path.join(item, 'SConscript'))
walk_kconfig(RTT_ROOT, source_list)
for src in source_list:
dst = src.replace(RTT_ROOT, '')
if dst[0] == os.sep or dst[0] == '/':
dst = dst[1:]
print '=> ', dst
dst = os.path.join(target_path, dst)
do_copy_file(src, dst)
# copy tools directory
print("=> tools")
do_copy_folder(os.path.join(RTT_ROOT, "tools"), os.path.join(target_path, "tools"), ignore_patterns('*.pyc'))
do_copy_file(os.path.join(RTT_ROOT, 'Kconfig'), os.path.join(target_path, 'Kconfig'))
do_copy_file(os.path.join(RTT_ROOT, 'AUTHORS'), os.path.join(target_path, 'AUTHORS'))
do_copy_file(os.path.join(RTT_ROOT, 'COPYING'), os.path.join(target_path, 'COPYING'))
do_copy_file(os.path.join(RTT_ROOT, 'README.md'), os.path.join(target_path, 'README.md'))
do_copy_file(os.path.join(RTT_ROOT, 'README_zh.md'), os.path.join(target_path, 'README_zh.md'))
print('=> libc')
do_copy_folder(os.path.join(RTT_ROOT, "components", 'libc', 'compilers'), os.path.join(target_path, "components", 'libc', 'compilers'))
print('done!')
def MakeCopyHeader(program, BSP_ROOT, RTT_ROOT, Env):
global source_list
global source_ext
source_ext = []
source_ext = ["h", "xpm"]
target_path = os.path.join(BSP_ROOT, 'rt-thread')
if target_path.startswith(RTT_ROOT):
print('please use scons --copy-header to copy header files only')
return
for item in program:
walk_children(item)
source_list.sort()
# fill source file in RT-Thread
target_list = []
for src in source_list:
if Env['PLATFORM'] == 'win32':
src = src.lower()
if src.startswith(RTT_ROOT):
target_list.append(src)
source_list = target_list def bsp_update_kconfig(dist_dir):
# change RTT_ROOT in Kconfig
with open(os.path.join(dist_dir, 'Kconfig'), "r") as f:
data = f.readlines()
with open(os.path.join(dist_dir, 'Kconfig'), "w") as f:
found = 0
for line in data:
if line.find('RTT_ROOT') != -1:
found = 1
if line.find('default') != -1 and found:
position = line.find('default')
line = line[0:position] + 'default: "rt-thread"\n'
found = 0
f.write(line)
def bs_update_ide_project(bsp_root, rtt_root):
import subprocess
# default update the projects which have template file
tgt_dict = {'mdk4':('keil', 'armcc'),
'mdk5':('keil', 'armcc'),
'iar':('iar', 'iar'),
'vs':('msvc', 'cl'),
'vs2012':('msvc', 'cl'),
'cdk':('gcc', 'gcc')}
scons_env = os.environ.copy()
scons_env["RTT_ROOT"] = rtt_root
for item in tgt_dict:
child = subprocess.Popen('scons --target=' + item, cwd=bsp_root, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, stderr = child.communicate()
if child.returncode == 0:
print("update %s project" % item)
def zip_dist(bsp_root, dist_dir, dist_name):
import zipfile
for src in source_list: zip_filename = os.path.join(bsp_root, 'dist', dist_name)
dst = src.replace(RTT_ROOT, '') zip = zipfile.ZipFile(zip_filename + ".zip", 'w')
if dst[0] == os.sep or dst[0] == '/': pre_len = len(os.path.dirname(dist_dir))
dst = dst[1:]
print '=> ', dst
dst = os.path.join(target_path, dst)
do_copy_file(src, dst)
# copy tools directory for parent, dirnames, filenames in os.walk(dist_dir):
print "=> tools" for filename in filenames:
do_copy_folder(os.path.join(RTT_ROOT, "tools"), os.path.join(target_path, "tools"), ignore_patterns('*.pyc')) pathfile = os.path.join(parent, filename)
do_copy_file(os.path.join(RTT_ROOT, 'Kconfig'), os.path.join(target_path, 'Kconfig')) arcname = pathfile[pre_len:].strip(os.path.sep)
do_copy_file(os.path.join(RTT_ROOT, 'AUTHORS'), os.path.join(target_path, 'AUTHORS')) zip.write(pathfile, arcname)
do_copy_file(os.path.join(RTT_ROOT, 'COPYING'), os.path.join(target_path, 'COPYING'))
do_copy_file(os.path.join(RTT_ROOT, 'README.md'), os.path.join(target_path, 'README.md'))
do_copy_file(os.path.join(RTT_ROOT, 'README_zh.md'), os.path.join(target_path, 'README_zh.md'))
print('done!') zip.close()
def MkDist(program, BSP_ROOT, RTT_ROOT, Env): def MkDist(program, BSP_ROOT, RTT_ROOT, Env):
print("make distribution....") print("make distribution....")
...@@ -206,122 +155,53 @@ def MkDist(program, BSP_ROOT, RTT_ROOT, Env): ...@@ -206,122 +155,53 @@ def MkDist(program, BSP_ROOT, RTT_ROOT, Env):
dist_name = os.path.basename(BSP_ROOT) dist_name = os.path.basename(BSP_ROOT)
dist_dir = os.path.join(BSP_ROOT, 'dist', dist_name) dist_dir = os.path.join(BSP_ROOT, 'dist', dist_name)
target_path = os.path.join(dist_dir, 'rt-thread')
# copy BSP files # copy BSP files
print("=> %s" % os.path.basename(BSP_ROOT))
do_copy_folder(os.path.join(BSP_ROOT), dist_dir, do_copy_folder(os.path.join(BSP_ROOT), dist_dir,
ignore_patterns('build', 'dist', '*.pyc', '*.old', '*.map', 'rtthread.bin', '.sconsign.dblite', '*.elf', '*.axf', 'cconfig.h')) ignore_patterns('build', 'dist', '*.pyc', '*.old', '*.map', 'rtthread.bin', '.sconsign.dblite', '*.elf', '*.axf', 'cconfig.h'))
global source_list # copy tools directory
print("=> components")
do_copy_folder(os.path.join(RTT_ROOT, "components"), os.path.join(target_path, "components"))
target_path = os.path.join(dist_dir, 'rt-thread') # skip documentation directory
# skip examples
for item in program: # copy include directory
walk_children(item) print("=> include")
do_copy_folder(os.path.join(RTT_ROOT, "include"), os.path.join(target_path, "include"))
source_list.sort() # copy all libcpu/ARCH directory
print('=> libcpu')
import rtconfig
do_copy_folder(os.path.join(RTT_ROOT, 'libcpu', rtconfig.ARCH), os.path.join(target_path, 'libcpu', rtconfig.ARCH))
do_copy_file(os.path.join(RTT_ROOT, 'libcpu', 'Kconfig'), os.path.join(target_path, 'libcpu', 'Kconfig'))
do_copy_file(os.path.join(RTT_ROOT, 'libcpu', 'SConscript'), os.path.join(target_path, 'libcpu', 'SConscript'))
# copy the source files in RT-Thread # copy src directory
target_list = [] print("=> src")
for src in source_list: do_copy_folder(os.path.join(RTT_ROOT, "src"), os.path.join(target_path, "src"))
if src.lower().startswith(BSP_ROOT.lower()):
continue
if src.lower().startswith(RTT_ROOT.lower()):
target_list.append(src)
source_list = target_list
# get source directory
src_dir = []
for src in source_list:
src = src.replace(RTT_ROOT, '')
if src[0] == os.sep or src[0] == '/':
src = src[1:]
path = os.path.dirname(src)
sub_path = path.split(os.sep)
full_path = RTT_ROOT
for item in sub_path:
full_path = os.path.join(full_path, item)
if full_path not in src_dir:
src_dir.append(full_path)
for item in src_dir:
source_list.append(os.path.join(item, 'SConscript'))
# add all of Kconfig files
walk_kconfig(RTT_ROOT, source_list)
source_list.sort()
for src in source_list:
dst = src.replace(RTT_ROOT, '')
if dst[0] == os.sep or dst[0] == '/':
dst = dst[1:]
print('=> %s' % dst)
dst = os.path.join(target_path, dst)
do_copy_file(src, dst)
# copy tools directory # copy tools directory
print("=> tools") print("=> tools")
do_copy_folder(os.path.join(RTT_ROOT, "tools"), os.path.join(target_path, "tools"), ignore_patterns('*.pyc')) do_copy_folder(os.path.join(RTT_ROOT, "tools"), os.path.join(target_path, "tools"), ignore_patterns('*.pyc'))
do_copy_file(os.path.join(RTT_ROOT, 'Kconfig'), os.path.join(target_path, 'Kconfig')) do_copy_file(os.path.join(RTT_ROOT, 'Kconfig'), os.path.join(target_path, 'Kconfig'))
do_copy_file(os.path.join(RTT_ROOT, 'AUTHORS'), os.path.join(target_path, 'AUTHORS')) do_copy_file(os.path.join(RTT_ROOT, 'AUTHORS'), os.path.join(target_path, 'AUTHORS'))
do_copy_file(os.path.join(RTT_ROOT, 'COPYING'), os.path.join(target_path, 'COPYING')) do_copy_file(os.path.join(RTT_ROOT, 'COPYING'), os.path.join(target_path, 'COPYING'))
do_copy_file(os.path.join(RTT_ROOT, 'README.md'), os.path.join(target_path, 'README.md')) do_copy_file(os.path.join(RTT_ROOT, 'README.md'), os.path.join(target_path, 'README.md'))
do_copy_file(os.path.join(RTT_ROOT, 'README_zh.md'), os.path.join(target_path, 'README_zh.md')) do_copy_file(os.path.join(RTT_ROOT, 'README_zh.md'), os.path.join(target_path, 'README_zh.md'))
print('=> libc')
do_copy_folder(os.path.join(RTT_ROOT, "components", 'libc', 'compilers'), os.path.join(target_path, "components", 'libc', 'compilers'))
# change RTT_ROOT in SConstruct # change RTT_ROOT in SConstruct
try: bsp_update_sconstruct(dist_dir)
sconstruct = file(os.path.join(BSP_ROOT, 'SConstruct'))
out = file(os.path.join(dist_dir, 'SConstruct'), 'w')
for line in sconstruct:
if line.find('RTT_ROOT') != -1:
if line.find('sys.path') != -1:
out.write('# set RTT_ROOT\n')
out.write("if not os.getenv('RTT_ROOT'): \n RTT_ROOT='rt-thread'\n\n")
out.write(line)
except :
print('')
# change RTT_ROOT in Kconfig # change RTT_ROOT in Kconfig
try: bsp_update_kconfig(dist_dir)
if os.path.exists(os.path.join(BSP_ROOT, 'Kconfig')): # update all project files
Kconfig = file(os.path.join(BSP_ROOT, 'Kconfig')) bs_update_ide_project(dist_dir, target_path)
out = file(os.path.join(dist_dir, 'Kconfig'), 'w')
found = 0
for line in Kconfig:
if line.find('RTT_ROOT') != -1:
found = 1
if line.find('default') != -1 and found:
position = line.find('default')
line = line[0:position] + 'default: "rt-thread"\n'
found = 0
out.write(line)
out.close()
except :
print('')
# make zip package # make zip package
import zipfile zip_dist(BSP_ROOT, dist_dir, dist_name)
zip_filename = os.path.join(BSP_ROOT, 'dist', dist_name)
zip = zipfile.ZipFile(zip_filename + ".zip", 'w')
pre_len = len(os.path.dirname(dist_dir))
for parent, dirnames, filenames in os.walk(dist_dir):
for filename in filenames:
pathfile = os.path.join(parent, filename)
arcname = pathfile[pre_len:].strip(os.path.sep)
zip.write(pathfile, arcname)
zip.close()
print('done!') print('done!')
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册