12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ import glob
16
+ import logging
15
17
import os
16
18
import shlex
17
19
import subprocess
@@ -78,7 +80,7 @@ def FlashBundleName(self):
78
80
elif self == Efr32App .PUMP :
79
81
return 'pump_app.flashbundle.txt'
80
82
elif self == Efr32App .UNIT_TEST :
81
- return ' efr32_device_tests.flashbundle.txt'
83
+ return os . path . join ( 'tests' , ' efr32_device_tests.flashbundle.txt')
82
84
else :
83
85
raise Exception ('Unknown app type: %r' % self )
84
86
@@ -259,13 +261,44 @@ def __init__(self,
259
261
def GnBuildArgs (self ):
260
262
return self .extra_gn_options
261
263
264
+ def _bundle (self ):
265
+ # Only unit-test needs to generate the flashbundle here. All other examples will generate a flashbundle via the silabs_executable template.
266
+ if self .app == Efr32App .UNIT_TEST :
267
+ flash_bundle_path = os .path .join (self .output_dir , self .app .FlashBundleName ())
268
+ logging .info (f'Generating flashbundle { flash_bundle_path } ' )
269
+
270
+ patterns = [
271
+ os .path .join (self .output_dir , "tests" , "*.flash.py" ),
272
+ os .path .join (self .output_dir , "tests" , "*.s37" ),
273
+ os .path .join (self .output_dir , "tests" , "silabs_firmware_utils.py" ),
274
+ os .path .join (self .output_dir , "tests" , "firmware_utils.py" ),
275
+ ]
276
+
277
+ # Generate the list of files by globbing each pattern.
278
+ files = []
279
+ for pattern in patterns :
280
+ files += list (map (lambda x : os .path .basename (x ), glob .glob (pattern )))
281
+
282
+ # Create the bundle file.
283
+ with open (flash_bundle_path , 'w' ) as bundle_file :
284
+ bundle_file .write ("\n " .join (files ))
285
+
262
286
def build_outputs (self ):
263
287
extensions = ["out" , "hex" ]
264
288
if self .options .enable_link_map_file :
265
289
extensions .append ("out.map" )
266
- for ext in extensions :
267
- name = f"{ self .app .AppNamePrefix ()} .{ ext } "
268
- yield BuilderOutput (os .path .join (self .output_dir , name ), name )
290
+
291
+ if self .app == Efr32App .UNIT_TEST :
292
+ # Efr32 unit-test generates the "tests" subdir with a set of files for each individual unit test source.
293
+ for ext in extensions :
294
+ pattern = os .path .join (self .output_dir , "tests" , f"*.{ ext } " )
295
+ for name in map (lambda x : os .path .basename (x ), glob .glob (pattern )):
296
+ yield BuilderOutput (os .path .join (self .output_dir , "tests" , name ), name )
297
+ else :
298
+ # All other examples have just one set of files.
299
+ for ext in extensions :
300
+ name = f"{ self .app .AppNamePrefix ()} .{ ext } "
301
+ yield BuilderOutput (os .path .join (self .output_dir , name ), name )
269
302
270
303
if self .app == Efr32App .UNIT_TEST :
271
304
# Include test runner python wheels
@@ -275,11 +308,17 @@ def build_outputs(self):
275
308
os .path .join (root , file ),
276
309
os .path .join ("chip_pw_test_runner_wheels" , file ))
277
310
278
- # Figure out flash bundle files and build accordingly
311
+ def bundle_outputs (self ):
312
+ # If flashbundle creation is enabled, the outputs will include the s37 and flash.py files, plus the two firmware utils scripts that support flash.py.
313
+ # For the unit-test example, there will be a s37 and flash.py file for each unit test source.
279
314
with open (os .path .join (self .output_dir , self .app .FlashBundleName ())) as f :
280
315
for name in filter (None , [x .strip () for x in f .readlines ()]):
316
+ if self .app == Efr32App .UNIT_TEST :
317
+ sourcepath = os .path .join (self .output_dir , "tests" , name ) # Unit tests are in the "tests" subdir.
318
+ else :
319
+ sourcepath = os .path .join (self .output_dir , name )
281
320
yield BuilderOutput (
282
- os . path . join ( self . output_dir , name ) ,
321
+ sourcepath ,
283
322
os .path .join ("flashbundle" , name ))
284
323
285
324
def generate (self ):
0 commit comments