Skip to content

Commit a2a0916

Browse files
committed
[tools] add eclipse project for support --specs=nano.specs
1 parent 75ae343 commit a2a0916

File tree

1 file changed

+137
-108
lines changed

1 file changed

+137
-108
lines changed

tools/eclipse.py

Lines changed: 137 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -142,129 +142,158 @@ def HandleToolOption(tools, env, project, reset):
142142
CPPDEFINES = project['CPPDEFINES']
143143
paths = [ConverToRttEclipsePathFormat(RelativeProjectPath(env, os.path.normpath(i)).replace('\\', '/')) for i in project['CPPPATH']]
144144

145+
compile_include_paths_option = None
146+
compile_include_files_option = None
147+
compile_defs_option = None
148+
linker_scriptfile_option = None
149+
linker_script_option = None
150+
linker_nostart_option = None
151+
linker_libs_option = None
152+
linker_paths_option = None
153+
linker_newlib_nano_option = None
154+
145155
for tool in tools:
156+
146157
if tool.get('id').find('c.compile') != 1:
147158
options = tool.findall('option')
148-
include_paths_option = None
149-
include_files_option = None
150-
defs_option = None
151159
# find all compile options
152160
for option in options:
153161
if option.get('id').find('c.compiler.include.paths') != -1 or option.get('id').find('c.compiler.option.includepaths') != -1:
154-
include_paths_option = option
162+
compile_include_paths_option = option
155163
elif option.get('id').find('c.compiler.include.files') != -1 or option.get('id').find('c.compiler.option.includefiles') != -1 :
156-
include_files_option = option
164+
compile_include_files_option = option
157165
elif option.get('id').find('c.compiler.defs') != -1 or option.get('id').find('c.compiler.option.definedsymbols') != -1:
158-
defs_option = option
159-
# change the inclue path
160-
if include_paths_option is not None :
161-
option = include_paths_option
162-
# find all of paths in this project
163-
include_paths = option.findall('listOptionValue')
164-
for item in include_paths:
165-
if reset is True or IsRttEclipsePathFormat(item.get('value')) :
166-
# clean old configuration
167-
option.remove(item)
168-
# print('c.compiler.include.paths')
169-
paths = sorted(paths)
170-
for item in paths:
171-
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item})
172-
# change the inclue files (default) or definitions
173-
if include_files_option is not None:
174-
option = include_files_option
175-
file_header = '''
166+
compile_defs_option = option
167+
168+
if tool.get('id').find('c.linker') != -1:
169+
options = tool.findall('option')
170+
# find all linker options
171+
for option in options:
172+
if option.get('id').find('c.linker.scriptfile') != -1:
173+
linker_scriptfile_option = option
174+
elif option.get('id').find('c.linker.option.script') != -1:
175+
linker_script_option = option
176+
elif option.get('id').find('c.linker.nostart') != -1:
177+
linker_nostart_option = option
178+
elif option.get('id').find('c.linker.libs') != -1 and env.has_key('LIBS'):
179+
linker_libs_option = option
180+
elif option.get('id').find('c.linker.paths') != -1 and env.has_key('LIBPATH'):
181+
linker_paths_option = option
182+
elif option.get('id').find('c.linker.usenewlibnano') != -1:
183+
linker_newlib_nano_option = option
184+
185+
# change the inclue path
186+
if compile_include_paths_option is not None :
187+
option = compile_include_paths_option
188+
# find all of paths in this project
189+
include_paths = option.findall('listOptionValue')
190+
for item in include_paths:
191+
if reset is True or IsRttEclipsePathFormat(item.get('value')) :
192+
# clean old configuration
193+
option.remove(item)
194+
# print('c.compiler.include.paths')
195+
paths = sorted(paths)
196+
for item in paths:
197+
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item})
198+
# change the inclue files (default) or definitions
199+
if compile_include_files_option is not None:
200+
option = compile_include_files_option
201+
# add '_REENT_SMALL' to CPPDEFINES when --specs=nano.specs has select
202+
if linker_newlib_nano_option is not None and linker_newlib_nano_option.get('value') == 'true' and '_REENT_SMALL' not in CPPDEFINES:
203+
CPPDEFINES += ['_REENT_SMALL']
204+
print(linker_newlib_nano_option.get('value'))
205+
206+
file_header = '''
176207
#ifndef RTCONFIG_PREINC_H__
177208
#define RTCONFIG_PREINC_H__
178209
179210
/* Automatically generated file; DO NOT EDIT. */
180211
/* RT-Thread pre-include file */
181212
182213
'''
183-
file_tail = '\n#endif /*RTCONFIG_PREINC_H__*/\n'
184-
rtt_pre_inc_item = '"${workspace_loc:/${ProjName}/rtconfig_preinc.h}"'
185-
# save the CPPDEFINES in to rtconfig_preinc.h
186-
with open('rtconfig_preinc.h', mode = 'w+') as f:
187-
f.write(file_header)
188-
for cppdef in CPPDEFINES:
189-
f.write("#define " + cppdef + '\n')
190-
f.write(file_tail)
191-
# change the c.compiler.include.files
192-
files = option.findall('listOptionValue')
193-
find_ok = False
194-
for item in files:
195-
if item.get('value') == rtt_pre_inc_item:
196-
find_ok = True
197-
break
198-
if find_ok is False:
199-
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': rtt_pre_inc_item})
200-
elif defs_option is not None :
201-
option = defs_option
202-
defs = option.findall('listOptionValue')
203-
project_defs = []
204-
for item in defs:
205-
if reset is True:
206-
# clean all old configuration
207-
option.remove(item)
208-
else:
209-
project_defs += [item.get('value')]
210-
if len(project_defs) > 0:
211-
cproject_defs = set(CPPDEFINES) - set(project_defs)
212-
else:
213-
cproject_defs = CPPDEFINES
214-
215-
# print('c.compiler.defs')
216-
cproject_defs = sorted(cproject_defs)
217-
for item in cproject_defs:
218-
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item})
219-
220-
if tool.get('id').find('c.linker') != -1:
221-
options = tool.findall('option')
222-
for option in options:
223-
# update linker script config
224-
if option.get('id').find('c.linker.scriptfile') != -1:
225-
linker_script = 'link.lds'
226-
items = env['LINKFLAGS'].split(' ')
227-
if '-T' in items:
228-
linker_script = items[items.index('-T') + 1]
229-
linker_script = ConverToRttEclipsePathFormat(linker_script)
230-
231-
listOptionValue = option.find('listOptionValue')
232-
if listOptionValue != None:
233-
listOptionValue.set('value', linker_script)
234-
else:
235-
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': linker_script})
236-
237-
# scriptfile in stm32cubeIDE
238-
if option.get('id').find('c.linker.option.script') != -1:
239-
items = env['LINKFLAGS'].split(' ')
240-
if '-T' in items:
241-
linker_script = ConverToRttEclipsePathFormat(items[items.index('-T') + 1]).strip('"')
242-
option.set('value',linker_script)
243-
244-
# update nostartfiles config
245-
if option.get('id').find('c.linker.nostart') != -1:
246-
if env['LINKFLAGS'].find('-nostartfiles') != -1:
247-
option.set('value', 'true')
248-
else:
249-
option.set('value', 'false')
250-
251-
# update libs
252-
if option.get('id').find('c.linker.libs') != -1 and env.has_key('LIBS'):
253-
# remove old libs
254-
for item in option.findall('listOptionValue'):
255-
option.remove(item)
256-
# add new libs
257-
for lib in env['LIBS']:
258-
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': lib})
259-
260-
# update lib paths
261-
if option.get('id').find('c.linker.paths') != -1 and env.has_key('LIBPATH'):
262-
# remove old lib paths
263-
for item in option.findall('listOptionValue'):
264-
option.remove(item)
265-
# add new old lib paths
266-
for path in env['LIBPATH']:
267-
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': path})
214+
file_tail = '\n#endif /*RTCONFIG_PREINC_H__*/\n'
215+
rtt_pre_inc_item = '"${workspace_loc:/${ProjName}/rtconfig_preinc.h}"'
216+
# save the CPPDEFINES in to rtconfig_preinc.h
217+
with open('rtconfig_preinc.h', mode = 'w+') as f:
218+
f.write(file_header)
219+
for cppdef in CPPDEFINES:
220+
f.write("#define " + cppdef + '\n')
221+
f.write(file_tail)
222+
# change the c.compiler.include.files
223+
files = option.findall('listOptionValue')
224+
find_ok = False
225+
for item in files:
226+
if item.get('value') == rtt_pre_inc_item:
227+
find_ok = True
228+
break
229+
if find_ok is False:
230+
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': rtt_pre_inc_item})
231+
elif compile_defs_option is not None :
232+
option = compile_defs_option
233+
defs = option.findall('listOptionValue')
234+
project_defs = []
235+
for item in defs:
236+
if reset is True:
237+
# clean all old configuration
238+
option.remove(item)
239+
else:
240+
project_defs += [item.get('value')]
241+
if len(project_defs) > 0:
242+
cproject_defs = set(CPPDEFINES) - set(project_defs)
243+
else:
244+
cproject_defs = CPPDEFINES
245+
246+
# print('c.compiler.defs')
247+
cproject_defs = sorted(cproject_defs)
248+
for item in cproject_defs:
249+
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item})
250+
251+
# update linker script config
252+
if linker_scriptfile_option is not None :
253+
option = linker_scriptfile_option
254+
linker_script = 'link.lds'
255+
items = env['LINKFLAGS'].split(' ')
256+
if '-T' in items:
257+
linker_script = items[items.index('-T') + 1]
258+
linker_script = ConverToRttEclipsePathFormat(linker_script)
259+
260+
listOptionValue = option.find('listOptionValue')
261+
if listOptionValue != None:
262+
listOptionValue.set('value', linker_script)
263+
else:
264+
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': linker_script})
265+
# scriptfile in stm32cubeIDE
266+
if linker_script_option is not None :
267+
option = linker_script_option
268+
items = env['LINKFLAGS'].split(' ')
269+
if '-T' in items:
270+
linker_script = ConverToRttEclipsePathFormat(items[items.index('-T') + 1]).strip('"')
271+
option.set('value', linker_script)
272+
# update nostartfiles config
273+
if linker_nostart_option is not None :
274+
option = linker_nostart_option
275+
if env['LINKFLAGS'].find('-nostartfiles') != -1:
276+
option.set('value', 'true')
277+
else:
278+
option.set('value', 'false')
279+
# update libs
280+
if linker_libs_option is not None :
281+
option = linker_libs_option
282+
# remove old libs
283+
for item in option.findall('listOptionValue'):
284+
option.remove(item)
285+
# add new libs
286+
for lib in env['LIBS']:
287+
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': lib})
288+
# update lib paths
289+
if linker_paths_option is not None :
290+
option = linker_paths_option
291+
# remove old lib paths
292+
for item in option.findall('listOptionValue'):
293+
option.remove(item)
294+
# add new old lib paths
295+
for path in env['LIBPATH']:
296+
SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': path})
268297

269298
return
270299

0 commit comments

Comments
 (0)