Clone of official tools

Committer:
theotherjimmy
Date:
Tue Sep 25 13:43:09 2018 -0500
Revision:
43:2a7da56ebd24
Parent:
41:2a77626a4c21
Child:
46:e502676b7f84
Release 5.10.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
The Other Jimmy 31:8ea194f6145b 1 """ The CLI entry point for exporting projects from the mbed tools to any of the
The Other Jimmy 31:8ea194f6145b 2 supported IDEs or project structures.
The Other Jimmy 31:8ea194f6145b 3 """
theotherjimmy 43:2a7da56ebd24 4 from __future__ import print_function, absolute_import
theotherjimmy 43:2a7da56ebd24 5 from builtins import str
theotherjimmy 43:2a7da56ebd24 6
screamer 0:66f3b5499f7f 7 import sys
theotherjimmy 43:2a7da56ebd24 8 from os.path import (join, abspath, dirname, exists, basename, normpath,
theotherjimmy 43:2a7da56ebd24 9 realpath, relpath, basename)
theotherjimmy 43:2a7da56ebd24 10 from os import remove
screamer 0:66f3b5499f7f 11 ROOT = abspath(join(dirname(__file__), ".."))
screamer 0:66f3b5499f7f 12 sys.path.insert(0, ROOT)
screamer 0:66f3b5499f7f 13
screamer 0:66f3b5499f7f 14 from shutil import move, rmtree
screamer 22:9e85236d8716 15 from argparse import ArgumentParser
screamer 0:66f3b5499f7f 16
The Other Jimmy 31:8ea194f6145b 17 from tools.paths import EXPORT_DIR, MBED_HAL, MBED_LIBRARIES, MBED_TARGETS_PATH
The Other Jimmy 35:da9c89f8be7d 18 from tools.settings import BUILD_DIR
theotherjimmy 43:2a7da56ebd24 19 from tools.export import (
theotherjimmy 43:2a7da56ebd24 20 EXPORTERS,
theotherjimmy 43:2a7da56ebd24 21 mcu_ide_matrix,
theotherjimmy 43:2a7da56ebd24 22 mcu_ide_list,
theotherjimmy 43:2a7da56ebd24 23 export_project,
theotherjimmy 43:2a7da56ebd24 24 get_exporter_toolchain,
theotherjimmy 43:2a7da56ebd24 25 )
screamer 23:fbae331171fa 26 from tools.tests import TESTS, TEST_MAP
The Other Jimmy 31:8ea194f6145b 27 from tools.tests import test_known, test_name_known, Test
theotherjimmy 40:7d3fa6b99b2b 28 from tools.targets import TARGET_NAMES, set_targets_json_location
theotherjimmy 43:2a7da56ebd24 29 from tools.utils import (
theotherjimmy 43:2a7da56ebd24 30 argparse_filestring_type,
theotherjimmy 43:2a7da56ebd24 31 argparse_profile_filestring_type,
theotherjimmy 43:2a7da56ebd24 32 argparse_many,
theotherjimmy 43:2a7da56ebd24 33 args_error,
theotherjimmy 43:2a7da56ebd24 34 )
The Other Jimmy 31:8ea194f6145b 35 from tools.utils import argparse_force_lowercase_type
The Other Jimmy 31:8ea194f6145b 36 from tools.utils import argparse_force_uppercase_type
The Other Jimmy 31:8ea194f6145b 37 from tools.utils import print_large_string
theotherjimmy 41:2a77626a4c21 38 from tools.utils import NotSupportedException
The Other Jimmy 38:399953da035d 39 from tools.options import extract_profile, list_profiles, extract_mcus
theotherjimmy 43:2a7da56ebd24 40 from tools.notifier.term import TerminalNotifier
theotherjimmy 40:7d3fa6b99b2b 41 from tools.build_profiles import find_targets_json, find_build_profile, get_toolchain_profile
theotherjimmy 40:7d3fa6b99b2b 42 from tools.toolchains import mbedToolchain
The Other Jimmy 31:8ea194f6145b 43
theotherjimmy 43:2a7da56ebd24 44 EXPORTER_ALIASES = {
theotherjimmy 43:2a7da56ebd24 45 u'gcc_arm': u'make_gcc_arm',
theotherjimmy 43:2a7da56ebd24 46 u'uvision': u'uvision5',
theotherjimmy 43:2a7da56ebd24 47 }
theotherjimmy 43:2a7da56ebd24 48
theotherjimmy 43:2a7da56ebd24 49
theotherjimmy 43:2a7da56ebd24 50 def resolve_exporter_alias(ide):
theotherjimmy 43:2a7da56ebd24 51 if ide in EXPORTER_ALIASES:
theotherjimmy 43:2a7da56ebd24 52 return EXPORTER_ALIASES[ide]
theotherjimmy 43:2a7da56ebd24 53 else:
theotherjimmy 43:2a7da56ebd24 54 return ide
theotherjimmy 43:2a7da56ebd24 55
theotherjimmy 43:2a7da56ebd24 56
theotherjimmy 43:2a7da56ebd24 57 def setup_project(
theotherjimmy 43:2a7da56ebd24 58 ide,
theotherjimmy 43:2a7da56ebd24 59 target,
theotherjimmy 43:2a7da56ebd24 60 zip,
theotherjimmy 43:2a7da56ebd24 61 program,
theotherjimmy 43:2a7da56ebd24 62 source_dir,
theotherjimmy 43:2a7da56ebd24 63 build,
theotherjimmy 43:2a7da56ebd24 64 export_path,
theotherjimmy 43:2a7da56ebd24 65 ):
The Other Jimmy 31:8ea194f6145b 66 """Generate a name, if not provided, and find dependencies
The Other Jimmy 31:8ea194f6145b 67
The Other Jimmy 31:8ea194f6145b 68 Positional arguments:
The Other Jimmy 31:8ea194f6145b 69 ide - IDE or project structure that will soon be exported to
The Other Jimmy 31:8ea194f6145b 70 target - MCU that the project will build for
The Other Jimmy 31:8ea194f6145b 71
The Other Jimmy 31:8ea194f6145b 72 Keyword arguments:
The Other Jimmy 31:8ea194f6145b 73 program - the index of a test program
The Other Jimmy 31:8ea194f6145b 74 source_dir - the directory, or directories that contain all of the sources
The Other Jimmy 31:8ea194f6145b 75 build - a directory that will contain the result of the export
The Other Jimmy 31:8ea194f6145b 76 """
The Other Jimmy 31:8ea194f6145b 77 # Some libraries have extra macros (called by exporter symbols) to we need
The Other Jimmy 31:8ea194f6145b 78 # to pass them to maintain compilation macros integrity between compiled
The Other Jimmy 31:8ea194f6145b 79 # library and header files we might use with it
The Other Jimmy 31:8ea194f6145b 80 if source_dir:
The Other Jimmy 31:8ea194f6145b 81 # --source is used to generate IDE files to toolchain directly
The Other Jimmy 31:8ea194f6145b 82 # in the source tree and doesn't generate zip file
The Other Jimmy 31:8ea194f6145b 83 project_dir = export_path or source_dir[0]
The Other Jimmy 31:8ea194f6145b 84 if program:
The Other Jimmy 31:8ea194f6145b 85 project_name = TESTS[program]
The Other Jimmy 31:8ea194f6145b 86 else:
The Other Jimmy 31:8ea194f6145b 87 project_name = basename(normpath(realpath(source_dir[0])))
theotherjimmy 43:2a7da56ebd24 88 if zip:
theotherjimmy 43:2a7da56ebd24 89 src_paths = {path.strip(".\\/"): [path] for path in source_dir}
theotherjimmy 43:2a7da56ebd24 90 else:
theotherjimmy 43:2a7da56ebd24 91 src_paths = {relpath(path, project_dir): [path] for path in source_dir}
The Other Jimmy 31:8ea194f6145b 92 lib_paths = None
The Other Jimmy 31:8ea194f6145b 93 else:
The Other Jimmy 31:8ea194f6145b 94 test = Test(program)
The Other Jimmy 31:8ea194f6145b 95 if not build:
The Other Jimmy 31:8ea194f6145b 96 # Substitute the mbed library builds with their sources
The Other Jimmy 31:8ea194f6145b 97 if MBED_LIBRARIES in test.dependencies:
The Other Jimmy 31:8ea194f6145b 98 test.dependencies.remove(MBED_LIBRARIES)
The Other Jimmy 31:8ea194f6145b 99 test.dependencies.append(MBED_HAL)
The Other Jimmy 31:8ea194f6145b 100 test.dependencies.append(MBED_TARGETS_PATH)
screamer 0:66f3b5499f7f 101
The Other Jimmy 31:8ea194f6145b 102 src_paths = [test.source_dir]
The Other Jimmy 31:8ea194f6145b 103 lib_paths = test.dependencies
The Other Jimmy 31:8ea194f6145b 104 project_name = "_".join([test.id, ide, target])
The Other Jimmy 31:8ea194f6145b 105 project_dir = join(EXPORT_DIR, project_name)
screamer 0:66f3b5499f7f 106
The Other Jimmy 31:8ea194f6145b 107 return project_dir, project_name, src_paths, lib_paths
The Other Jimmy 31:8ea194f6145b 108
The Other Jimmy 31:8ea194f6145b 109
The Other Jimmy 31:8ea194f6145b 110 def export(target, ide, build=None, src=None, macros=None, project_id=None,
theotherjimmy 43:2a7da56ebd24 111 zip_proj=False, build_profile=None, export_path=None, notify=None,
theotherjimmy 43:2a7da56ebd24 112 app_config=None, ignore=None):
The Other Jimmy 31:8ea194f6145b 113 """Do an export of a project.
The Other Jimmy 31:8ea194f6145b 114
The Other Jimmy 31:8ea194f6145b 115 Positional arguments:
The Other Jimmy 31:8ea194f6145b 116 target - MCU that the project will compile for
The Other Jimmy 31:8ea194f6145b 117 ide - the IDE or project structure to export to
The Other Jimmy 31:8ea194f6145b 118
The Other Jimmy 31:8ea194f6145b 119 Keyword arguments:
The Other Jimmy 31:8ea194f6145b 120 build - to use the compiled mbed libraries or not
The Other Jimmy 31:8ea194f6145b 121 src - directory or directories that contain the source to export
The Other Jimmy 31:8ea194f6145b 122 macros - extra macros to add to the project
The Other Jimmy 31:8ea194f6145b 123 project_id - the name of the project
The Other Jimmy 31:8ea194f6145b 124 clean - start from a clean state before exporting
The Other Jimmy 31:8ea194f6145b 125 zip_proj - create a zip file or not
theotherjimmy 43:2a7da56ebd24 126 ignore - list of paths to add to mbedignore
The Other Jimmy 31:8ea194f6145b 127
The Other Jimmy 31:8ea194f6145b 128 Returns an object of type Exporter (tools/exports/exporters.py)
The Other Jimmy 31:8ea194f6145b 129 """
theotherjimmy 40:7d3fa6b99b2b 130 ###################################
theotherjimmy 40:7d3fa6b99b2b 131 # mbed Classic/2.0/libary support #
theotherjimmy 40:7d3fa6b99b2b 132
theotherjimmy 40:7d3fa6b99b2b 133 # Find build system profile
theotherjimmy 40:7d3fa6b99b2b 134 profile = None
theotherjimmy 40:7d3fa6b99b2b 135 targets_json = None
theotherjimmy 40:7d3fa6b99b2b 136 for path in src:
theotherjimmy 40:7d3fa6b99b2b 137 profile = find_build_profile(path) or profile
theotherjimmy 40:7d3fa6b99b2b 138 if profile:
theotherjimmy 40:7d3fa6b99b2b 139 targets_json = join(dirname(dirname(abspath(__file__))), 'legacy_targets.json')
theotherjimmy 40:7d3fa6b99b2b 140 else:
theotherjimmy 40:7d3fa6b99b2b 141 targets_json = find_targets_json(path) or targets_json
theotherjimmy 40:7d3fa6b99b2b 142
theotherjimmy 40:7d3fa6b99b2b 143 # Apply targets.json to active targets
theotherjimmy 40:7d3fa6b99b2b 144 if targets_json:
theotherjimmy 43:2a7da56ebd24 145 notify.info("Using targets from %s" % targets_json)
theotherjimmy 40:7d3fa6b99b2b 146 set_targets_json_location(targets_json)
theotherjimmy 40:7d3fa6b99b2b 147
theotherjimmy 40:7d3fa6b99b2b 148 # Apply profile to toolchains
theotherjimmy 40:7d3fa6b99b2b 149 if profile:
theotherjimmy 40:7d3fa6b99b2b 150 def init_hook(self):
theotherjimmy 40:7d3fa6b99b2b 151 profile_data = get_toolchain_profile(self.name, profile)
theotherjimmy 40:7d3fa6b99b2b 152 if not profile_data:
theotherjimmy 40:7d3fa6b99b2b 153 return
theotherjimmy 43:2a7da56ebd24 154 notify.info("Using toolchain %s profile %s" % (self.name, profile))
theotherjimmy 40:7d3fa6b99b2b 155
theotherjimmy 40:7d3fa6b99b2b 156 for k,v in profile_data.items():
theotherjimmy 40:7d3fa6b99b2b 157 if self.flags.has_key(k):
theotherjimmy 40:7d3fa6b99b2b 158 self.flags[k] = v
theotherjimmy 40:7d3fa6b99b2b 159 else:
theotherjimmy 40:7d3fa6b99b2b 160 setattr(self, k, v)
theotherjimmy 40:7d3fa6b99b2b 161
theotherjimmy 40:7d3fa6b99b2b 162 mbedToolchain.init = init_hook
theotherjimmy 40:7d3fa6b99b2b 163
theotherjimmy 40:7d3fa6b99b2b 164 # mbed Classic/2.0/libary support #
theotherjimmy 40:7d3fa6b99b2b 165 ###################################
theotherjimmy 40:7d3fa6b99b2b 166
theotherjimmy 43:2a7da56ebd24 167 project_dir, name, src, lib = setup_project(
theotherjimmy 43:2a7da56ebd24 168 ide,
theotherjimmy 43:2a7da56ebd24 169 target,
theotherjimmy 43:2a7da56ebd24 170 bool(zip_proj),
theotherjimmy 43:2a7da56ebd24 171 program=project_id,
theotherjimmy 43:2a7da56ebd24 172 source_dir=src,
theotherjimmy 43:2a7da56ebd24 173 build=build,
theotherjimmy 43:2a7da56ebd24 174 export_path=export_path,
theotherjimmy 43:2a7da56ebd24 175 )
theotherjimmy 43:2a7da56ebd24 176
theotherjimmy 43:2a7da56ebd24 177 zip_name = name+".zip" if zip_proj else None
theotherjimmy 43:2a7da56ebd24 178
theotherjimmy 43:2a7da56ebd24 179 return export_project(
theotherjimmy 43:2a7da56ebd24 180 src,
theotherjimmy 43:2a7da56ebd24 181 project_dir,
theotherjimmy 43:2a7da56ebd24 182 target,
theotherjimmy 43:2a7da56ebd24 183 ide,
theotherjimmy 43:2a7da56ebd24 184 name=name,
theotherjimmy 43:2a7da56ebd24 185 macros=macros,
theotherjimmy 43:2a7da56ebd24 186 libraries_paths=lib,
theotherjimmy 43:2a7da56ebd24 187 zip_proj=zip_name,
theotherjimmy 43:2a7da56ebd24 188 build_profile=build_profile,
theotherjimmy 43:2a7da56ebd24 189 notify=TerminalNotifier(),
theotherjimmy 43:2a7da56ebd24 190 app_config=app_config,
theotherjimmy 43:2a7da56ebd24 191 ignore=ignore
theotherjimmy 43:2a7da56ebd24 192 )
theotherjimmy 43:2a7da56ebd24 193
theotherjimmy 43:2a7da56ebd24 194 def clean(source_dir):
theotherjimmy 43:2a7da56ebd24 195 if exists(EXPORT_DIR):
theotherjimmy 43:2a7da56ebd24 196 rmtree(EXPORT_DIR)
theotherjimmy 43:2a7da56ebd24 197 for cls in EXPORTERS.values():
theotherjimmy 43:2a7da56ebd24 198 try:
theotherjimmy 43:2a7da56ebd24 199 cls.clean(basename(abspath(source_dir[0])))
theotherjimmy 43:2a7da56ebd24 200 except (NotImplementedError, IOError, OSError):
theotherjimmy 43:2a7da56ebd24 201 pass
theotherjimmy 43:2a7da56ebd24 202 for f in list(EXPORTERS.values())[0].CLEAN_FILES:
theotherjimmy 43:2a7da56ebd24 203 try:
theotherjimmy 43:2a7da56ebd24 204 remove(f)
theotherjimmy 43:2a7da56ebd24 205 except (IOError, OSError):
theotherjimmy 43:2a7da56ebd24 206 pass
theotherjimmy 43:2a7da56ebd24 207
The Other Jimmy 35:da9c89f8be7d 208 return export_project(src, project_dir, target, ide, name=name,
The Other Jimmy 35:da9c89f8be7d 209 macros=macros, libraries_paths=lib, zip_proj=zip_name,
theotherjimmy 43:2a7da56ebd24 210 build_profile=build_profile, notify=notify,
theotherjimmy 43:2a7da56ebd24 211 app_config=app_config, ignore=ignore)
The Other Jimmy 31:8ea194f6145b 212
The Other Jimmy 31:8ea194f6145b 213
theotherjimmy 43:2a7da56ebd24 214 def get_args(argv):
screamer 22:9e85236d8716 215 parser = ArgumentParser()
screamer 0:66f3b5499f7f 216
screamer 0:66f3b5499f7f 217 targetnames = TARGET_NAMES
screamer 0:66f3b5499f7f 218 targetnames.sort()
theotherjimmy 43:2a7da56ebd24 219 toolchainlist = list(EXPORTERS.keys()) + list(EXPORTER_ALIASES.keys())
screamer 0:66f3b5499f7f 220 toolchainlist.sort()
screamer 0:66f3b5499f7f 221
theotherjimmy 43:2a7da56ebd24 222 parser.add_argument(
theotherjimmy 43:2a7da56ebd24 223 "-m", "--mcu",
theotherjimmy 43:2a7da56ebd24 224 metavar="MCU",
theotherjimmy 43:2a7da56ebd24 225 help="generate project for the given MCU ({})".format(
theotherjimmy 43:2a7da56ebd24 226 ', '.join(targetnames))
theotherjimmy 43:2a7da56ebd24 227 )
screamer 0:66f3b5499f7f 228
theotherjimmy 43:2a7da56ebd24 229 parser.add_argument(
theotherjimmy 43:2a7da56ebd24 230 "-i",
theotherjimmy 43:2a7da56ebd24 231 dest="ide",
theotherjimmy 43:2a7da56ebd24 232 type=argparse_force_lowercase_type(
theotherjimmy 43:2a7da56ebd24 233 toolchainlist, "toolchain"),
theotherjimmy 43:2a7da56ebd24 234 help="The target IDE: %s" % str(toolchainlist)
theotherjimmy 43:2a7da56ebd24 235 )
screamer 0:66f3b5499f7f 236
theotherjimmy 43:2a7da56ebd24 237 parser.add_argument(
theotherjimmy 43:2a7da56ebd24 238 "-c", "--clean",
theotherjimmy 43:2a7da56ebd24 239 action="store_true",
theotherjimmy 43:2a7da56ebd24 240 default=False,
theotherjimmy 43:2a7da56ebd24 241 help="clean the export directory"
theotherjimmy 43:2a7da56ebd24 242 )
screamer 0:66f3b5499f7f 243
screamer 22:9e85236d8716 244 group = parser.add_mutually_exclusive_group(required=False)
The Other Jimmy 31:8ea194f6145b 245 group.add_argument(
The Other Jimmy 31:8ea194f6145b 246 "-p",
The Other Jimmy 31:8ea194f6145b 247 type=test_known,
The Other Jimmy 31:8ea194f6145b 248 dest="program",
theotherjimmy 43:2a7da56ebd24 249 help="The index of the desired test program: [0-%s]" % (len(TESTS) - 1)
theotherjimmy 43:2a7da56ebd24 250 )
screamer 0:66f3b5499f7f 251
theotherjimmy 43:2a7da56ebd24 252 group.add_argument(
theotherjimmy 43:2a7da56ebd24 253 "-n",
theotherjimmy 43:2a7da56ebd24 254 type=test_name_known,
theotherjimmy 43:2a7da56ebd24 255 dest="program",
theotherjimmy 43:2a7da56ebd24 256 help="The name of the desired test program"
theotherjimmy 43:2a7da56ebd24 257 )
screamer 0:66f3b5499f7f 258
theotherjimmy 43:2a7da56ebd24 259 parser.add_argument(
theotherjimmy 43:2a7da56ebd24 260 "-b",
theotherjimmy 43:2a7da56ebd24 261 dest="build",
theotherjimmy 43:2a7da56ebd24 262 default=False,
theotherjimmy 43:2a7da56ebd24 263 action="store_true",
theotherjimmy 43:2a7da56ebd24 264 help="use the mbed library build, instead of the sources"
theotherjimmy 43:2a7da56ebd24 265 )
screamer 0:66f3b5499f7f 266
theotherjimmy 43:2a7da56ebd24 267 group.add_argument(
theotherjimmy 43:2a7da56ebd24 268 "-L", "--list-tests",
theotherjimmy 43:2a7da56ebd24 269 action="store_true",
theotherjimmy 43:2a7da56ebd24 270 dest="list_tests",
theotherjimmy 43:2a7da56ebd24 271 default=False,
theotherjimmy 43:2a7da56ebd24 272 help="list available programs in order and exit"
theotherjimmy 43:2a7da56ebd24 273 )
screamer 0:66f3b5499f7f 274
theotherjimmy 43:2a7da56ebd24 275 group.add_argument(
theotherjimmy 43:2a7da56ebd24 276 "-S", "--list-matrix",
theotherjimmy 43:2a7da56ebd24 277 dest="supported_ides",
theotherjimmy 43:2a7da56ebd24 278 default=False,
theotherjimmy 43:2a7da56ebd24 279 const="matrix",
theotherjimmy 43:2a7da56ebd24 280 choices=["matrix", "ides"],
theotherjimmy 43:2a7da56ebd24 281 nargs="?",
theotherjimmy 43:2a7da56ebd24 282 help="displays supported matrix of MCUs and IDEs"
theotherjimmy 43:2a7da56ebd24 283 )
theotherjimmy 43:2a7da56ebd24 284
theotherjimmy 43:2a7da56ebd24 285 group.add_argument(
theotherjimmy 43:2a7da56ebd24 286 "--update-packs",
theotherjimmy 43:2a7da56ebd24 287 dest="update_packs",
theotherjimmy 43:2a7da56ebd24 288 action="store_true",
theotherjimmy 43:2a7da56ebd24 289 default=False
theotherjimmy 43:2a7da56ebd24 290 )
theotherjimmy 43:2a7da56ebd24 291
theotherjimmy 43:2a7da56ebd24 292 parser.add_argument(
theotherjimmy 43:2a7da56ebd24 293 "-E",
theotherjimmy 43:2a7da56ebd24 294 action="store_true",
theotherjimmy 43:2a7da56ebd24 295 dest="supported_ides_html",
theotherjimmy 43:2a7da56ebd24 296 default=False,
theotherjimmy 43:2a7da56ebd24 297 help="Generate a markdown version of the results of -S in README.md"
theotherjimmy 43:2a7da56ebd24 298 )
screamer 0:66f3b5499f7f 299
theotherjimmy 43:2a7da56ebd24 300 parser.add_argument(
theotherjimmy 43:2a7da56ebd24 301 "--build",
theotherjimmy 43:2a7da56ebd24 302 type=argparse_filestring_type,
theotherjimmy 43:2a7da56ebd24 303 dest="build_dir",
theotherjimmy 43:2a7da56ebd24 304 default=None,
theotherjimmy 43:2a7da56ebd24 305 help="Directory for the exported project files"
theotherjimmy 43:2a7da56ebd24 306 )
screamer 0:66f3b5499f7f 307
theotherjimmy 43:2a7da56ebd24 308 parser.add_argument(
theotherjimmy 43:2a7da56ebd24 309 "--source",
theotherjimmy 43:2a7da56ebd24 310 action="append",
theotherjimmy 43:2a7da56ebd24 311 type=argparse_filestring_type,
theotherjimmy 43:2a7da56ebd24 312 dest="source_dir",
theotherjimmy 43:2a7da56ebd24 313 default=[],
theotherjimmy 43:2a7da56ebd24 314 help="The source (input) directory"
theotherjimmy 43:2a7da56ebd24 315 )
theotherjimmy 43:2a7da56ebd24 316
theotherjimmy 43:2a7da56ebd24 317 parser.add_argument(
theotherjimmy 43:2a7da56ebd24 318 "-D",
theotherjimmy 43:2a7da56ebd24 319 action="append",
theotherjimmy 43:2a7da56ebd24 320 dest="macros",
theotherjimmy 43:2a7da56ebd24 321 help="Add a macro definition"
theotherjimmy 43:2a7da56ebd24 322 )
screamer 0:66f3b5499f7f 323
theotherjimmy 43:2a7da56ebd24 324 parser.add_argument(
theotherjimmy 43:2a7da56ebd24 325 "--profile",
theotherjimmy 43:2a7da56ebd24 326 dest="profile",
theotherjimmy 43:2a7da56ebd24 327 action="append",
theotherjimmy 43:2a7da56ebd24 328 type=argparse_profile_filestring_type,
theotherjimmy 43:2a7da56ebd24 329 help=("Build profile to use. Can be either path to json"
theotherjimmy 43:2a7da56ebd24 330 "file or one of the default one ({})".format(
theotherjimmy 43:2a7da56ebd24 331 ", ".join(list_profiles()))),
theotherjimmy 43:2a7da56ebd24 332 default=[]
theotherjimmy 43:2a7da56ebd24 333 )
theotherjimmy 43:2a7da56ebd24 334
theotherjimmy 43:2a7da56ebd24 335 parser.add_argument(
theotherjimmy 43:2a7da56ebd24 336 "--app-config",
theotherjimmy 43:2a7da56ebd24 337 dest="app_config",
theotherjimmy 43:2a7da56ebd24 338 default=None
theotherjimmy 43:2a7da56ebd24 339 )
The Other Jimmy 31:8ea194f6145b 340
theotherjimmy 43:2a7da56ebd24 341 parser.add_argument(
theotherjimmy 43:2a7da56ebd24 342 "-z",
theotherjimmy 43:2a7da56ebd24 343 action="store_true",
theotherjimmy 43:2a7da56ebd24 344 default=None,
theotherjimmy 43:2a7da56ebd24 345 dest="zip",
theotherjimmy 43:2a7da56ebd24 346 )
The Other Jimmy 31:8ea194f6145b 347
theotherjimmy 43:2a7da56ebd24 348 parser.add_argument(
theotherjimmy 43:2a7da56ebd24 349 "--ignore",
theotherjimmy 43:2a7da56ebd24 350 dest="ignore",
theotherjimmy 43:2a7da56ebd24 351 type=argparse_many(str),
theotherjimmy 43:2a7da56ebd24 352 default=None,
theotherjimmy 43:2a7da56ebd24 353 help=("Comma separated list of patterns to add to mbedignore "
theotherjimmy 43:2a7da56ebd24 354 "(eg. ./main.cpp)")
theotherjimmy 43:2a7da56ebd24 355 )
screamer 0:66f3b5499f7f 356
theotherjimmy 43:2a7da56ebd24 357 return parser.parse_args(argv), parser
theotherjimmy 43:2a7da56ebd24 358
theotherjimmy 43:2a7da56ebd24 359
theotherjimmy 43:2a7da56ebd24 360 def main():
theotherjimmy 43:2a7da56ebd24 361 """Entry point"""
theotherjimmy 43:2a7da56ebd24 362 # Parse Options
theotherjimmy 43:2a7da56ebd24 363 options, parser = get_args(sys.argv[1:])
screamer 0:66f3b5499f7f 364
screamer 0:66f3b5499f7f 365 # Print available tests in order and exit
theotherjimmy 43:2a7da56ebd24 366 if options.list_tests:
theotherjimmy 43:2a7da56ebd24 367 print('\n'.join(str(test) for test in sorted(TEST_MAP.values())))
theotherjimmy 43:2a7da56ebd24 368 elif options.supported_ides:
The Other Jimmy 36:96847d42f010 369 if options.supported_ides == "matrix":
The Other Jimmy 36:96847d42f010 370 print_large_string(mcu_ide_matrix())
The Other Jimmy 36:96847d42f010 371 elif options.supported_ides == "ides":
theotherjimmy 43:2a7da56ebd24 372 print(mcu_ide_list())
theotherjimmy 43:2a7da56ebd24 373 elif options.supported_ides_html:
screamer 0:66f3b5499f7f 374 html = mcu_ide_matrix(verbose_html=True)
theotherjimmy 43:2a7da56ebd24 375 with open("README.md", "w") as readme:
theotherjimmy 43:2a7da56ebd24 376 readme.write("Exporter IDE/Platform Support\n")
theotherjimmy 43:2a7da56ebd24 377 readme.write("-----------------------------------\n")
theotherjimmy 43:2a7da56ebd24 378 readme.write("\n")
theotherjimmy 43:2a7da56ebd24 379 readme.write(html)
theotherjimmy 43:2a7da56ebd24 380 elif options.update_packs:
The Other Jimmy 31:8ea194f6145b 381 from tools.arm_pack_manager import Cache
The Other Jimmy 31:8ea194f6145b 382 cache = Cache(True, True)
theotherjimmy 43:2a7da56ebd24 383 cache.cache_everything()
theotherjimmy 43:2a7da56ebd24 384 else:
theotherjimmy 43:2a7da56ebd24 385 # Check required arguments
theotherjimmy 43:2a7da56ebd24 386 if not options.mcu:
theotherjimmy 43:2a7da56ebd24 387 args_error(parser, "argument -m/--mcu is required")
theotherjimmy 43:2a7da56ebd24 388 if not options.ide:
theotherjimmy 43:2a7da56ebd24 389 args_error(parser, "argument -i is required")
theotherjimmy 43:2a7da56ebd24 390 if (options.program is None) and (not options.source_dir):
theotherjimmy 43:2a7da56ebd24 391 args_error(parser, "one of -p, -n, or --source is required")
The Other Jimmy 31:8ea194f6145b 392
theotherjimmy 43:2a7da56ebd24 393 if options.clean:
theotherjimmy 43:2a7da56ebd24 394 clean(options.source_dir)
The Other Jimmy 35:da9c89f8be7d 395
theotherjimmy 43:2a7da56ebd24 396 ide = resolve_exporter_alias(options.ide)
theotherjimmy 43:2a7da56ebd24 397 exporter, toolchain_name = get_exporter_toolchain(ide)
theotherjimmy 43:2a7da56ebd24 398 profile = extract_profile(parser, options, toolchain_name, fallback="debug")
theotherjimmy 43:2a7da56ebd24 399 mcu = extract_mcus(parser, options)[0]
theotherjimmy 43:2a7da56ebd24 400 if not exporter.is_target_supported(mcu):
theotherjimmy 43:2a7da56ebd24 401 args_error(parser, "%s not supported by %s" % (mcu, ide))
theotherjimmy 43:2a7da56ebd24 402
theotherjimmy 43:2a7da56ebd24 403 try:
theotherjimmy 43:2a7da56ebd24 404 export(
theotherjimmy 43:2a7da56ebd24 405 mcu,
theotherjimmy 43:2a7da56ebd24 406 ide,
theotherjimmy 43:2a7da56ebd24 407 build=options.build,
theotherjimmy 43:2a7da56ebd24 408 src=options.source_dir,
theotherjimmy 43:2a7da56ebd24 409 macros=options.macros,
theotherjimmy 43:2a7da56ebd24 410 project_id=options.program,
theotherjimmy 43:2a7da56ebd24 411 zip_proj=not bool(options.source_dir) or options.zip,
theotherjimmy 43:2a7da56ebd24 412 build_profile=profile,
theotherjimmy 43:2a7da56ebd24 413 app_config=options.app_config,
theotherjimmy 43:2a7da56ebd24 414 export_path=options.build_dir,
theotherjimmy 43:2a7da56ebd24 415 ignore=options.ignore
theotherjimmy 43:2a7da56ebd24 416 )
theotherjimmy 43:2a7da56ebd24 417 except NotSupportedException as exc:
theotherjimmy 43:2a7da56ebd24 418 args_error(parser, "%s not supported by %s" % (mcu, ide))
theotherjimmy 43:2a7da56ebd24 419 print("[Not Supported] %s" % str(exc))
theotherjimmy 43:2a7da56ebd24 420 exit(0)
The Other Jimmy 31:8ea194f6145b 421
The Other Jimmy 31:8ea194f6145b 422 if __name__ == "__main__":
The Other Jimmy 31:8ea194f6145b 423 main()