3131# Marker type for an 'append:' configuration. Maps variables
3232# to the list of values to append to them.
3333Appends = Dict [str , List [str ]]
34+ BoardRevisionAppends = Dict [str , Dict [str , List [str ]]]
3435
3536def _new_append ():
3637 return defaultdict (list )
3738
3839def _new_board2appends ():
39- return defaultdict (_new_append )
40+ return defaultdict (lambda : defaultdict ( _new_append ) )
4041
4142@dataclass
4243class Snippet :
@@ -45,7 +46,7 @@ class Snippet:
4546
4647 name : str
4748 appends : Appends = field (default_factory = _new_append )
48- board2appends : Dict [str , Appends ] = field (default_factory = _new_board2appends )
49+ board2appends : Dict [str , BoardRevisionAppends ] = field (default_factory = _new_board2appends )
4950
5051 def process_data (self , pathobj : Path , snippet_data : dict , sysbuild : bool ):
5152 '''Process the data in a snippet.yml file, after it is loaded into a
@@ -68,10 +69,16 @@ def append_value(variable, value):
6869 if board .startswith ('/' ) and not board .endswith ('/' ):
6970 _err (f"snippet file { pathobj } : board { board } starts with '/', so "
7071 "it must end with '/' to use a regular expression" )
72+ for revision , appenddata in settings .get ('revisions' , {}).items ():
73+ for variable , value in appenddata .get ('append' , {}).items ():
74+ if (sysbuild is True and variable [0 :3 ] == 'SB_' ) or \
75+ (sysbuild is False and variable [0 :3 ] != 'SB_' ):
76+ self .board2appends [board ][revision ][variable ].append (
77+ append_value (variable , value ))
7178 for variable , value in settings .get ('append' , {}).items ():
7279 if (sysbuild is True and variable [0 :3 ] == 'SB_' ) or \
7380 (sysbuild is False and variable [0 :3 ] != 'SB_' ):
74- self .board2appends [board ][variable ].append (
81+ self .board2appends [board ]["" ][ variable ].append (
7582 append_value (variable , value ))
7683
7784class Snippets (UserDict ):
@@ -167,7 +174,18 @@ def print_appends_for_board(self, board: str, appends: Appends):
167174 self .print (f'''\
168175 # Appends for board '{ board } '
169176if("${{BOARD}}${{BOARD_QUALIFIERS}}" STREQUAL "{ board } ")''' )
170- self .print_appends (appends , 1 )
177+
178+ # Output board variables first then board revision variables
179+ self .print_appends (appends ["" ], 1 )
180+
181+ for revision in appends :
182+ if revision != "" :
183+ self .print (f'''\
184+ # Appends for revision '{ revision } '
185+ if("${{BOARD_REVISION}}" STREQUAL "{ revision } ")''' )
186+ self .print_appends (appends [revision ], 2 )
187+ self .print (' endif()' )
188+
171189 self .print ('endif()' )
172190
173191 def print_appends (self , appends : Appends , indent : int ):
0 commit comments