Clone of official tools

Revision:
43:2a7da56ebd24
Parent:
40:7d3fa6b99b2b
--- a/make.py	Mon Nov 06 13:17:14 2017 -0600
+++ b/make.py	Tue Sep 25 13:43:09 2018 -0500
@@ -18,6 +18,8 @@
 
 TEST BUILD & RUN
 """
+from __future__ import print_function
+from builtins import str
 import sys
 import json
 from time import sleep
@@ -43,6 +45,7 @@
 from tools.options import get_default_options_parser
 from tools.options import extract_profile
 from tools.options import extract_mcus
+from tools.notifier.term import TerminalNotifier
 from tools.build_api import build_project
 from tools.build_api import mcu_toolchain_matrix
 from tools.build_api import mcu_toolchain_list
@@ -52,7 +55,6 @@
 from utils import argparse_many
 from utils import argparse_dir_not_parent
 from tools.toolchains import mbedToolchain, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
-from tools.settings import CLI_COLOR_MAP
 
 if __name__ == '__main__':
     # Parse Options
@@ -138,6 +140,8 @@
                       default=None, help="The build (output) directory")
     parser.add_argument("-N", "--artifact-name", dest="artifact_name",
                       default=None, help="The built project's name")
+    parser.add_argument("--ignore", dest="ignore", type=argparse_many(str),
+                        default=None, help="Comma separated list of patterns to add to mbedignore (eg. ./main.cpp)")
     parser.add_argument("-d", "--disk", dest="disk",
                       default=None, help="The mbed disk")
     parser.add_argument("-s", "--serial", dest="serial",
@@ -186,20 +190,21 @@
     # Only prints matrix of supported toolchains
     if options.supported_toolchains:
         if options.supported_toolchains == "matrix":
-            print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
+            print(mcu_toolchain_matrix(platform_filter=options.general_filter_regex,
+                                       release_version=None))
         elif options.supported_toolchains == "toolchains":
             toolchain_list = mcu_toolchain_list()
             # Only print the lines that matter
             for line in toolchain_list.split("\n"):
                 if not "mbed" in line:
-                    print line
+                    print(line)
         elif options.supported_toolchains == "targets":
-            print mcu_target_list()
+            print(mcu_target_list())
         exit(0)
 
     # Print available tests in order and exit
     if options.list_tests is True:
-        print '\n'.join(map(str, sorted(TEST_MAP.values())))
+        print('\n'.join(map(str, sorted(TEST_MAP.values()))))
         sys.exit()
 
     # force program to "0" if a source dir is specified
@@ -230,22 +235,13 @@
         args_error(parser, "argument --build is required when argument --source is provided")
 
 
-    if options.color:
-        # This import happens late to prevent initializing colorization when we don't need it
-        import colorize
-        if options.verbose:
-            notify = mbedToolchain.print_notify_verbose
-        else:
-            notify = mbedToolchain.print_notify
-        notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify)
-    else:
-        notify = None
+    notify = TerminalNotifier(options.verbose, options.silent, options.color)
 
     if not TOOLCHAIN_CLASSES[toolchain].check_executable():
         search_path = TOOLCHAIN_PATHS[toolchain] or "No path set"
         args_error(parser, "Could not find executable for %s.\n"
                            "Currently set search path: %s"
-                           %(toolchain,search_path))
+                           %(toolchain, search_path))
 
     # Test
     build_data_blob = {} if options.build_data else None
@@ -259,7 +255,7 @@
         if options.extra is not None:        test.extra_files = options.extra
 
         if not test.is_supported(mcu, toolchain):
-            print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain)
+            print('The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain))
             sys.exit()
 
         # Linking with extra libraries
@@ -277,24 +273,28 @@
             build_dir = options.build_dir
 
         try:
-            bin_file = build_project(test.source_dir, build_dir, mcu, toolchain,
-                                     set(test.dependencies),
-                                     linker_script=options.linker_script,
-                                     clean=options.clean,
-                                     verbose=options.verbose,
-                                     notify=notify,
-                                     report=build_data_blob,
-                                     silent=options.silent,
-                                     macros=options.macros,
-                                     jobs=options.jobs,
-                                     name=options.artifact_name,
-                                     app_config=options.app_config,
-                                     inc_dirs=[dirname(MBED_LIBRARIES)],
-                                     build_profile=extract_profile(parser,
-                                                                   options,
-                                                                   toolchain),
-                                     stats_depth=options.stats_depth)
-            print 'Image: %s'% bin_file
+            bin_file, update_file = build_project(
+                test.source_dir,
+                build_dir,
+                mcu,
+                toolchain,
+                set(test.dependencies),
+                linker_script=options.linker_script,
+                clean=options.clean,
+                notify=notify,
+                report=build_data_blob,
+                macros=options.macros,
+                jobs=options.jobs,
+                name=options.artifact_name,
+                app_config=options.app_config,
+                inc_dirs=[dirname(MBED_LIBRARIES)],
+                build_profile=extract_profile(parser, options, toolchain),
+                stats_depth=options.stats_depth,
+                ignore=options.ignore
+            )
+            if update_file:
+                print('Update Image: %s' % update_file)
+            print('Image: %s' % bin_file)
 
             if options.disk:
                 # Simple copy to the mbed disk
@@ -328,16 +328,16 @@
                     sys.stdout.write(c)
                     sys.stdout.flush()
 
-        except KeyboardInterrupt, e:
-            print "\n[CTRL+c] exit"
+        except KeyboardInterrupt as e:
+            print("\n[CTRL+c] exit")
         except NotSupportedException as e:
-            print "\nCould not compile for %s: %s" % (mcu, str(e))
-        except Exception,e:
+            print("\nCould not compile for %s: %s" % (mcu, str(e)))
+        except Exception as e:
             if options.verbose:
                 import traceback
                 traceback.print_exc(file=sys.stdout)
             else:
-                print "[ERROR] %s" % str(e)
+                print("[ERROR] %s" % str(e))
 
             sys.exit(1)
     if options.build_data: