@@ -122,61 +122,100 @@ def ExcludePaths(rootpath, paths):
122122 return ret
123123
124124
125- def ConverToEclipsePathFormat (path ):
126- if path .startswith ('.' ):
127- path = path [1 :]
128- return '"${workspace_loc:/${ProjName}/' + path + '}"'
125+ rtt_path_prefix = '"${workspace_loc://${ProjName}//'
126+
127+
128+ def ConverToRttEclipsePathFormat (path ):
129+ return rtt_path_prefix + path + '}"'
130+
131+
132+ def IsRttEclipsePathFormat (path ):
133+ if path .startswith (rtt_path_prefix ):
134+ return True
135+ else :
136+ return False
129137
130138
131139def HandleToolOption (tools , env , project , reset ):
132140 BSP_ROOT = os .path .abspath (env ['BSP_ROOT' ])
133141
134142 CPPDEFINES = project ['CPPDEFINES' ]
135- paths = [ConverToEclipsePathFormat (RelativeProjectPath (env , os .path .normpath (i )).replace ('\\ ' , '/' )) for i in project ['CPPPATH' ]]
143+ paths = [ConverToRttEclipsePathFormat (RelativeProjectPath (env , os .path .normpath (i )).replace ('\\ ' , '/' )) for i in project ['CPPPATH' ]]
136144
137145 for tool in tools :
138146 if tool .get ('id' ).find ('c.compile' ) != 1 :
139147 options = tool .findall ('option' )
148+ include_paths_option = None
149+ include_files_option = None
150+ defs_option = None
151+ # find all compile options
140152 for option in options :
141153 if option .get ('id' ).find ('c.compiler.include.paths' ) != - 1 or option .get ('id' ).find ('c.compiler.option.includepaths' ) != - 1 :
142- # find all of paths in this project
143- include_paths = option .findall ('listOptionValue' )
144- project_paths = []
145- for item in include_paths :
146- if reset is True :
147- # clean all old configuration
148- option .remove (item )
149- else :
150- project_paths += [item .get ('value' )]
151-
152- if len (project_paths ) > 0 :
153- cproject_paths = set (paths ) - set (project_paths )
154- else :
155- cproject_paths = paths
156-
157- # print('c.compiler.include.paths')
158- cproject_paths = sorted (cproject_paths )
159- for item in cproject_paths :
160- SubElement (option , 'listOptionValue' , {'builtIn' : 'false' , 'value' : item })
161-
162- if option .get ('id' ).find ('c.compiler.defs' ) != - 1 or option .get ('id' ).find ('c.compiler.option.definedsymbols' ) != - 1 :
163- defs = option .findall ('listOptionValue' )
164- project_defs = []
165- for item in defs :
166- if reset is True :
167- # clean all old configuration
168- option .remove (item )
169- else :
170- project_defs += [item .get ('value' )]
171- if len (project_defs ) > 0 :
172- cproject_defs = set (CPPDEFINES ) - set (project_defs )
154+ include_paths_option = option
155+ 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
157+ 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 = '''
176+ #ifndef RTCONFIG_PREINC_H__
177+ #define RTCONFIG_PREINC_H__
178+
179+ /* Automatically generated file; DO NOT EDIT. */
180+ /* RT-Thread pre-include file */
181+
182+ '''
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 )
173208 else :
174- cproject_defs = CPPDEFINES
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
175214
176- # print('c.compiler.defs')
177- cproject_defs = sorted (cproject_defs )
178- for item in cproject_defs :
179- SubElement (option , 'listOptionValue' , {'builtIn' : 'false' , 'value' : item })
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 })
180219
181220 if tool .get ('id' ).find ('c.linker' ) != - 1 :
182221 options = tool .findall ('option' )
@@ -187,7 +226,7 @@ def HandleToolOption(tools, env, project, reset):
187226 items = env ['LINKFLAGS' ].split (' ' )
188227 if '-T' in items :
189228 linker_script = items [items .index ('-T' ) + 1 ]
190- linker_script = ConverToEclipsePathFormat (linker_script )
229+ linker_script = ConverToRttEclipsePathFormat (linker_script )
191230
192231 listOptionValue = option .find ('listOptionValue' )
193232 if listOptionValue != None :
@@ -199,7 +238,7 @@ def HandleToolOption(tools, env, project, reset):
199238 if option .get ('id' ).find ('c.linker.option.script' ) != - 1 :
200239 items = env ['LINKFLAGS' ].split (' ' )
201240 if '-T' in items :
202- linker_script = ConverToEclipsePathFormat (items [items .index ('-T' ) + 1 ]).strip ('"' )
241+ linker_script = ConverToRttEclipsePathFormat (items [items .index ('-T' ) + 1 ]).strip ('"' )
203242 option .set ('value' ,linker_script )
204243
205244 # update nostartfiles config
@@ -262,6 +301,7 @@ def UpdateProjectStructure(env, prj_name):
262301
263302 return
264303
304+
265305def GenExcluding (env , project ):
266306 rtt_root = os .path .abspath (env ['RTT_ROOT' ])
267307 bsp_root = os .path .abspath (env ['BSP_ROOT' ])
@@ -273,7 +313,17 @@ def GenExcluding(env, project):
273313 exclude_paths = ExcludePaths (rtt_root , all_paths )
274314 elif rtt_root .startswith (bsp_root ):
275315 # RT-Thread root folder is in the bsp folder, such as project folder which generate by 'scons --dist' cmd
276- exclude_paths = ExcludePaths (bsp_root , all_paths )
316+ check_path = []
317+ exclude_paths = []
318+ # analyze the primary folder which relative to BSP_ROOT and in all_paths
319+ for path in all_paths :
320+ if path .startswith (bsp_root ) :
321+ folders = RelativeProjectPath (env , path ).split ('\\ ' )
322+ if folders [0 ] != '.' and '\\ ' + folders [0 ] not in check_path :
323+ check_path += ['\\ ' + folders [0 ]]
324+ # exclue the folder which has managed by scons
325+ for path in check_path :
326+ exclude_paths += ExcludePaths (bsp_root + path , all_paths )
277327 else :
278328 exclude_paths = ExcludePaths (rtt_root , all_paths )
279329 exclude_paths += ExcludePaths (bsp_root , all_paths )
@@ -292,15 +342,16 @@ def GenExcluding(env, project):
292342 exclude_paths += [path ]
293343
294344 exclude_paths = [RelativeProjectPath (env , path ).replace ('\\ ' , '/' ) for path in exclude_paths ]
295- env ['ExPaths' ] = exclude_paths
296345
297346 all_files = CollectFiles (all_paths , source_pattern )
298347 src_files = project ['FILES' ]
299348
300349 exclude_files = ExcludeFiles (all_files , src_files )
301350 exclude_files = [RelativeProjectPath (env , file ).replace ('\\ ' , '/' ) for file in exclude_files ]
351+
352+ env ['ExPaths' ] = exclude_paths
302353 env ['ExFiles' ] = exclude_files
303-
354+
304355 return exclude_paths + exclude_files
305356
306357
@@ -315,7 +366,7 @@ def RelativeProjectPath(env, path):
315366 return 'rt-thread/' + _make_path_relative (rtt_root , path )
316367
317368 # TODO add others folder
318- print ('ERROR: the ' + path + 'not support' )
369+ print ('ERROR: the ' + path + ' not support' )
319370
320371 return path
321372
0 commit comments