22#
33# SPDX-License-Identifier: Apache-2.0
44
5+ from itertools import count
56import re
67import sys
78import subprocess
@@ -34,6 +35,10 @@ def __init__(self, app):
3435 self .app_version = ''
3536 # App readme
3637 self .readme = ''
38+ # App description
39+ self .description = ''
40+ # App SDK count
41+ self .sdkcount = ''
3742
3843current_app = App (None )
3944
@@ -118,26 +123,39 @@ def remove_app_from_config(apps):
118123 new_apps = []
119124 for app in apps :
120125 # remove './' in string
121- app_dir = app ['app_dir' ][2 :]
126+ if app ['app_dir' ].startswith ('./' ):
127+ app_dir = app ['app_dir' ][2 :]
128+ else :
129+ app_dir = app ['app_dir' ]
130+
122131 if app_dir not in config_apps :
123132 continue
124133
125134 example = config_apps [app_dir ]
126135 matched_build_info = []
136+ sdkcount = {}
127137 for build_info in app ['build_info' ]:
128138 target = build_info .get ('target' )
129139 if (
130140 example .get (target ) and
131141 build_info .get ('sdkconfig' ) in example .get (target , {}).get ('sdkconfig' , [])
132142 ):
143+ if build_info .get ('sdkconfig' ) == 'defaults' :
144+ build_info ['sdkconfig' ] = target + '_generic'
133145 matched_build_info .append (build_info )
146+
147+ if not sdkcount .get (f'developKits.{ target } ' ):
148+ sdkcount [f'developKits.{ target } ' ] = 1
149+ else :
150+ sdkcount [f'developKits.{ target } ' ] += 1
134151 if matched_build_info :
135152 app ['build_info' ] = matched_build_info
153+ app ['sdkcount' ] = sdkcount
136154 if config_apps [app_dir ].get ('readme' ):
137- print (config_apps [app_dir ]['readme' ])
138155 app ['readme' ] = config_apps [app_dir ]['readme' ]
156+ if config_apps [app_dir ].get ('description' ):
157+ app ['description' ] = config_apps [app_dir ]['description' ]
139158 new_apps .append (app )
140-
141159 return new_apps
142160
143161# Squash the json into a list of apps
@@ -183,6 +201,9 @@ def merge_binaries(apps):
183201 build_dirs = build_info ['build_dir' ]
184202 idf_version = build_info ['idf_version' ]
185203 app_version = app ['app_version' ]
204+ sdkcount = app ['sdkcount' ]
205+ if sdkcount .get (f'developKits.{ target } ' ) == 1 :
206+ sdkconfig = ''
186207 bin_name = f'{ app ["name" ]} -{ target } ' + (f'-{ sdkconfig } ' if sdkconfig else '' ) + (f'-{ app_version } ' if app_version else '' ) + (f'-{ idf_version } ' if idf_version else '' ) + '.bin'
187208 cmd = ['esptool.py' , '--chip' , target , 'merge_bin' , '-o' , bin_name , '@flash_args' ]
188209 cwd = os .path .join (app .get ('app_dir' ), build_dirs )
@@ -204,22 +225,38 @@ def merge_binaries(apps):
204225def write_app (app ):
205226 # If we are working with kits
206227 for build_info in app ['build_info' ]:
228+ target = build_info ['target' ]
229+ sdkconfig = build_info ['sdkconfig' ]
207230 idf_version = build_info ['idf_version' ]
208231 app_version = app ['app_version' ]
209- sdkconfig = build_info ['sdkconfig' ]
210- bin_name = f'{ app ["name" ]} -{ build_info ["target" ]} ' + (f'-{ sdkconfig } ' if sdkconfig else '' ) + (f'-{ app_version } ' if app_version else '' ) + (f'-{ idf_version } ' if idf_version else '' ) + '.bin'
232+ sdkcount = app ['sdkcount' ]
233+ if sdkcount .get (f'developKits.{ target } ' ) == 1 :
234+ sdkconfig = ''
235+ bin_name = f'{ app ["name" ]} -{ target } ' + (f'-{ sdkconfig } ' if sdkconfig else '' ) + (f'-{ app_version } ' if app_version else '' ) + (f'-{ idf_version } ' if idf_version else '' ) + '.bin'
211236 support_app = f'{ app ["name" ]} '
212237 if not toml_obj .get (support_app ):
213238 toml_obj [support_app ] = {}
214239 toml_obj [support_app ]['android_app_url' ] = ''
215240 toml_obj [support_app ]['ios_app_url' ] = ''
216241 if app .get ('readme' ):
217242 toml_obj [support_app ]['readme.text' ] = app ['readme' ]
243+ if app .get ('description' ):
244+ toml_obj [support_app ]['description' ] = app ['description' ]
245+
218246 if not toml_obj [support_app ].get ('chipsets' ):
219- toml_obj [support_app ]['chipsets' ] = [f'{ build_info ["target" ]} -{ build_info ["sdkconfig" ]} ' ]
247+ toml_obj [support_app ]['chipsets' ] = [f'{ target } ' ]
248+ elif f'{ target } ' not in toml_obj [support_app ]['chipsets' ]:
249+ toml_obj [support_app ]['chipsets' ].append (f'{ target } ' )
250+
251+ if sdkcount .get (f'developKits.{ target } ' ) > 1 :
252+ if not toml_obj [support_app ].get (f'developKits.{ target } ' ):
253+ toml_obj [support_app ][f'developKits.{ target } ' ] = [f'{ sdkconfig } ' ]
254+ else :
255+ toml_obj [support_app ][f'developKits.{ target } ' ].append (f'{ sdkconfig } ' )
256+ if sdkcount .get (f'developKits.{ target } ' ) == 1 :
257+ toml_obj [support_app ][f'image.{ target } ' ] = bin_name
220258 else :
221- toml_obj [support_app ]['chipsets' ].append (f'{ build_info ["target" ]} -{ build_info ["sdkconfig" ]} ' )
222- toml_obj [support_app ][f'image.{ build_info ["target" ]} -{ build_info ["sdkconfig" ]} ' ] = bin_name
259+ toml_obj [support_app ][f'image.{ sdkconfig } ' ] = bin_name
223260
224261# Create the config.toml file
225262def create_config_toml (apps ):
@@ -232,14 +269,14 @@ def create_config_toml(apps):
232269
233270 # This is a workaround to remove the quotes around the image.<string> in the config.toml file as dot is not allowed in the key by default
234271 with open ('binaries/config.toml' , 'r' ) as toml_file :
235- fixed = replace_image_and_readme_string (toml_file .read ())
272+ fixed = unquote_config_keys (toml_file .read ())
236273
237274 with open ('binaries/config.toml' , 'w' ) as toml_file :
238275 toml_file .write (fixed )
239276
240- def replace_image_and_readme_string (text ):
277+ def unquote_config_keys (text ):
241278 # Define the regular expression pattern to find "image.<string>"
242- pattern = r'"((image|readme)\.[\w-]+)"'
279+ pattern = r'"((image|readme|developKits )\.[\w-]+)"'
243280 # Use re.sub() to replace the matched pattern with image.<string>
244281 result = re .sub (pattern , r'\1' , text )
245282 return result
0 commit comments