提交 62a7c59c 编写于 作者: armink_ztl's avatar armink_ztl

[Tools] Sync to latest version.

上级 7a6a1e11
...@@ -105,8 +105,11 @@ class Win32Spawn: ...@@ -105,8 +105,11 @@ class Win32Spawn:
try: try:
proc = subprocess.Popen(cmdline, env=_e, shell=False) proc = subprocess.Popen(cmdline, env=_e, shell=False)
except Exception as e: except Exception as e:
print ('Error in calling:\n' + cmdline) print ('Error in calling command:' + cmdline.split(' ')[0])
print ('Exception: ' + e + ': ' + os.strerror(e.errno)) print ('Exception: ' + os.strerror(e.errno))
if (os.strerror(e.errno) == "No such file or directory"):
print ("\nPlease check Toolchains PATH setting.\n")
return e.errno return e.errno
finally: finally:
os.environ['PATH'] = old_path os.environ['PATH'] = old_path
...@@ -128,7 +131,7 @@ def GenCconfigFile(env, BuildOptions): ...@@ -128,7 +131,7 @@ def GenCconfigFile(env, BuildOptions):
f = open('cconfig.h', 'r') f = open('cconfig.h', 'r')
if f: if f:
contents = f.read() contents = f.read()
f.close(); f.close()
prep = PatchedPreProcessor() prep = PatchedPreProcessor()
prep.process_contents(contents) prep.process_contents(contents)
...@@ -184,7 +187,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ ...@@ -184,7 +187,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
AddOption('--target', AddOption('--target',
dest = 'target', dest = 'target',
type = 'string', type = 'string',
help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk') help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk/ses')
AddOption('--genconfig', AddOption('--genconfig',
dest = 'genconfig', dest = 'genconfig',
action = 'store_true', action = 'store_true',
...@@ -224,7 +227,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ ...@@ -224,7 +227,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
'vsc' : ('gcc', 'gcc'), 'vsc' : ('gcc', 'gcc'),
'cb':('keil', 'armcc'), 'cb':('keil', 'armcc'),
'ua':('gcc', 'gcc'), 'ua':('gcc', 'gcc'),
'cdk':('gcc', 'gcc')} 'cdk':('gcc', 'gcc'),
'ses' : ('gcc', 'gcc')}
tgt_name = GetOption('target') tgt_name = GetOption('target')
if tgt_name: if tgt_name:
...@@ -345,8 +349,20 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ ...@@ -345,8 +349,20 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
action = 'store_true', action = 'store_true',
default = False, default = False,
help = 'make menuconfig for RT-Thread BSP') help = 'make menuconfig for RT-Thread BSP')
if GetOption('pyconfig'): AddOption('--pyconfig-silent',
dest = 'pyconfig_silent',
action = 'store_true',
default = False,
help = 'Don`t show pyconfig window')
if GetOption('pyconfig_silent'):
from menuconfig import pyconfig_silent
pyconfig_silent(Rtt_Root)
exit(0)
elif GetOption('pyconfig'):
from menuconfig import pyconfig from menuconfig import pyconfig
pyconfig(Rtt_Root) pyconfig(Rtt_Root)
exit(0) exit(0)
...@@ -797,6 +813,10 @@ def GenTargetProject(program = None): ...@@ -797,6 +813,10 @@ def GenTargetProject(program = None):
from cdk import CDKProject from cdk import CDKProject
CDKProject('project.cdkproj', Projects) CDKProject('project.cdkproj', Projects)
if GetOption('target') == 'ses':
from ses import SESProject
SESProject(Env)
def EndBuilding(target, program = None): def EndBuilding(target, program = None):
import rtconfig import rtconfig
...@@ -805,6 +825,12 @@ def EndBuilding(target, program = None): ...@@ -805,6 +825,12 @@ def EndBuilding(target, program = None):
Env['target'] = program Env['target'] = program
Env['project'] = Projects Env['project'] = Projects
if hasattr(rtconfig, 'BSP_LIBRARY_TYPE'):
Env['bsp_lib_type'] = rtconfig.BSP_LIBRARY_TYPE
if hasattr(rtconfig, 'dist_handle'):
Env['dist_handle'] = rtconfig.dist_handle
Env.AddPostAction(target, rtconfig.POST_ACTION) Env.AddPostAction(target, rtconfig.POST_ACTION)
# Add addition clean files # Add addition clean files
Clean(target, 'cconfig.h') Clean(target, 'cconfig.h')
......
...@@ -251,3 +251,20 @@ def pyconfig(RTT_ROOT): ...@@ -251,3 +251,20 @@ def pyconfig(RTT_ROOT):
if mtime != mtime2: if mtime != mtime2:
mk_rtconfig(fn) mk_rtconfig(fn)
# pyconfig_silent for windows and linux
def pyconfig_silent(RTT_ROOT):
import pymenuconfig
print("In pyconfig silent mode. Don`t display menuconfig window.")
touch_env()
env_dir = get_env_dir()
os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages')
fn = '.config'
pymenuconfig.main(['--kconfig', 'Kconfig', '--config', '.config', '--silent', 'True'])
# silent mode, force to make rtconfig.h
mk_rtconfig(fn)
...@@ -122,6 +122,24 @@ def bsp_update_kconfig(dist_dir): ...@@ -122,6 +122,24 @@ def bsp_update_kconfig(dist_dir):
line = line[0:position] + 'default: "rt-thread"\n' line = line[0:position] + 'default: "rt-thread"\n'
found = 0 found = 0
f.write(line) f.write(line)
def bsp_update_kconfig_library(dist_dir):
# change RTT_ROOT in Kconfig
if not os.path.isfile(os.path.join(dist_dir, 'Kconfig')):
return
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('../libraries') != -1 and found:
position = line.find('../libraries')
line = line[0:position] + 'libraries/Kconfig"\n'
found = 0
f.write(line)
def bs_update_ide_project(bsp_root, rtt_root): def bs_update_ide_project(bsp_root, rtt_root):
import subprocess import subprocess
...@@ -169,6 +187,21 @@ def MkDist_Strip(program, BSP_ROOT, RTT_ROOT, Env): ...@@ -169,6 +187,21 @@ def MkDist_Strip(program, BSP_ROOT, RTT_ROOT, Env):
print('=> %s' % os.path.basename(BSP_ROOT)) print('=> %s' % os.path.basename(BSP_ROOT))
bsp_copy_files(BSP_ROOT, dist_dir) bsp_copy_files(BSP_ROOT, dist_dir)
# copy stm32 bsp libiary files
if os.path.basename(os.path.dirname(BSP_ROOT)) == 'stm32':
print("=> copy stm32 bsp library")
library_path = os.path.join(os.path.dirname(BSP_ROOT), 'libraries')
library_dir = os.path.join(dist_dir, 'libraries')
bsp_copy_files(os.path.join(library_path, 'HAL_Drivers'), os.path.join(library_dir, 'HAL_Drivers'))
bsp_copy_files(os.path.join(library_path, Env['bsp_lib_type']), os.path.join(library_dir, Env['bsp_lib_type']))
shutil.copyfile(os.path.join(library_path, 'Kconfig'), os.path.join(library_dir, 'Kconfig'))
# do bsp special dist handle
if 'dist_handle' in Env:
print("=> start dist handle")
dist_handle = Env['dist_handle']
dist_handle(BSP_ROOT)
# get all source files from program # get all source files from program
for item in program: for item in program:
walk_children(item) walk_children(item)
...@@ -260,6 +293,7 @@ def MkDist_Strip(program, BSP_ROOT, RTT_ROOT, Env): ...@@ -260,6 +293,7 @@ def MkDist_Strip(program, BSP_ROOT, RTT_ROOT, Env):
bsp_update_sconstruct(dist_dir) bsp_update_sconstruct(dist_dir)
# change RTT_ROOT in Kconfig # change RTT_ROOT in Kconfig
bsp_update_kconfig(dist_dir) bsp_update_kconfig(dist_dir)
bsp_update_kconfig_library(dist_dir)
# update all project files # update all project files
bs_update_ide_project(dist_dir, target_path) bs_update_ide_project(dist_dir, target_path)
...@@ -280,6 +314,21 @@ def MkDist(program, BSP_ROOT, RTT_ROOT, Env): ...@@ -280,6 +314,21 @@ def MkDist(program, BSP_ROOT, RTT_ROOT, Env):
print('=> %s' % os.path.basename(BSP_ROOT)) print('=> %s' % os.path.basename(BSP_ROOT))
bsp_copy_files(BSP_ROOT, dist_dir) bsp_copy_files(BSP_ROOT, dist_dir)
# copy stm32 bsp libiary files
if os.path.basename(os.path.dirname(BSP_ROOT)) == 'stm32':
print("=> copy stm32 bsp library")
library_path = os.path.join(os.path.dirname(BSP_ROOT), 'libraries')
library_dir = os.path.join(dist_dir, 'libraries')
bsp_copy_files(os.path.join(library_path, 'HAL_Drivers'), os.path.join(library_dir, 'HAL_Drivers'))
bsp_copy_files(os.path.join(library_path, Env['bsp_lib_type']), os.path.join(library_dir, Env['bsp_lib_type']))
shutil.copyfile(os.path.join(library_path, 'Kconfig'), os.path.join(library_dir, 'Kconfig'))
# do bsp special dist handle
if 'dist_handle' in Env:
print("=> start dist handle")
dist_handle = Env['dist_handle']
dist_handle(BSP_ROOT)
# copy tools directory # copy tools directory
print('=> components') print('=> components')
do_copy_folder(os.path.join(RTT_ROOT, 'components'), os.path.join(target_path, 'components')) do_copy_folder(os.path.join(RTT_ROOT, 'components'), os.path.join(target_path, 'components'))
...@@ -316,6 +365,7 @@ def MkDist(program, BSP_ROOT, RTT_ROOT, Env): ...@@ -316,6 +365,7 @@ def MkDist(program, BSP_ROOT, RTT_ROOT, Env):
bsp_update_sconstruct(dist_dir) bsp_update_sconstruct(dist_dir)
# change RTT_ROOT in Kconfig # change RTT_ROOT in Kconfig
bsp_update_kconfig(dist_dir) bsp_update_kconfig(dist_dir)
bsp_update_kconfig_library(dist_dir)
# update all project files # update all project files
bs_update_ide_project(dist_dir, target_path) bs_update_ide_project(dist_dir, target_path)
......
...@@ -543,8 +543,11 @@ class MenuConfig(object): ...@@ -543,8 +543,11 @@ class MenuConfig(object):
('Save as', ACTION_SAVE_AS), ('Save as', ACTION_SAVE_AS),
) )
def __init__(self, kconfig): def __init__(self, kconfig, __silent=None):
self.kconfig = kconfig self.kconfig = kconfig
self.__silent = __silent
if self.__silent is True:
return
# Instantiate Tk widgets # Instantiate Tk widgets
self.root = tk.Tk() self.root = tk.Tk()
...@@ -728,6 +731,8 @@ class MenuConfig(object): ...@@ -728,6 +731,8 @@ class MenuConfig(object):
def _close_window(self): def _close_window(self):
if self.prevent_losing_changes(): if self.prevent_losing_changes():
print('Exiting..') print('Exiting..')
if self.__silent is True:
return
self.root.destroy() self.root.destroy()
def _action_exit(self): def _action_exit(self):
...@@ -949,6 +954,8 @@ class MenuConfig(object): ...@@ -949,6 +954,8 @@ class MenuConfig(object):
- current config path - current config path
- status string (see set_status_string()) - status string (see set_status_string())
""" """
if self.__silent is True:
return
self.tk_status.set('{} [{}] {}'.format( self.tk_status.set('{} [{}] {}'.format(
'<UNSAVED>' if self.unsaved_changes else '', '<UNSAVED>' if self.unsaved_changes else '',
self.config_path if self.config_path else '', self.config_path if self.config_path else '',
...@@ -1017,6 +1024,10 @@ class MenuConfig(object): ...@@ -1017,6 +1024,10 @@ class MenuConfig(object):
self.mark_as_changed() self.mark_as_changed()
if not self.unsaved_changes: if not self.unsaved_changes:
return True return True
if self.__silent:
saved = self.save_config()
return saved
res = messagebox.askyesnocancel( res = messagebox.askyesnocancel(
parent=self.root, parent=self.root,
title='Unsaved changes', title='Unsaved changes',
...@@ -1056,11 +1067,13 @@ class MenuConfig(object): ...@@ -1056,11 +1067,13 @@ class MenuConfig(object):
self.kconfig.load_config(path) self.kconfig.load_config(path)
except IOError as e: except IOError as e:
self.set_status_string('Failed to load: \'{}\''.format(path)) self.set_status_string('Failed to load: \'{}\''.format(path))
self.refresh_display() if not self.__silent:
self.refresh_display()
print('Failed to load config \'{}\': {}'.format(path, e)) print('Failed to load config \'{}\': {}'.format(path, e))
return False return False
self.set_status_string('Opened config') self.set_status_string('Opened config')
self.refresh_display() if not self.__silent:
self.refresh_display()
return True return True
def save_config(self, force_file_dialog=False): def save_config(self, force_file_dialog=False):
...@@ -1154,19 +1167,39 @@ def main(argv=None): ...@@ -1154,19 +1167,39 @@ def main(argv=None):
type=str, type=str,
help='path to .config file to load' help='path to .config file to load'
) )
if "--silent" in argv:
parser.add_argument(
'--silent',
dest = '_silent_',
type=str,
help='silent mode, not show window'
)
args = parser.parse_args(argv) args = parser.parse_args(argv)
kconfig_path = args.kconfig kconfig_path = args.kconfig
config_path = args.config config_path = args.config
# Verify that Kconfig file exists # Verify that Kconfig file exists
if not os.path.isfile(kconfig_path): if not os.path.isfile(kconfig_path):
raise RuntimeError('\'{}\': no such file'.format(kconfig_path)) raise RuntimeError('\'{}\': no such file'.format(kconfig_path))
# Parse Kconfig files # Parse Kconfig files
kconf = kconfiglib.Kconfig(filename=kconfig_path) kconf = kconfiglib.Kconfig(filename=kconfig_path)
mc = MenuConfig(kconf)
# If config file was specified, load it if "--silent" not in argv:
if config_path: print("In normal mode. Will show menuconfig window.")
mc.open_config(config_path) mc = MenuConfig(kconf)
tk.mainloop() # If config file was specified, load it
if config_path:
mc.open_config(config_path)
print("Enter mainloop. Waiting...")
tk.mainloop()
else:
print("In silent mode. Don`t show menuconfig window.")
mc = MenuConfig(kconf, True)
# If config file was specified, load it
if config_path:
mc.open_config(config_path)
mc._close_window()
if __name__ == '__main__': if __name__ == '__main__':
......
# SEGGER Embedded Studio Project Generator
import os
import sys
import xml.etree.ElementTree as etree
from xml.etree.ElementTree import SubElement
from utils import _make_path_relative
from utils import xml_indent
from utils import ProjectInfo
def SDKAddGroup(parent, name, files, project_path):
# don't add an empty group
if len(files) == 0:
return
group = SubElement(parent, 'folder', attrib={'Name': name})
for f in files:
fn = f.rfile()
name = fn.name
path = os.path.dirname(fn.abspath)
basename = os.path.basename(path)
path = _make_path_relative(project_path, path)
elm_attr_name = os.path.join(path, name)
file = SubElement(group, 'file', attrib={'file_name': elm_attr_name})
return group
def SESProject(env) :
target = 'project.emProject'
tree = etree.parse('template.emProject')
# print(etree.dump(tree.getroot()))
# etree.dump(tree.getroot())
project = ProjectInfo(env)
# print(project)
# return
project_path = os.path.abspath(env['BSP_ROOT'])
script = env['project']
root = tree.getroot()
out = file(target, 'w')
out.write('<!DOCTYPE CrossStudio_Project_File>\n')
CPPPATH = []
CPPDEFINES = []
LINKFLAGS = ''
CCFLAGS = ''
project_node = tree.find('project')
for group in script:
# print(group)
group_tree = SDKAddGroup(project_node, group['name'], group['src'], project_path)
# get each group's cc flags
if group.has_key('CCFLAGS') and group['CCFLAGS']:
if CCFLAGS:
CCFLAGS += ' ' + group['CCFLAGS']
else:
CCFLAGS += group['CCFLAGS']
# get each group's link flags
if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
if LINKFLAGS:
LINKFLAGS += ' ' + group['LINKFLAGS']
else:
LINKFLAGS += group['LINKFLAGS']
# write include path, definitions and link flags
path = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in project['CPPPATH']])
path = path.replace('\\', '/')
defines = ';'.join(set(project['CPPDEFINES']))
node = tree.findall('project/configuration')
for item in node:
if item.get('c_preprocessor_definitions'):
item.set('c_preprocessor_definitions', defines)
if item.get('c_user_include_directories'):
item.set('c_user_include_directories', path)
xml_indent(root)
out.write(etree.tostring(root, encoding='utf-8'))
out.close()
return
...@@ -245,7 +245,9 @@ def ProjectInfo(env): ...@@ -245,7 +245,9 @@ def ProjectInfo(env):
return proj return proj
def VersionCmp(ver1, ver2): def VersionCmp(ver1, ver2):
la = ver1.split('.') la=[];
if ver1:
la = ver1.split('.')
lb = ver2.split('.') lb = ver2.split('.')
f = 0 f = 0
if len(la) > len(lb): if len(la) > len(lb):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册