Skip to content

Commit 62a7c59

Browse files
committed
[Tools] Sync to latest version.
1 parent 7a6a1e1 commit 62a7c59

File tree

6 files changed

+235
-15
lines changed

6 files changed

+235
-15
lines changed

tools/building.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ def spawn(self, sh, escape, cmd, args, env):
105105
try:
106106
proc = subprocess.Popen(cmdline, env=_e, shell=False)
107107
except Exception as e:
108-
print ('Error in calling:\n' + cmdline)
109-
print ('Exception: ' + e + ': ' + os.strerror(e.errno))
108+
print ('Error in calling command:' + cmdline.split(' ')[0])
109+
print ('Exception: ' + os.strerror(e.errno))
110+
if (os.strerror(e.errno) == "No such file or directory"):
111+
print ("\nPlease check Toolchains PATH setting.\n")
112+
110113
return e.errno
111114
finally:
112115
os.environ['PATH'] = old_path
@@ -128,7 +131,7 @@ def GenCconfigFile(env, BuildOptions):
128131
f = open('cconfig.h', 'r')
129132
if f:
130133
contents = f.read()
131-
f.close();
134+
f.close()
132135

133136
prep = PatchedPreProcessor()
134137
prep.process_contents(contents)
@@ -184,7 +187,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
184187
AddOption('--target',
185188
dest = 'target',
186189
type = 'string',
187-
help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk')
190+
help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk/ses')
188191
AddOption('--genconfig',
189192
dest = 'genconfig',
190193
action = 'store_true',
@@ -224,7 +227,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
224227
'vsc' : ('gcc', 'gcc'),
225228
'cb':('keil', 'armcc'),
226229
'ua':('gcc', 'gcc'),
227-
'cdk':('gcc', 'gcc')}
230+
'cdk':('gcc', 'gcc'),
231+
'ses' : ('gcc', 'gcc')}
228232
tgt_name = GetOption('target')
229233

230234
if tgt_name:
@@ -345,8 +349,20 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
345349
action = 'store_true',
346350
default = False,
347351
help = 'make menuconfig for RT-Thread BSP')
348-
if GetOption('pyconfig'):
352+
AddOption('--pyconfig-silent',
353+
dest = 'pyconfig_silent',
354+
action = 'store_true',
355+
default = False,
356+
help = 'Don`t show pyconfig window')
357+
358+
if GetOption('pyconfig_silent'):
359+
from menuconfig import pyconfig_silent
360+
361+
pyconfig_silent(Rtt_Root)
362+
exit(0)
363+
elif GetOption('pyconfig'):
349364
from menuconfig import pyconfig
365+
350366
pyconfig(Rtt_Root)
351367
exit(0)
352368

@@ -797,6 +813,10 @@ def GenTargetProject(program = None):
797813
from cdk import CDKProject
798814
CDKProject('project.cdkproj', Projects)
799815

816+
if GetOption('target') == 'ses':
817+
from ses import SESProject
818+
SESProject(Env)
819+
800820
def EndBuilding(target, program = None):
801821
import rtconfig
802822

@@ -805,6 +825,12 @@ def EndBuilding(target, program = None):
805825
Env['target'] = program
806826
Env['project'] = Projects
807827

828+
if hasattr(rtconfig, 'BSP_LIBRARY_TYPE'):
829+
Env['bsp_lib_type'] = rtconfig.BSP_LIBRARY_TYPE
830+
831+
if hasattr(rtconfig, 'dist_handle'):
832+
Env['dist_handle'] = rtconfig.dist_handle
833+
808834
Env.AddPostAction(target, rtconfig.POST_ACTION)
809835
# Add addition clean files
810836
Clean(target, 'cconfig.h')

tools/menuconfig.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,20 @@ def pyconfig(RTT_ROOT):
251251
if mtime != mtime2:
252252
mk_rtconfig(fn)
253253

254+
255+
# pyconfig_silent for windows and linux
256+
def pyconfig_silent(RTT_ROOT):
257+
import pymenuconfig
258+
print("In pyconfig silent mode. Don`t display menuconfig window.")
259+
260+
touch_env()
261+
env_dir = get_env_dir()
262+
263+
os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages')
264+
265+
fn = '.config'
266+
267+
pymenuconfig.main(['--kconfig', 'Kconfig', '--config', '.config', '--silent', 'True'])
268+
269+
# silent mode, force to make rtconfig.h
270+
mk_rtconfig(fn)

tools/mkdist.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ def bsp_update_kconfig(dist_dir):
122122
line = line[0:position] + 'default: "rt-thread"\n'
123123
found = 0
124124
f.write(line)
125+
126+
def bsp_update_kconfig_library(dist_dir):
127+
# change RTT_ROOT in Kconfig
128+
if not os.path.isfile(os.path.join(dist_dir, 'Kconfig')):
129+
return
130+
131+
with open(os.path.join(dist_dir, 'Kconfig'), 'r') as f:
132+
data = f.readlines()
133+
with open(os.path.join(dist_dir, 'Kconfig'), 'w') as f:
134+
found = 0
135+
for line in data:
136+
if line.find('RTT_ROOT') != -1:
137+
found = 1
138+
if line.find('../libraries') != -1 and found:
139+
position = line.find('../libraries')
140+
line = line[0:position] + 'libraries/Kconfig"\n'
141+
found = 0
142+
f.write(line)
125143

126144
def bs_update_ide_project(bsp_root, rtt_root):
127145
import subprocess
@@ -169,6 +187,21 @@ def MkDist_Strip(program, BSP_ROOT, RTT_ROOT, Env):
169187
print('=> %s' % os.path.basename(BSP_ROOT))
170188
bsp_copy_files(BSP_ROOT, dist_dir)
171189

190+
# copy stm32 bsp libiary files
191+
if os.path.basename(os.path.dirname(BSP_ROOT)) == 'stm32':
192+
print("=> copy stm32 bsp library")
193+
library_path = os.path.join(os.path.dirname(BSP_ROOT), 'libraries')
194+
library_dir = os.path.join(dist_dir, 'libraries')
195+
bsp_copy_files(os.path.join(library_path, 'HAL_Drivers'), os.path.join(library_dir, 'HAL_Drivers'))
196+
bsp_copy_files(os.path.join(library_path, Env['bsp_lib_type']), os.path.join(library_dir, Env['bsp_lib_type']))
197+
shutil.copyfile(os.path.join(library_path, 'Kconfig'), os.path.join(library_dir, 'Kconfig'))
198+
199+
# do bsp special dist handle
200+
if 'dist_handle' in Env:
201+
print("=> start dist handle")
202+
dist_handle = Env['dist_handle']
203+
dist_handle(BSP_ROOT)
204+
172205
# get all source files from program
173206
for item in program:
174207
walk_children(item)
@@ -260,6 +293,7 @@ def MkDist_Strip(program, BSP_ROOT, RTT_ROOT, Env):
260293
bsp_update_sconstruct(dist_dir)
261294
# change RTT_ROOT in Kconfig
262295
bsp_update_kconfig(dist_dir)
296+
bsp_update_kconfig_library(dist_dir)
263297
# update all project files
264298
bs_update_ide_project(dist_dir, target_path)
265299

@@ -280,6 +314,21 @@ def MkDist(program, BSP_ROOT, RTT_ROOT, Env):
280314
print('=> %s' % os.path.basename(BSP_ROOT))
281315
bsp_copy_files(BSP_ROOT, dist_dir)
282316

317+
# copy stm32 bsp libiary files
318+
if os.path.basename(os.path.dirname(BSP_ROOT)) == 'stm32':
319+
print("=> copy stm32 bsp library")
320+
library_path = os.path.join(os.path.dirname(BSP_ROOT), 'libraries')
321+
library_dir = os.path.join(dist_dir, 'libraries')
322+
bsp_copy_files(os.path.join(library_path, 'HAL_Drivers'), os.path.join(library_dir, 'HAL_Drivers'))
323+
bsp_copy_files(os.path.join(library_path, Env['bsp_lib_type']), os.path.join(library_dir, Env['bsp_lib_type']))
324+
shutil.copyfile(os.path.join(library_path, 'Kconfig'), os.path.join(library_dir, 'Kconfig'))
325+
326+
# do bsp special dist handle
327+
if 'dist_handle' in Env:
328+
print("=> start dist handle")
329+
dist_handle = Env['dist_handle']
330+
dist_handle(BSP_ROOT)
331+
283332
# copy tools directory
284333
print('=> components')
285334
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):
316365
bsp_update_sconstruct(dist_dir)
317366
# change RTT_ROOT in Kconfig
318367
bsp_update_kconfig(dist_dir)
368+
bsp_update_kconfig_library(dist_dir)
319369
# update all project files
320370
bs_update_ide_project(dist_dir, target_path)
321371

tools/pymenuconfig.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,11 @@ class MenuConfig(object):
543543
('Save as', ACTION_SAVE_AS),
544544
)
545545

546-
def __init__(self, kconfig):
546+
def __init__(self, kconfig, __silent=None):
547547
self.kconfig = kconfig
548+
self.__silent = __silent
549+
if self.__silent is True:
550+
return
548551

549552
# Instantiate Tk widgets
550553
self.root = tk.Tk()
@@ -728,6 +731,8 @@ def handle_keypress(self, ev):
728731
def _close_window(self):
729732
if self.prevent_losing_changes():
730733
print('Exiting..')
734+
if self.__silent is True:
735+
return
731736
self.root.destroy()
732737

733738
def _action_exit(self):
@@ -949,6 +954,8 @@ def update_status(self):
949954
- current config path
950955
- status string (see set_status_string())
951956
"""
957+
if self.__silent is True:
958+
return
952959
self.tk_status.set('{} [{}] {}'.format(
953960
'<UNSAVED>' if self.unsaved_changes else '',
954961
self.config_path if self.config_path else '',
@@ -1017,6 +1024,10 @@ def prevent_losing_changes(self):
10171024
self.mark_as_changed()
10181025
if not self.unsaved_changes:
10191026
return True
1027+
1028+
if self.__silent:
1029+
saved = self.save_config()
1030+
return saved
10201031
res = messagebox.askyesnocancel(
10211032
parent=self.root,
10221033
title='Unsaved changes',
@@ -1056,11 +1067,13 @@ def open_config(self, path=None):
10561067
self.kconfig.load_config(path)
10571068
except IOError as e:
10581069
self.set_status_string('Failed to load: \'{}\''.format(path))
1059-
self.refresh_display()
1070+
if not self.__silent:
1071+
self.refresh_display()
10601072
print('Failed to load config \'{}\': {}'.format(path, e))
10611073
return False
10621074
self.set_status_string('Opened config')
1063-
self.refresh_display()
1075+
if not self.__silent:
1076+
self.refresh_display()
10641077
return True
10651078

10661079
def save_config(self, force_file_dialog=False):
@@ -1154,19 +1167,39 @@ def main(argv=None):
11541167
type=str,
11551168
help='path to .config file to load'
11561169
)
1170+
if "--silent" in argv:
1171+
parser.add_argument(
1172+
'--silent',
1173+
dest = '_silent_',
1174+
type=str,
1175+
help='silent mode, not show window'
1176+
)
11571177
args = parser.parse_args(argv)
11581178
kconfig_path = args.kconfig
11591179
config_path = args.config
11601180
# Verify that Kconfig file exists
11611181
if not os.path.isfile(kconfig_path):
11621182
raise RuntimeError('\'{}\': no such file'.format(kconfig_path))
1183+
11631184
# Parse Kconfig files
11641185
kconf = kconfiglib.Kconfig(filename=kconfig_path)
1165-
mc = MenuConfig(kconf)
1166-
# If config file was specified, load it
1167-
if config_path:
1168-
mc.open_config(config_path)
1169-
tk.mainloop()
1186+
1187+
if "--silent" not in argv:
1188+
print("In normal mode. Will show menuconfig window.")
1189+
mc = MenuConfig(kconf)
1190+
# If config file was specified, load it
1191+
if config_path:
1192+
mc.open_config(config_path)
1193+
1194+
print("Enter mainloop. Waiting...")
1195+
tk.mainloop()
1196+
else:
1197+
print("In silent mode. Don`t show menuconfig window.")
1198+
mc = MenuConfig(kconf, True)
1199+
# If config file was specified, load it
1200+
if config_path:
1201+
mc.open_config(config_path)
1202+
mc._close_window()
11701203

11711204

11721205
if __name__ == '__main__':

tools/ses.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# SEGGER Embedded Studio Project Generator
2+
3+
import os
4+
import sys
5+
6+
import xml.etree.ElementTree as etree
7+
from xml.etree.ElementTree import SubElement
8+
from utils import _make_path_relative
9+
from utils import xml_indent
10+
from utils import ProjectInfo
11+
12+
def SDKAddGroup(parent, name, files, project_path):
13+
# don't add an empty group
14+
if len(files) == 0:
15+
return
16+
17+
group = SubElement(parent, 'folder', attrib={'Name': name})
18+
19+
for f in files:
20+
fn = f.rfile()
21+
name = fn.name
22+
path = os.path.dirname(fn.abspath)
23+
24+
basename = os.path.basename(path)
25+
path = _make_path_relative(project_path, path)
26+
elm_attr_name = os.path.join(path, name)
27+
28+
file = SubElement(group, 'file', attrib={'file_name': elm_attr_name})
29+
30+
return group
31+
32+
def SESProject(env) :
33+
target = 'project.emProject'
34+
tree = etree.parse('template.emProject')
35+
# print(etree.dump(tree.getroot()))
36+
# etree.dump(tree.getroot())
37+
38+
project = ProjectInfo(env)
39+
# print(project)
40+
# return
41+
42+
project_path = os.path.abspath(env['BSP_ROOT'])
43+
script = env['project']
44+
45+
root = tree.getroot()
46+
out = file(target, 'w')
47+
out.write('<!DOCTYPE CrossStudio_Project_File>\n')
48+
49+
CPPPATH = []
50+
CPPDEFINES = []
51+
LINKFLAGS = ''
52+
CCFLAGS = ''
53+
54+
project_node = tree.find('project')
55+
56+
for group in script:
57+
# print(group)
58+
59+
group_tree = SDKAddGroup(project_node, group['name'], group['src'], project_path)
60+
61+
# get each group's cc flags
62+
if group.has_key('CCFLAGS') and group['CCFLAGS']:
63+
if CCFLAGS:
64+
CCFLAGS += ' ' + group['CCFLAGS']
65+
else:
66+
CCFLAGS += group['CCFLAGS']
67+
68+
# get each group's link flags
69+
if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
70+
if LINKFLAGS:
71+
LINKFLAGS += ' ' + group['LINKFLAGS']
72+
else:
73+
LINKFLAGS += group['LINKFLAGS']
74+
75+
# write include path, definitions and link flags
76+
path = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in project['CPPPATH']])
77+
path = path.replace('\\', '/')
78+
defines = ';'.join(set(project['CPPDEFINES']))
79+
80+
node = tree.findall('project/configuration')
81+
for item in node:
82+
if item.get('c_preprocessor_definitions'):
83+
item.set('c_preprocessor_definitions', defines)
84+
85+
if item.get('c_user_include_directories'):
86+
item.set('c_user_include_directories', path)
87+
88+
xml_indent(root)
89+
out.write(etree.tostring(root, encoding='utf-8'))
90+
out.close()
91+
92+
return

0 commit comments

Comments
 (0)