Clone of official tools
project.py@47:21ae3e5a7128, 2021-02-04 (annotated)
- Committer:
- Anders Blomdell
- Date:
- Thu Feb 04 17:17:13 2021 +0100
- Revision:
- 47:21ae3e5a7128
- Parent:
- 46:e502676b7f84
Add a few normpath calls
Who changed what in which revision?
User | Revision | Line number | New 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 | |
Anders Blomdell |
46:e502676b7f84 | 133 | if notify == None: |
Anders Blomdell |
46:e502676b7f84 | 134 | notify = TerminalNotifier() |
theotherjimmy |
40:7d3fa6b99b2b | 135 | # Find build system profile |
theotherjimmy |
40:7d3fa6b99b2b | 136 | profile = None |
theotherjimmy |
40:7d3fa6b99b2b | 137 | targets_json = None |
theotherjimmy |
40:7d3fa6b99b2b | 138 | for path in src: |
theotherjimmy |
40:7d3fa6b99b2b | 139 | profile = find_build_profile(path) or profile |
theotherjimmy |
40:7d3fa6b99b2b | 140 | if profile: |
theotherjimmy |
40:7d3fa6b99b2b | 141 | targets_json = join(dirname(dirname(abspath(__file__))), 'legacy_targets.json') |
theotherjimmy |
40:7d3fa6b99b2b | 142 | else: |
theotherjimmy |
40:7d3fa6b99b2b | 143 | targets_json = find_targets_json(path) or targets_json |
theotherjimmy |
40:7d3fa6b99b2b | 144 | |
theotherjimmy |
40:7d3fa6b99b2b | 145 | # Apply targets.json to active targets |
theotherjimmy |
40:7d3fa6b99b2b | 146 | if targets_json: |
theotherjimmy |
43:2a7da56ebd24 | 147 | notify.info("Using targets from %s" % targets_json) |
theotherjimmy |
40:7d3fa6b99b2b | 148 | set_targets_json_location(targets_json) |
theotherjimmy |
40:7d3fa6b99b2b | 149 | |
theotherjimmy |
40:7d3fa6b99b2b | 150 | # Apply profile to toolchains |
theotherjimmy |
40:7d3fa6b99b2b | 151 | if profile: |
theotherjimmy |
40:7d3fa6b99b2b | 152 | def init_hook(self): |
theotherjimmy |
40:7d3fa6b99b2b | 153 | profile_data = get_toolchain_profile(self.name, profile) |
theotherjimmy |
40:7d3fa6b99b2b | 154 | if not profile_data: |
theotherjimmy |
40:7d3fa6b99b2b | 155 | return |
theotherjimmy |
43:2a7da56ebd24 | 156 | notify.info("Using toolchain %s profile %s" % (self.name, profile)) |
theotherjimmy |
40:7d3fa6b99b2b | 157 | |
theotherjimmy |
40:7d3fa6b99b2b | 158 | for k,v in profile_data.items(): |
theotherjimmy |
40:7d3fa6b99b2b | 159 | if self.flags.has_key(k): |
theotherjimmy |
40:7d3fa6b99b2b | 160 | self.flags[k] = v |
theotherjimmy |
40:7d3fa6b99b2b | 161 | else: |
theotherjimmy |
40:7d3fa6b99b2b | 162 | setattr(self, k, v) |
theotherjimmy |
40:7d3fa6b99b2b | 163 | |
theotherjimmy |
40:7d3fa6b99b2b | 164 | mbedToolchain.init = init_hook |
theotherjimmy |
40:7d3fa6b99b2b | 165 | |
theotherjimmy |
40:7d3fa6b99b2b | 166 | # mbed Classic/2.0/libary support # |
theotherjimmy |
40:7d3fa6b99b2b | 167 | ################################### |
theotherjimmy |
40:7d3fa6b99b2b | 168 | |
theotherjimmy |
43:2a7da56ebd24 | 169 | project_dir, name, src, lib = setup_project( |
theotherjimmy |
43:2a7da56ebd24 | 170 | ide, |
theotherjimmy |
43:2a7da56ebd24 | 171 | target, |
theotherjimmy |
43:2a7da56ebd24 | 172 | bool(zip_proj), |
theotherjimmy |
43:2a7da56ebd24 | 173 | program=project_id, |
theotherjimmy |
43:2a7da56ebd24 | 174 | source_dir=src, |
theotherjimmy |
43:2a7da56ebd24 | 175 | build=build, |
theotherjimmy |
43:2a7da56ebd24 | 176 | export_path=export_path, |
theotherjimmy |
43:2a7da56ebd24 | 177 | ) |
theotherjimmy |
43:2a7da56ebd24 | 178 | |
theotherjimmy |
43:2a7da56ebd24 | 179 | zip_name = name+".zip" if zip_proj else None |
theotherjimmy |
43:2a7da56ebd24 | 180 | |
theotherjimmy |
43:2a7da56ebd24 | 181 | return export_project( |
theotherjimmy |
43:2a7da56ebd24 | 182 | src, |
theotherjimmy |
43:2a7da56ebd24 | 183 | project_dir, |
theotherjimmy |
43:2a7da56ebd24 | 184 | target, |
theotherjimmy |
43:2a7da56ebd24 | 185 | ide, |
theotherjimmy |
43:2a7da56ebd24 | 186 | name=name, |
theotherjimmy |
43:2a7da56ebd24 | 187 | macros=macros, |
theotherjimmy |
43:2a7da56ebd24 | 188 | libraries_paths=lib, |
theotherjimmy |
43:2a7da56ebd24 | 189 | zip_proj=zip_name, |
theotherjimmy |
43:2a7da56ebd24 | 190 | build_profile=build_profile, |
theotherjimmy |
43:2a7da56ebd24 | 191 | notify=TerminalNotifier(), |
theotherjimmy |
43:2a7da56ebd24 | 192 | app_config=app_config, |
theotherjimmy |
43:2a7da56ebd24 | 193 | ignore=ignore |
theotherjimmy |
43:2a7da56ebd24 | 194 | ) |
theotherjimmy |
43:2a7da56ebd24 | 195 | |
theotherjimmy |
43:2a7da56ebd24 | 196 | def clean(source_dir): |
theotherjimmy |
43:2a7da56ebd24 | 197 | if exists(EXPORT_DIR): |
theotherjimmy |
43:2a7da56ebd24 | 198 | rmtree(EXPORT_DIR) |
theotherjimmy |
43:2a7da56ebd24 | 199 | for cls in EXPORTERS.values(): |
theotherjimmy |
43:2a7da56ebd24 | 200 | try: |
theotherjimmy |
43:2a7da56ebd24 | 201 | cls.clean(basename(abspath(source_dir[0]))) |
theotherjimmy |
43:2a7da56ebd24 | 202 | except (NotImplementedError, IOError, OSError): |
theotherjimmy |
43:2a7da56ebd24 | 203 | pass |
theotherjimmy |
43:2a7da56ebd24 | 204 | for f in list(EXPORTERS.values())[0].CLEAN_FILES: |
theotherjimmy |
43:2a7da56ebd24 | 205 | try: |
theotherjimmy |
43:2a7da56ebd24 | 206 | remove(f) |
theotherjimmy |
43:2a7da56ebd24 | 207 | except (IOError, OSError): |
theotherjimmy |
43:2a7da56ebd24 | 208 | pass |
theotherjimmy |
43:2a7da56ebd24 | 209 | |
The Other Jimmy |
35:da9c89f8be7d | 210 | return export_project(src, project_dir, target, ide, name=name, |
The Other Jimmy |
35:da9c89f8be7d | 211 | macros=macros, libraries_paths=lib, zip_proj=zip_name, |
theotherjimmy |
43:2a7da56ebd24 | 212 | build_profile=build_profile, notify=notify, |
theotherjimmy |
43:2a7da56ebd24 | 213 | app_config=app_config, ignore=ignore) |
The Other Jimmy |
31:8ea194f6145b | 214 | |
The Other Jimmy |
31:8ea194f6145b | 215 | |
theotherjimmy |
43:2a7da56ebd24 | 216 | def get_args(argv): |
screamer | 22:9e85236d8716 | 217 | parser = ArgumentParser() |
screamer | 0:66f3b5499f7f | 218 | |
screamer | 0:66f3b5499f7f | 219 | targetnames = TARGET_NAMES |
screamer | 0:66f3b5499f7f | 220 | targetnames.sort() |
theotherjimmy |
43:2a7da56ebd24 | 221 | toolchainlist = list(EXPORTERS.keys()) + list(EXPORTER_ALIASES.keys()) |
screamer | 0:66f3b5499f7f | 222 | toolchainlist.sort() |
screamer | 0:66f3b5499f7f | 223 | |
theotherjimmy |
43:2a7da56ebd24 | 224 | parser.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 225 | "-m", "--mcu", |
theotherjimmy |
43:2a7da56ebd24 | 226 | metavar="MCU", |
theotherjimmy |
43:2a7da56ebd24 | 227 | help="generate project for the given MCU ({})".format( |
theotherjimmy |
43:2a7da56ebd24 | 228 | ', '.join(targetnames)) |
theotherjimmy |
43:2a7da56ebd24 | 229 | ) |
screamer | 0:66f3b5499f7f | 230 | |
theotherjimmy |
43:2a7da56ebd24 | 231 | parser.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 232 | "-i", |
theotherjimmy |
43:2a7da56ebd24 | 233 | dest="ide", |
theotherjimmy |
43:2a7da56ebd24 | 234 | type=argparse_force_lowercase_type( |
theotherjimmy |
43:2a7da56ebd24 | 235 | toolchainlist, "toolchain"), |
theotherjimmy |
43:2a7da56ebd24 | 236 | help="The target IDE: %s" % str(toolchainlist) |
theotherjimmy |
43:2a7da56ebd24 | 237 | ) |
screamer | 0:66f3b5499f7f | 238 | |
theotherjimmy |
43:2a7da56ebd24 | 239 | parser.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 240 | "-c", "--clean", |
theotherjimmy |
43:2a7da56ebd24 | 241 | action="store_true", |
theotherjimmy |
43:2a7da56ebd24 | 242 | default=False, |
theotherjimmy |
43:2a7da56ebd24 | 243 | help="clean the export directory" |
theotherjimmy |
43:2a7da56ebd24 | 244 | ) |
screamer | 0:66f3b5499f7f | 245 | |
screamer | 22:9e85236d8716 | 246 | group = parser.add_mutually_exclusive_group(required=False) |
The Other Jimmy |
31:8ea194f6145b | 247 | group.add_argument( |
The Other Jimmy |
31:8ea194f6145b | 248 | "-p", |
The Other Jimmy |
31:8ea194f6145b | 249 | type=test_known, |
The Other Jimmy |
31:8ea194f6145b | 250 | dest="program", |
theotherjimmy |
43:2a7da56ebd24 | 251 | help="The index of the desired test program: [0-%s]" % (len(TESTS) - 1) |
theotherjimmy |
43:2a7da56ebd24 | 252 | ) |
screamer | 0:66f3b5499f7f | 253 | |
theotherjimmy |
43:2a7da56ebd24 | 254 | group.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 255 | "-n", |
theotherjimmy |
43:2a7da56ebd24 | 256 | type=test_name_known, |
theotherjimmy |
43:2a7da56ebd24 | 257 | dest="program", |
theotherjimmy |
43:2a7da56ebd24 | 258 | help="The name of the desired test program" |
theotherjimmy |
43:2a7da56ebd24 | 259 | ) |
screamer | 0:66f3b5499f7f | 260 | |
theotherjimmy |
43:2a7da56ebd24 | 261 | parser.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 262 | "-b", |
theotherjimmy |
43:2a7da56ebd24 | 263 | dest="build", |
theotherjimmy |
43:2a7da56ebd24 | 264 | default=False, |
theotherjimmy |
43:2a7da56ebd24 | 265 | action="store_true", |
theotherjimmy |
43:2a7da56ebd24 | 266 | help="use the mbed library build, instead of the sources" |
theotherjimmy |
43:2a7da56ebd24 | 267 | ) |
screamer | 0:66f3b5499f7f | 268 | |
theotherjimmy |
43:2a7da56ebd24 | 269 | group.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 270 | "-L", "--list-tests", |
theotherjimmy |
43:2a7da56ebd24 | 271 | action="store_true", |
theotherjimmy |
43:2a7da56ebd24 | 272 | dest="list_tests", |
theotherjimmy |
43:2a7da56ebd24 | 273 | default=False, |
theotherjimmy |
43:2a7da56ebd24 | 274 | help="list available programs in order and exit" |
theotherjimmy |
43:2a7da56ebd24 | 275 | ) |
screamer | 0:66f3b5499f7f | 276 | |
theotherjimmy |
43:2a7da56ebd24 | 277 | group.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 278 | "-S", "--list-matrix", |
theotherjimmy |
43:2a7da56ebd24 | 279 | dest="supported_ides", |
theotherjimmy |
43:2a7da56ebd24 | 280 | default=False, |
theotherjimmy |
43:2a7da56ebd24 | 281 | const="matrix", |
theotherjimmy |
43:2a7da56ebd24 | 282 | choices=["matrix", "ides"], |
theotherjimmy |
43:2a7da56ebd24 | 283 | nargs="?", |
theotherjimmy |
43:2a7da56ebd24 | 284 | help="displays supported matrix of MCUs and IDEs" |
theotherjimmy |
43:2a7da56ebd24 | 285 | ) |
theotherjimmy |
43:2a7da56ebd24 | 286 | |
theotherjimmy |
43:2a7da56ebd24 | 287 | group.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 288 | "--update-packs", |
theotherjimmy |
43:2a7da56ebd24 | 289 | dest="update_packs", |
theotherjimmy |
43:2a7da56ebd24 | 290 | action="store_true", |
theotherjimmy |
43:2a7da56ebd24 | 291 | default=False |
theotherjimmy |
43:2a7da56ebd24 | 292 | ) |
theotherjimmy |
43:2a7da56ebd24 | 293 | |
theotherjimmy |
43:2a7da56ebd24 | 294 | parser.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 295 | "-E", |
theotherjimmy |
43:2a7da56ebd24 | 296 | action="store_true", |
theotherjimmy |
43:2a7da56ebd24 | 297 | dest="supported_ides_html", |
theotherjimmy |
43:2a7da56ebd24 | 298 | default=False, |
theotherjimmy |
43:2a7da56ebd24 | 299 | help="Generate a markdown version of the results of -S in README.md" |
theotherjimmy |
43:2a7da56ebd24 | 300 | ) |
screamer | 0:66f3b5499f7f | 301 | |
theotherjimmy |
43:2a7da56ebd24 | 302 | parser.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 303 | "--build", |
theotherjimmy |
43:2a7da56ebd24 | 304 | type=argparse_filestring_type, |
theotherjimmy |
43:2a7da56ebd24 | 305 | dest="build_dir", |
theotherjimmy |
43:2a7da56ebd24 | 306 | default=None, |
theotherjimmy |
43:2a7da56ebd24 | 307 | help="Directory for the exported project files" |
theotherjimmy |
43:2a7da56ebd24 | 308 | ) |
screamer | 0:66f3b5499f7f | 309 | |
theotherjimmy |
43:2a7da56ebd24 | 310 | parser.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 311 | "--source", |
theotherjimmy |
43:2a7da56ebd24 | 312 | action="append", |
theotherjimmy |
43:2a7da56ebd24 | 313 | type=argparse_filestring_type, |
theotherjimmy |
43:2a7da56ebd24 | 314 | dest="source_dir", |
theotherjimmy |
43:2a7da56ebd24 | 315 | default=[], |
theotherjimmy |
43:2a7da56ebd24 | 316 | help="The source (input) directory" |
theotherjimmy |
43:2a7da56ebd24 | 317 | ) |
theotherjimmy |
43:2a7da56ebd24 | 318 | |
theotherjimmy |
43:2a7da56ebd24 | 319 | parser.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 320 | "-D", |
theotherjimmy |
43:2a7da56ebd24 | 321 | action="append", |
theotherjimmy |
43:2a7da56ebd24 | 322 | dest="macros", |
theotherjimmy |
43:2a7da56ebd24 | 323 | help="Add a macro definition" |
theotherjimmy |
43:2a7da56ebd24 | 324 | ) |
screamer | 0:66f3b5499f7f | 325 | |
theotherjimmy |
43:2a7da56ebd24 | 326 | parser.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 327 | "--profile", |
theotherjimmy |
43:2a7da56ebd24 | 328 | dest="profile", |
theotherjimmy |
43:2a7da56ebd24 | 329 | action="append", |
theotherjimmy |
43:2a7da56ebd24 | 330 | type=argparse_profile_filestring_type, |
theotherjimmy |
43:2a7da56ebd24 | 331 | help=("Build profile to use. Can be either path to json" |
theotherjimmy |
43:2a7da56ebd24 | 332 | "file or one of the default one ({})".format( |
theotherjimmy |
43:2a7da56ebd24 | 333 | ", ".join(list_profiles()))), |
theotherjimmy |
43:2a7da56ebd24 | 334 | default=[] |
theotherjimmy |
43:2a7da56ebd24 | 335 | ) |
theotherjimmy |
43:2a7da56ebd24 | 336 | |
theotherjimmy |
43:2a7da56ebd24 | 337 | parser.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 338 | "--app-config", |
theotherjimmy |
43:2a7da56ebd24 | 339 | dest="app_config", |
theotherjimmy |
43:2a7da56ebd24 | 340 | default=None |
theotherjimmy |
43:2a7da56ebd24 | 341 | ) |
The Other Jimmy |
31:8ea194f6145b | 342 | |
theotherjimmy |
43:2a7da56ebd24 | 343 | parser.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 344 | "-z", |
theotherjimmy |
43:2a7da56ebd24 | 345 | action="store_true", |
theotherjimmy |
43:2a7da56ebd24 | 346 | default=None, |
theotherjimmy |
43:2a7da56ebd24 | 347 | dest="zip", |
theotherjimmy |
43:2a7da56ebd24 | 348 | ) |
The Other Jimmy |
31:8ea194f6145b | 349 | |
theotherjimmy |
43:2a7da56ebd24 | 350 | parser.add_argument( |
theotherjimmy |
43:2a7da56ebd24 | 351 | "--ignore", |
theotherjimmy |
43:2a7da56ebd24 | 352 | dest="ignore", |
theotherjimmy |
43:2a7da56ebd24 | 353 | type=argparse_many(str), |
theotherjimmy |
43:2a7da56ebd24 | 354 | default=None, |
theotherjimmy |
43:2a7da56ebd24 | 355 | help=("Comma separated list of patterns to add to mbedignore " |
theotherjimmy |
43:2a7da56ebd24 | 356 | "(eg. ./main.cpp)") |
theotherjimmy |
43:2a7da56ebd24 | 357 | ) |
screamer | 0:66f3b5499f7f | 358 | |
theotherjimmy |
43:2a7da56ebd24 | 359 | return parser.parse_args(argv), parser |
theotherjimmy |
43:2a7da56ebd24 | 360 | |
theotherjimmy |
43:2a7da56ebd24 | 361 | |
theotherjimmy |
43:2a7da56ebd24 | 362 | def main(): |
theotherjimmy |
43:2a7da56ebd24 | 363 | """Entry point""" |
theotherjimmy |
43:2a7da56ebd24 | 364 | # Parse Options |
theotherjimmy |
43:2a7da56ebd24 | 365 | options, parser = get_args(sys.argv[1:]) |
screamer | 0:66f3b5499f7f | 366 | |
screamer | 0:66f3b5499f7f | 367 | # Print available tests in order and exit |
theotherjimmy |
43:2a7da56ebd24 | 368 | if options.list_tests: |
theotherjimmy |
43:2a7da56ebd24 | 369 | print('\n'.join(str(test) for test in sorted(TEST_MAP.values()))) |
theotherjimmy |
43:2a7da56ebd24 | 370 | elif options.supported_ides: |
The Other Jimmy |
36:96847d42f010 | 371 | if options.supported_ides == "matrix": |
The Other Jimmy |
36:96847d42f010 | 372 | print_large_string(mcu_ide_matrix()) |
The Other Jimmy |
36:96847d42f010 | 373 | elif options.supported_ides == "ides": |
theotherjimmy |
43:2a7da56ebd24 | 374 | print(mcu_ide_list()) |
theotherjimmy |
43:2a7da56ebd24 | 375 | elif options.supported_ides_html: |
screamer | 0:66f3b5499f7f | 376 | html = mcu_ide_matrix(verbose_html=True) |
theotherjimmy |
43:2a7da56ebd24 | 377 | with open("README.md", "w") as readme: |
theotherjimmy |
43:2a7da56ebd24 | 378 | readme.write("Exporter IDE/Platform Support\n") |
theotherjimmy |
43:2a7da56ebd24 | 379 | readme.write("-----------------------------------\n") |
theotherjimmy |
43:2a7da56ebd24 | 380 | readme.write("\n") |
theotherjimmy |
43:2a7da56ebd24 | 381 | readme.write(html) |
theotherjimmy |
43:2a7da56ebd24 | 382 | elif options.update_packs: |
The Other Jimmy |
31:8ea194f6145b | 383 | from tools.arm_pack_manager import Cache |
The Other Jimmy |
31:8ea194f6145b | 384 | cache = Cache(True, True) |
theotherjimmy |
43:2a7da56ebd24 | 385 | cache.cache_everything() |
theotherjimmy |
43:2a7da56ebd24 | 386 | else: |
theotherjimmy |
43:2a7da56ebd24 | 387 | # Check required arguments |
theotherjimmy |
43:2a7da56ebd24 | 388 | if not options.mcu: |
theotherjimmy |
43:2a7da56ebd24 | 389 | args_error(parser, "argument -m/--mcu is required") |
theotherjimmy |
43:2a7da56ebd24 | 390 | if not options.ide: |
theotherjimmy |
43:2a7da56ebd24 | 391 | args_error(parser, "argument -i is required") |
theotherjimmy |
43:2a7da56ebd24 | 392 | if (options.program is None) and (not options.source_dir): |
theotherjimmy |
43:2a7da56ebd24 | 393 | args_error(parser, "one of -p, -n, or --source is required") |
The Other Jimmy |
31:8ea194f6145b | 394 | |
theotherjimmy |
43:2a7da56ebd24 | 395 | if options.clean: |
theotherjimmy |
43:2a7da56ebd24 | 396 | clean(options.source_dir) |
The Other Jimmy |
35:da9c89f8be7d | 397 | |
theotherjimmy |
43:2a7da56ebd24 | 398 | ide = resolve_exporter_alias(options.ide) |
theotherjimmy |
43:2a7da56ebd24 | 399 | exporter, toolchain_name = get_exporter_toolchain(ide) |
theotherjimmy |
43:2a7da56ebd24 | 400 | profile = extract_profile(parser, options, toolchain_name, fallback="debug") |
theotherjimmy |
43:2a7da56ebd24 | 401 | mcu = extract_mcus(parser, options)[0] |
theotherjimmy |
43:2a7da56ebd24 | 402 | if not exporter.is_target_supported(mcu): |
theotherjimmy |
43:2a7da56ebd24 | 403 | args_error(parser, "%s not supported by %s" % (mcu, ide)) |
theotherjimmy |
43:2a7da56ebd24 | 404 | |
theotherjimmy |
43:2a7da56ebd24 | 405 | try: |
theotherjimmy |
43:2a7da56ebd24 | 406 | export( |
theotherjimmy |
43:2a7da56ebd24 | 407 | mcu, |
theotherjimmy |
43:2a7da56ebd24 | 408 | ide, |
theotherjimmy |
43:2a7da56ebd24 | 409 | build=options.build, |
theotherjimmy |
43:2a7da56ebd24 | 410 | src=options.source_dir, |
theotherjimmy |
43:2a7da56ebd24 | 411 | macros=options.macros, |
theotherjimmy |
43:2a7da56ebd24 | 412 | project_id=options.program, |
theotherjimmy |
43:2a7da56ebd24 | 413 | zip_proj=not bool(options.source_dir) or options.zip, |
theotherjimmy |
43:2a7da56ebd24 | 414 | build_profile=profile, |
theotherjimmy |
43:2a7da56ebd24 | 415 | app_config=options.app_config, |
theotherjimmy |
43:2a7da56ebd24 | 416 | export_path=options.build_dir, |
theotherjimmy |
43:2a7da56ebd24 | 417 | ignore=options.ignore |
theotherjimmy |
43:2a7da56ebd24 | 418 | ) |
theotherjimmy |
43:2a7da56ebd24 | 419 | except NotSupportedException as exc: |
theotherjimmy |
43:2a7da56ebd24 | 420 | args_error(parser, "%s not supported by %s" % (mcu, ide)) |
theotherjimmy |
43:2a7da56ebd24 | 421 | print("[Not Supported] %s" % str(exc)) |
theotherjimmy |
43:2a7da56ebd24 | 422 | exit(0) |
The Other Jimmy |
31:8ea194f6145b | 423 | |
The Other Jimmy |
31:8ea194f6145b | 424 | if __name__ == "__main__": |
The Other Jimmy |
31:8ea194f6145b | 425 | main() |