Skip to content

Commit 72beee7

Browse files
committed
Refactor notification logic into it's own class
1 parent b033a6e commit 72beee7

File tree

5 files changed

+241
-206
lines changed

5 files changed

+241
-206
lines changed

tools/build_api.py

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,8 @@ def get_mbed_official_release(version):
292292

293293
def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
294294
macros=None, clean=False, jobs=1,
295-
notify=None, silent=False, verbose=False,
296-
extra_verbose=False, config=None,
297-
app_config=None, build_profile=None):
295+
notify=None, config=None, app_config=None,
296+
build_profile=None):
298297
""" Prepares resource related objects - toolchain, target, config
299298
300299
Positional arguments:
@@ -307,9 +306,6 @@ def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
307306
clean - Rebuild everything if True
308307
jobs - how many compilers we can run at once
309308
notify - Notify function for logs
310-
silent - suppress printing of progress indicators
311-
verbose - Write the actual tools command lines used if True
312-
extra_verbose - even more output!
313309
config - a Config object to use instead of creating one
314310
app_config - location of a chosen mbed_app.json file
315311
build_profile - a list of mergeable build profiles
@@ -332,13 +328,12 @@ def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
332328
for key in profile:
333329
profile[key].extend(contents[toolchain_name].get(key, []))
334330

335-
toolchain = cur_tc(target, notify, macros, silent, build_dir=build_dir,
336-
extra_verbose=extra_verbose, build_profile=profile)
331+
toolchain = cur_tc(
332+
target, notify, macros, build_dir=build_dir, build_profile=profile)
337333

338334
toolchain.config = config
339335
toolchain.jobs = jobs
340336
toolchain.build_all = clean
341-
toolchain.VERBOSE = verbose
342337

343338
return toolchain
344339

@@ -489,11 +484,10 @@ def scan_resources(src_paths, toolchain, dependencies_paths=None,
489484
return resources
490485

491486
def build_project(src_paths, build_path, target, toolchain_name,
492-
libraries_paths=None, linker_script=None,
493-
clean=False, notify=None, verbose=False, name=None,
494-
macros=None, inc_dirs=None, jobs=1, silent=False,
487+
libraries_paths=None, linker_script=None, clean=False, silent=False,
488+
notify=None, name=None, macros=None, inc_dirs=None, jobs=1,
495489
report=None, properties=None, project_id=None,
496-
project_description=None, extra_verbose=False, config=None,
490+
project_description=None, config=None,
497491
app_config=None, build_profile=None, stats_depth=None):
498492
""" Build a project. A project may be a test or a user program.
499493
@@ -509,17 +503,14 @@ def build_project(src_paths, build_path, target, toolchain_name,
509503
linker_script - the file that drives the linker to do it's job
510504
clean - Rebuild everything if True
511505
notify - Notify function for logs
512-
verbose - Write the actual tools command lines used if True
513506
name - the name of the project
514507
macros - additional macros
515508
inc_dirs - additional directories where include files may be found
516509
jobs - how many compilers we can run at once
517-
silent - suppress printing of progress indicators
518510
report - a dict where a result may be appended
519511
properties - UUUUHHHHH beats me
520512
project_id - the name put in the report
521513
project_description - the human-readable version of what this thing does
522-
extra_verbose - even more output!
523514
config - a Config object to use instead of creating one
524515
app_config - location of a chosen mbed_app.json file
525516
build_profile - a dict of flags that will be passed to the compiler
@@ -540,15 +531,14 @@ def build_project(src_paths, build_path, target, toolchain_name,
540531

541532
toolchain = prepare_toolchain(
542533
src_paths, build_path, target, toolchain_name, macros=macros,
543-
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
544-
extra_verbose=extra_verbose, config=config, app_config=app_config,
545-
build_profile=build_profile)
534+
clean=clean, jobs=jobs, notify=notify, config=config,
535+
app_config=app_config, build_profile=build_profile)
546536

547537
# The first path will give the name to the library
548538
name = (name or toolchain.config.name or
549539
basename(normpath(abspath(src_paths[0]))))
550-
toolchain.info("Building project %s (%s, %s)" %
551-
(name, toolchain.target.name, toolchain_name))
540+
notify.info("Building project %s (%s, %s)" %
541+
(name, toolchain.target.name, toolchain_name))
552542

553543
# Initialize reporting
554544
if report != None:
@@ -610,7 +600,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
610600
if report != None:
611601
end = time()
612602
cur_result["elapsed_time"] = end - start
613-
cur_result["output"] = toolchain.get_output() + memap_table
603+
cur_result["output"] = notify.get_output() + memap_table
614604
cur_result["result"] = "OK"
615605
cur_result["memory_usage"] = (memap_instance.mem_report
616606
if memap_instance is not None else None)
@@ -633,7 +623,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
633623

634624
cur_result["elapsed_time"] = end - start
635625

636-
toolchain_output = toolchain.get_output()
626+
toolchain_output = notify.get_output()
637627
if toolchain_output:
638628
cur_result["output"] += toolchain_output
639629

@@ -644,9 +634,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
644634

645635
def build_library(src_paths, build_path, target, toolchain_name,
646636
dependencies_paths=None, name=None, clean=False,
647-
archive=True, notify=None, verbose=False, macros=None,
648-
inc_dirs=None, jobs=1, silent=False, report=None,
649-
properties=None, extra_verbose=False, project_id=None,
637+
archive=True, notify=None, macros=None, inc_dirs=None, jobs=1,
638+
report=None, properties=None, project_id=None,
650639
remove_config_header_file=False, app_config=None,
651640
build_profile=None):
652641
""" Build a library
@@ -664,14 +653,11 @@ def build_library(src_paths, build_path, target, toolchain_name,
664653
clean - Rebuild everything if True
665654
archive - whether the library will create an archive file
666655
notify - Notify function for logs
667-
verbose - Write the actual tools command lines used if True
668656
macros - additional macros
669657
inc_dirs - additional directories where include files may be found
670658
jobs - how many compilers we can run at once
671-
silent - suppress printing of progress indicators
672659
report - a dict where a result may be appended
673660
properties - UUUUHHHHH beats me
674-
extra_verbose - even more output!
675661
project_id - the name that goes in the report
676662
remove_config_header_file - delete config header file when done building
677663
app_config - location of a chosen mbed_app.json file
@@ -698,14 +684,13 @@ def build_library(src_paths, build_path, target, toolchain_name,
698684
# Pass all params to the unified prepare_toolchain()
699685
toolchain = prepare_toolchain(
700686
src_paths, build_path, target, toolchain_name, macros=macros,
701-
clean=clean, jobs=jobs, notify=notify, silent=silent,
702-
verbose=verbose, extra_verbose=extra_verbose, app_config=app_config,
687+
clean=clean, jobs=jobs, notify=notify, app_config=app_config,
703688
build_profile=build_profile)
704689

705690
# The first path will give the name to the library
706691
if name is None:
707692
name = basename(normpath(abspath(src_paths[0])))
708-
toolchain.info("Building library %s (%s, %s)" %
693+
notify.info("Building library %s (%s, %s)" %
709694
(name, toolchain.target.name, toolchain_name))
710695

711696
# Initialize reporting
@@ -770,7 +755,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
770755
if report != None:
771756
end = time()
772757
cur_result["elapsed_time"] = end - start
773-
cur_result["output"] = toolchain.get_output()
758+
cur_result["output"] = notify.get_output()
774759
cur_result["result"] = "OK"
775760

776761

@@ -788,7 +773,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
788773

789774
cur_result["elapsed_time"] = end - start
790775

791-
toolchain_output = toolchain.get_output()
776+
toolchain_output = notify.get_output()
792777
if toolchain_output:
793778
cur_result["output"] += toolchain_output
794779

@@ -805,9 +790,8 @@ def mbed2_obj_path(target_name, toolchain_name):
805790
real_tc_name = TOOLCHAIN_CLASSES[toolchain_name].__name__
806791
return join("TARGET_" + target_name, "TOOLCHAIN_" + real_tc_name)
807792

808-
def build_lib(lib_id, target, toolchain_name, verbose=False,
809-
clean=False, macros=None, notify=None, jobs=1, silent=False,
810-
report=None, properties=None, extra_verbose=False,
793+
def build_lib(lib_id, target, toolchain_name, clean=False, macros=None,
794+
notify=None, jobs=1, report=None, properties=None,
811795
build_profile=None):
812796
""" Legacy method for building mbed libraries
813797
@@ -818,14 +802,11 @@ def build_lib(lib_id, target, toolchain_name, verbose=False,
818802
819803
Keyword arguments:
820804
clean - Rebuild everything if True
821-
verbose - Write the actual tools command lines used if True
822805
macros - additional macros
823806
notify - Notify function for logs
824807
jobs - how many compilers we can run at once
825-
silent - suppress printing of progress indicators
826808
report - a dict where a result may be appended
827809
properties - UUUUHHHHH beats me
828-
extra_verbose - even more output!
829810
build_profile - a dict of flags that will be passed to the compiler
830811
"""
831812
lib = Library(lib_id)
@@ -890,10 +871,9 @@ def build_lib(lib_id, target, toolchain_name, verbose=False,
890871

891872
toolchain = prepare_toolchain(
892873
src_paths, tmp_path, target, toolchain_name, macros=macros,
893-
notify=notify, silent=silent, extra_verbose=extra_verbose,
894-
build_profile=build_profile, jobs=jobs, clean=clean)
874+
notify=notify, build_profile=build_profile, jobs=jobs, clean=clean)
895875

896-
toolchain.info("Building library %s (%s, %s)" %
876+
notify.info("Building library %s (%s, %s)" %
897877
(name.upper(), target.name, toolchain_name))
898878

899879
# Take into account the library configuration (MBED_CONFIG_FILE)
@@ -947,7 +927,7 @@ def build_lib(lib_id, target, toolchain_name, verbose=False,
947927
if report != None and needed_update:
948928
end = time()
949929
cur_result["elapsed_time"] = end - start
950-
cur_result["output"] = toolchain.get_output()
930+
cur_result["output"] = notify.get_output()
951931
cur_result["result"] = "OK"
952932

953933
add_result_to_report(report, cur_result)
@@ -959,7 +939,7 @@ def build_lib(lib_id, target, toolchain_name, verbose=False,
959939
cur_result["result"] = "FAIL"
960940
cur_result["elapsed_time"] = end - start
961941

962-
toolchain_output = toolchain.get_output()
942+
toolchain_output = notify.get_output()
963943
if toolchain_output:
964944
cur_result["output"] += toolchain_output
965945

@@ -970,9 +950,8 @@ def build_lib(lib_id, target, toolchain_name, verbose=False,
970950

971951
# We do have unique legacy conventions about how we build and package the mbed
972952
# library
973-
def build_mbed_libs(target, toolchain_name, verbose=False,
974-
clean=False, macros=None, notify=None, jobs=1, silent=False,
975-
report=None, properties=None, extra_verbose=False,
953+
def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
954+
notify=None, jobs=1, report=None, properties=None,
976955
build_profile=None):
977956
""" Function returns True is library was built and false if building was
978957
skipped
@@ -982,15 +961,12 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
982961
toolchain_name - the name of the build tools
983962
984963
Keyword arguments:
985-
verbose - Write the actual tools command lines used if True
986964
clean - Rebuild everything if True
987965
macros - additional macros
988966
notify - Notify function for logs
989967
jobs - how many compilers we can run at once
990-
silent - suppress printing of progress indicators
991968
report - a dict where a result may be appended
992969
properties - UUUUHHHHH beats me
993-
extra_verbose - even more output!
994970
build_profile - a dict of flags that will be passed to the compiler
995971
"""
996972

@@ -1034,8 +1010,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
10341010
mkdir(tmp_path)
10351011

10361012
toolchain = prepare_toolchain(
1037-
[""], tmp_path, target, toolchain_name, macros=macros,verbose=verbose,
1038-
notify=notify, silent=silent, extra_verbose=extra_verbose,
1013+
[""], tmp_path, target, toolchain_name, macros=macros, notify=notify,
10391014
build_profile=build_profile, jobs=jobs, clean=clean)
10401015

10411016
# Take into account the library configuration (MBED_CONFIG_FILE)
@@ -1044,7 +1019,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
10441019
toolchain.set_config_data(toolchain.config.get_config_data())
10451020

10461021
# mbed
1047-
toolchain.info("Building library %s (%s, %s)" %
1022+
notify.info("Building library %s (%s, %s)" %
10481023
('MBED', target.name, toolchain_name))
10491024

10501025
# Common Headers
@@ -1111,7 +1086,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
11111086
if report != None:
11121087
end = time()
11131088
cur_result["elapsed_time"] = end - start
1114-
cur_result["output"] = toolchain.get_output()
1089+
cur_result["output"] = notify.get_output()
11151090
cur_result["result"] = "OK"
11161091

11171092
add_result_to_report(report, cur_result)
@@ -1124,7 +1099,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
11241099
cur_result["result"] = "FAIL"
11251100
cur_result["elapsed_time"] = end - start
11261101

1127-
toolchain_output = toolchain.get_output()
1102+
toolchain_output = notify.get_output()
11281103
if toolchain_output:
11291104
cur_result["output"] += toolchain_output
11301105

tools/make.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from tools.options import get_default_options_parser
4646
from tools.options import extract_profile
4747
from tools.options import extract_mcus
48+
from tools.notifier import TerminalNotifier
4849
from tools.build_api import build_project
4950
from tools.build_api import mcu_toolchain_matrix
5051
from tools.build_api import mcu_toolchain_list
@@ -232,16 +233,7 @@
232233
args_error(parser, "argument --build is required when argument --source is provided")
233234

234235

235-
if options.color:
236-
# This import happens late to prevent initializing colorization when we don't need it
237-
import colorize
238-
if options.verbose:
239-
notify = mbedToolchain.print_notify_verbose
240-
else:
241-
notify = mbedToolchain.print_notify
242-
notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify)
243-
else:
244-
notify = None
236+
notify = TerminalNotifier(options.verbose, options.silent)
245237

246238
if not TOOLCHAIN_CLASSES[toolchain].check_executable():
247239
search_path = TOOLCHAIN_PATHS[toolchain] or "No path set"
@@ -283,10 +275,9 @@
283275
set(test.dependencies),
284276
linker_script=options.linker_script,
285277
clean=options.clean,
286-
verbose=options.verbose,
287278
notify=notify,
288-
report=build_data_blob,
289279
silent=options.silent,
280+
report=build_data_blob,
290281
macros=options.macros,
291282
jobs=options.jobs,
292283
name=options.artifact_name,

0 commit comments

Comments
 (0)