Clone of official tools

Revision:
38:399953da035d
Parent:
36:96847d42f010
Child:
43:2a7da56ebd24
--- a/options.py	Fri Jul 07 16:20:25 2017 -0500
+++ b/options.py	Thu Jul 13 15:26:26 2017 -0500
@@ -17,9 +17,9 @@
 from json import load
 from os.path import join, dirname
 from os import listdir
-from argparse import ArgumentParser
+from argparse import ArgumentParser, ArgumentTypeError
 from tools.toolchains import TOOLCHAINS
-from tools.targets import TARGET_NAMES
+from tools.targets import TARGET_NAMES, Target, update_target_data
 from tools.utils import argparse_force_uppercase_type, \
     argparse_lowercase_hyphen_type, argparse_many, \
     argparse_filestring_type, args_error, argparse_profile_filestring_type,\
@@ -47,10 +47,7 @@
     parser.add_argument("-m", "--mcu",
                         help=("build for the given MCU (%s)" %
                               ', '.join(targetnames)),
-                        metavar="MCU",
-                        type=argparse_many(
-                            argparse_force_uppercase_type(
-                                targetnames, "MCU")))
+                        metavar="MCU")
 
     parser.add_argument("-t", "--tool",
                         help=("build using the given TOOLCHAIN (%s)" %
@@ -130,3 +127,19 @@
              "See https://developer.mbed.org/platforms/Renesas-GR-PEACH/#important-notice "
              "for more information") % (mcu, mcu))
     return True
+    
+def extract_mcus(parser, options):
+    try:
+        if options.source_dir:
+            for source_dir in options.source_dir:
+                Target.add_extra_targets(source_dir)
+            update_target_data()
+    except KeyError:
+        pass
+    targetnames = TARGET_NAMES
+    targetnames.sort()
+    try:
+        return argparse_many(argparse_force_uppercase_type(targetnames, "MCU"))(options.mcu)
+    except ArgumentTypeError as exc:
+        args_error(parser, "argument -m/--mcu: {}".format(str(exc)))
+