summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarmink <[email protected]>2018-12-28 18:41:48 +0800
committerarmink <[email protected]>2018-12-28 18:41:48 +0800
commit62a7c59c7af239f8e3453d91058bf69719fa11ec (patch)
tree9341e4a6a8e63ab81437e1275b017d110cdb1078
parent7a6a1e11073617befcb542c62d6782ff03986fcc (diff)
[Tools] Sync to latest version.
-rw-r--r--tools/building.py38
-rw-r--r--tools/menuconfig.py17
-rw-r--r--tools/mkdist.py50
-rw-r--r--tools/pymenuconfig.py49
-rw-r--r--tools/ses.py92
-rw-r--r--tools/utils.py4
6 files changed, 235 insertions, 15 deletions
diff --git a/tools/building.py b/tools/building.py
index cbd245b948..57e58b9ab0 100644
--- a/tools/building.py
+++ b/tools/building.py
@@ -105,8 +105,11 @@ class Win32Spawn:
try:
proc = subprocess.Popen(cmdline, env=_e, shell=False)
except Exception as e:
- print ('Error in calling:\n' + cmdline)
- print ('Exception: ' + e + ': ' + os.strerror(e.errno))
+ print ('Error in calling command:' + cmdline.split(' ')[0])
+ 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
finally:
os.environ['PATH'] = old_path
@@ -128,7 +131,7 @@ def GenCconfigFile(env, BuildOptions):
f = open('cconfig.h', 'r')
if f:
contents = f.read()
- f.close();
+ f.close()
prep = PatchedPreProcessor()
prep.process_contents(contents)
@@ -184,7 +187,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
AddOption('--target',
dest = 'target',
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',
dest = 'genconfig',
action = 'store_true',
@@ -224,7 +227,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
'vsc' : ('gcc', 'gcc'),
'cb':('keil', 'armcc'),
'ua':('gcc', 'gcc'),
- 'cdk':('gcc', 'gcc')}
+ 'cdk':('gcc', 'gcc'),
+ 'ses' : ('gcc', 'gcc')}
tgt_name = GetOption('target')
if tgt_name:
@@ -345,8 +349,20 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
action = 'store_true',
default = False,
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
+
pyconfig(Rtt_Root)
exit(0)
@@ -797,6 +813,10 @@ def GenTargetProject(program = None):
from cdk import CDKProject
CDKProject('project.cdkproj', Projects)
+ if GetOption('target') == 'ses':
+ from ses import SESProject
+ SESProject(Env)
+
def EndBuilding(target, program = None):
import rtconfig
@@ -805,6 +825,12 @@ def EndBuilding(target, program = None):
Env['target'] = program
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)
# Add addition clean files
Clean(target, 'cconfig.h')
diff --git a/tools/menuconfig.py b/tools/menuconfig.py
index ea221553d0..2550424802 100644
--- a/tools/menuconfig.py
+++ b/tools/menuconfig.py
@@ -251,3 +251,20 @@ def pyconfig(RTT_ROOT):
if mtime != mtime2:
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)
diff --git a/tools/mkdist.py b/tools/mkdist.py
index eef6bfd118..cf30e95284 100644
--- a/tools/mkdist.py
+++ b/tools/mkdist.py
@@ -122,6 +122,24 @@ def bsp_update_kconfig(dist_dir):
line = line[0:position] + 'default: "rt-thread"\n'
found = 0
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):
import subprocess
@@ -169,6 +187,21 @@ def MkDist_Strip(program, BSP_ROOT, RTT_ROOT, Env):
print('=> %s' % os.path.basename(BSP_ROOT))
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
for item in program:
walk_children(item)
@@ -260,6 +293,7 @@ def MkDist_Strip(program, BSP_ROOT, RTT_ROOT, Env):
bsp_update_sconstruct(dist_dir)
# change RTT_ROOT in Kconfig
bsp_update_kconfig(dist_dir)
+ bsp_update_kconfig_library(dist_dir)
# update all project files
bs_update_ide_project(dist_dir, target_path)
@@ -280,6 +314,21 @@ def MkDist(program, BSP_ROOT, RTT_ROOT, Env):
print('=> %s' % os.path.basename(BSP_ROOT))
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
print('=> 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):
bsp_update_sconstruct(dist_dir)
# change RTT_ROOT in Kconfig
bsp_update_kconfig(dist_dir)
+ bsp_update_kconfig_library(dist_dir)
# update all project files
bs_update_ide_project(dist_dir, target_path)
diff --git a/tools/pymenuconfig.py b/tools/pymenuconfig.py
index 0e069355be..67893d7281 100644
--- a/tools/pymenuconfig.py
+++ b/tools/pymenuconfig.py
@@ -543,8 +543,11 @@ class MenuConfig(object):
('Save as', ACTION_SAVE_AS),
)
- def __init__(self, kconfig):
+ def __init__(self, kconfig, __silent=None):
self.kconfig = kconfig
+ self.__silent = __silent
+ if self.__silent is True:
+ return
# Instantiate Tk widgets
self.root = tk.Tk()
@@ -728,6 +731,8 @@ class MenuConfig(object):
def _close_window(self):
if self.prevent_losing_changes():
print('Exiting..')
+ if self.__silent is True:
+ return
self.root.destroy()
def _action_exit(self):
@@ -949,6 +954,8 @@ class MenuConfig(object):
- current config path
- status string (see set_status_string())
"""
+ if self.__silent is True:
+ return
self.tk_status.set('{} [{}] {}'.format(
'<UNSAVED>' if self.unsaved_changes else '',
self.config_path if self.config_path else '',
@@ -1017,6 +1024,10 @@ class MenuConfig(object):
self.mark_as_changed()
if not self.unsaved_changes:
return True
+
+ if self.__silent:
+ saved = self.save_config()
+ return saved
res = messagebox.askyesnocancel(
parent=self.root,
title='Unsaved changes',
@@ -1056,11 +1067,13 @@ class MenuConfig(object):
self.kconfig.load_config(path)
except IOError as e:
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))
return False
self.set_status_string('Opened config')
- self.refresh_display()
+ if not self.__silent:
+ self.refresh_display()
return True
def save_config(self, force_file_dialog=False):
@@ -1154,19 +1167,39 @@ def main(argv=None):
type=str,
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)
kconfig_path = args.kconfig
config_path = args.config
# Verify that Kconfig file exists
if not os.path.isfile(kconfig_path):
raise RuntimeError('\'{}\': no such file'.format(kconfig_path))
+
# Parse Kconfig files
kconf = kconfiglib.Kconfig(filename=kconfig_path)
- mc = MenuConfig(kconf)
- # If config file was specified, load it
- if config_path:
- mc.open_config(config_path)
- tk.mainloop()
+
+ if "--silent" not in argv:
+ print("In normal mode. Will show menuconfig window.")
+ mc = MenuConfig(kconf)
+ # 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__':
diff --git a/tools/ses.py b/tools/ses.py
new file mode 100644
index 0000000000..dcd9d34442
--- /dev/null
+++ b/tools/ses.py
@@ -0,0 +1,92 @@
+# 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
diff --git a/tools/utils.py b/tools/utils.py
index 692cf36c69..6dc56322a5 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -245,7 +245,9 @@ def ProjectInfo(env):
return proj
def VersionCmp(ver1, ver2):
- la = ver1.split('.')
+ la=[];
+ if ver1:
+ la = ver1.split('.')
lb = ver2.split('.')
f = 0
if len(la) > len(lb):