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