@@ -394,33 +394,145 @@ def build_library(src_paths, build_path, target, toolchain_name,
394
394
# Let Exception propagate
395
395
raise e
396
396
397
- def build_lib (lib_id , target , toolchain , options = None , verbose = False , clean = False , macros = None , notify = None , jobs = 1 , silent = False , report = None , properties = None , extra_verbose = False ):
398
- """ Wrapper for build_library function.
397
+ ######################
398
+ ### Legacy methods ###
399
+ ######################
400
+
401
+ def build_lib (lib_id , target , toolchain_name , options = None , verbose = False , clean = False , macros = None , notify = None , jobs = 1 , silent = False , report = None , properties = None , extra_verbose = False ):
402
+ """ Legacy method for building mbed libraries
399
403
Function builds library in proper directory using all dependencies and macros defined by user.
400
404
"""
401
405
lib = Library (lib_id )
402
- if lib .is_supported (target , toolchain ):
403
- # We need to combine macros from parameter list with macros from library definition
404
- MACROS = lib .macros if lib .macros else []
405
- if macros :
406
- MACROS .extend (macros )
407
-
408
- return build_library (lib .source_dir , lib .build_dir , target , toolchain , lib .dependencies , options ,
409
- verbose = verbose ,
410
- silent = silent ,
411
- clean = clean ,
412
- macros = MACROS ,
413
- notify = notify ,
414
- inc_dirs = lib .inc_dirs ,
415
- inc_dirs_ext = lib .inc_dirs_ext ,
416
- jobs = jobs ,
417
- report = report ,
418
- properties = properties ,
419
- extra_verbose = extra_verbose )
420
- else :
406
+ if not lib .is_supported (target , toolchain_name ):
421
407
print 'Library "%s" is not yet supported on target %s with toolchain %s' % (lib_id , target .name , toolchain )
422
408
return False
409
+
410
+ # We need to combine macros from parameter list with macros from library definition
411
+ MACROS = lib .macros if lib .macros else []
412
+ if macros :
413
+ macros .extend (MACROS )
414
+ else :
415
+ macros = MACROS
416
+
417
+ src_paths = lib .source_dir
418
+ build_path = lib .build_dir
419
+ dependencies_paths = lib .dependencies
420
+ inc_dirs = lib .inc_dirs
421
+ inc_dirs_ext = lib .inc_dirs_ext
422
+
423
+ """ src_path: the path of the source directory
424
+ build_path: the path of the build directory
425
+ target: ['LPC1768', 'LPC11U24', 'LPC2368']
426
+ toolchain: ['ARM', 'uARM', 'GCC_ARM', 'GCC_CR']
427
+ library_paths: List of paths to additional libraries
428
+ clean: Rebuild everything if True
429
+ notify: Notify function for logs
430
+ verbose: Write the actual tools command lines if True
431
+ inc_dirs: additional include directories which should be included in build
432
+ inc_dirs_ext: additional include directories which should be copied to library directory
433
+ """
434
+ if type (src_paths ) != ListType :
435
+ src_paths = [src_paths ]
436
+
437
+ # The first path will give the name to the library
438
+ name = basename (src_paths [0 ])
439
+
440
+ if report != None :
441
+ start = time ()
442
+ id_name = name .upper ()
443
+ description = name
444
+ vendor_label = target .extra_labels [0 ]
445
+ cur_result = None
446
+ prep_report (report , target .name , toolchain_name , id_name )
447
+ cur_result = create_result (target .name , toolchain_name , id_name , description )
423
448
449
+ if properties != None :
450
+ prep_properties (properties , target .name , toolchain_name , vendor_label )
451
+
452
+ for src_path in src_paths :
453
+ if not exists (src_path ):
454
+ error_msg = "The library source folder does not exist: %s" , src_path
455
+
456
+ if report != None :
457
+ cur_result ["output" ] = error_msg
458
+ cur_result ["result" ] = "FAIL"
459
+ add_result_to_report (report , cur_result )
460
+
461
+ raise Exception (error_msg )
462
+
463
+ try :
464
+ # Toolchain instance
465
+ toolchain = TOOLCHAIN_CLASSES [toolchain_name ](target , options , macros = macros , notify = notify , silent = silent , extra_verbose = extra_verbose )
466
+ toolchain .VERBOSE = verbose
467
+ toolchain .jobs = jobs
468
+ toolchain .build_all = clean
469
+
470
+ toolchain .info ("Building library %s (%s, %s)" % (name .upper (), target .name , toolchain_name ))
471
+
472
+ # Scan Resources
473
+ resources = []
474
+ for src_path in src_paths :
475
+ resources .append (toolchain .scan_resources (src_path ))
476
+
477
+ # Add extra include directories / files which are required by library
478
+ # This files usually are not in the same directory as source files so
479
+ # previous scan will not include them
480
+ if inc_dirs_ext is not None :
481
+ for inc_ext in inc_dirs_ext :
482
+ resources .append (toolchain .scan_resources (inc_ext ))
483
+
484
+ # Dependencies Include Paths
485
+ dependencies_include_dir = []
486
+ if dependencies_paths is not None :
487
+ for path in dependencies_paths :
488
+ lib_resources = toolchain .scan_resources (path )
489
+ dependencies_include_dir .extend (lib_resources .inc_dirs )
490
+
491
+ if inc_dirs :
492
+ dependencies_include_dir .extend (inc_dirs )
493
+
494
+ # Create the desired build directory structure
495
+ bin_path = join (build_path , toolchain .obj_path )
496
+ mkdir (bin_path )
497
+ tmp_path = join (build_path , '.temp' , toolchain .obj_path )
498
+ mkdir (tmp_path )
499
+
500
+ # Copy Headers
501
+ for resource in resources :
502
+ toolchain .copy_files (resource .headers , build_path , rel_path = resource .base_path )
503
+ dependencies_include_dir .extend (toolchain .scan_resources (build_path ).inc_dirs )
504
+
505
+ # Compile Sources
506
+ objects = []
507
+ for resource in resources :
508
+ objects .extend (toolchain .compile_sources (resource , tmp_path , dependencies_include_dir ))
509
+
510
+ needed_update = toolchain .build_library (objects , bin_path , name )
511
+
512
+ if report != None and needed_update :
513
+ end = time ()
514
+ cur_result ["elapsed_time" ] = end - start
515
+ cur_result ["output" ] = toolchain .get_output ()
516
+ cur_result ["result" ] = "OK"
517
+
518
+ add_result_to_report (report , cur_result )
519
+
520
+ except Exception , e :
521
+ if report != None :
522
+ end = time ()
523
+ cur_result ["result" ] = "FAIL"
524
+ cur_result ["elapsed_time" ] = end - start
525
+
526
+ toolchain_output = toolchain .get_output ()
527
+ if toolchain_output :
528
+ cur_result ["output" ] += toolchain_output
529
+
530
+ cur_result ["output" ] += str (e )
531
+
532
+ add_result_to_report (report , cur_result )
533
+
534
+ # Let Exception propagate
535
+ raise e
424
536
425
537
# We do have unique legacy conventions about how we build and package the mbed library
426
538
def build_mbed_libs (target , toolchain_name , options = None , verbose = False , clean = False , macros = None , notify = None , jobs = 1 , silent = False , report = None , properties = None , extra_verbose = False ):
@@ -543,6 +655,7 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=F
543
655
# Let Exception propagate
544
656
raise e
545
657
658
+
546
659
def get_unique_supported_toolchains ():
547
660
""" Get list of all unique toolchains supported by targets """
548
661
unique_supported_toolchains = []
0 commit comments