@@ -80,6 +80,25 @@ def get_file_element(file_name, virtual_dir, common_prefix, parent_dir, path_typ
8080 return generate_link_element (name , path , path_type = path_type )
8181
8282
83+ def generate_st_linker_option ():
84+ ele = ET .fromstring ( # noqa: S314
85+ """
86+ <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.otherflags" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.otherflags" valueType="stringList">
87+ \t \t \t \t \t \t \t \t \t </option>
88+ """
89+ )
90+ ele .tail = "\n \t \t \t \t \t \t \t \t "
91+ return ele
92+
93+
94+ def generate_st_build_id_flag ():
95+ ele = ET .fromstring ( # noqa: S314
96+ """<listOptionValue builtIn="false" value="-Wl,--build-id" />"""
97+ )
98+ ele .tail = "\n \t \t \t \t \t \t \t \t q"
99+ return ele
100+
101+
83102def recursive_glob_backport (dir_glob ):
84103 # Find first directory wildcard and walk the tree from there
85104 glob_root = dir_glob .split ("/*" )[0 ]
@@ -272,6 +291,8 @@ def _find_include_nodes(option):
272291 "ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths" ,
273292 # this is the element id used by NXP's MCUXpresso IDE
274293 "gnu.c.compiler.option.include.paths" ,
294+ # Element used by ST's STM32Cube IDE for include path enumeration
295+ "com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths" ,
275296 ))
276297
277298 memfault_sdk_include_paths = [
@@ -294,12 +315,54 @@ def _find_include_nodes(option):
294315 ele .tail = tail
295316 include_option .append (ele )
296317
318+ #
319+ # Add GNU build id to STM32Cube IDE based projects
320+ #
321+
322+ def _find_st_linker_tools (tool ):
323+ return tool .get ("id" , "" ).startswith (
324+ # Element used by ST's STM32Cube IDE for linker arguments
325+ "com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker" ,
326+ )
327+
328+ def _find_st_linker_options (option ):
329+ return option .get ("id" , "" ).startswith (
330+ "com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.otherflags"
331+ )
332+
333+ def _find_st_build_id_linker_flag (option ):
334+ return "--build-id" in option .get ("value" , "" )
335+
336+ tools = root .findall (".//tool" )
337+ linker_tools = filter (_find_st_linker_tools , tools )
338+ for linker_tool in linker_tools :
339+ all_linker_options = linker_tool .findall (".//option" )
340+
341+ linker_options = filter (_find_st_linker_options , all_linker_options )
342+ if len (list (linker_options )) != 0 :
343+ continue
344+
345+ ele = generate_st_linker_option ()
346+ linker_tool .insert (0 , ele )
347+
348+ # reload all linker options and now add the flag itself
349+ linker_options = filter (_find_st_linker_options , linker_tool .findall (".//option" ))
350+ for linker_option in linker_options :
351+ linker_flags = filter (
352+ _find_st_build_id_linker_flag , linker_option .findall (".//listOptionValue" )
353+ )
354+ if len (list (linker_flags )) != 0 :
355+ continue
356+ ele = generate_st_build_id_flag ()
357+ linker_option .insert (0 , ele )
358+
297359 #
298360 # Add GNU build id generation for all build configurations:
299361 #
300362
301363 def _find_linker_flags (option ):
302364 return option .get ("id" , "" ).startswith (
365+ # Element used by Dialog's Smart Snippets Studio IDE
303366 "ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.other"
304367 ) and option .get ("name" , "" ).startswith ("Other linker flags" )
305368
0 commit comments