takashi kadono
/
Nucleo446_SSD1331
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/tools/options.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 | """ |
kadonotakashi | 0:8fdf9a60065b | 2 | mbed SDK |
kadonotakashi | 0:8fdf9a60065b | 3 | Copyright (c) 2011-2013 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 4 | |
kadonotakashi | 0:8fdf9a60065b | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 6 | you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 7 | You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 8 | |
kadonotakashi | 0:8fdf9a60065b | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 10 | |
kadonotakashi | 0:8fdf9a60065b | 11 | Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 14 | See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 15 | limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 16 | """ |
kadonotakashi | 0:8fdf9a60065b | 17 | from __future__ import print_function, division, absolute_import |
kadonotakashi | 0:8fdf9a60065b | 18 | |
kadonotakashi | 0:8fdf9a60065b | 19 | from json import load |
kadonotakashi | 0:8fdf9a60065b | 20 | from os.path import join, dirname |
kadonotakashi | 0:8fdf9a60065b | 21 | from os import listdir |
kadonotakashi | 0:8fdf9a60065b | 22 | from argparse import ArgumentParser, ArgumentTypeError |
kadonotakashi | 0:8fdf9a60065b | 23 | |
kadonotakashi | 0:8fdf9a60065b | 24 | from .toolchains import TOOLCHAINS |
kadonotakashi | 0:8fdf9a60065b | 25 | from .targets import TARGET_NAMES, Target, update_target_data |
kadonotakashi | 0:8fdf9a60065b | 26 | from .utils import (argparse_force_uppercase_type, argparse_deprecate, |
kadonotakashi | 0:8fdf9a60065b | 27 | argparse_lowercase_hyphen_type, argparse_many, |
kadonotakashi | 0:8fdf9a60065b | 28 | argparse_filestring_type, args_error, |
kadonotakashi | 0:8fdf9a60065b | 29 | argparse_profile_filestring_type) |
kadonotakashi | 0:8fdf9a60065b | 30 | |
kadonotakashi | 0:8fdf9a60065b | 31 | FLAGS_DEPRECATION_MESSAGE = "Please use the --profile argument instead.\n"\ |
kadonotakashi | 0:8fdf9a60065b | 32 | "Documentation may be found in "\ |
kadonotakashi | 0:8fdf9a60065b | 33 | "docs/Toolchain_Profiles.md" |
kadonotakashi | 0:8fdf9a60065b | 34 | |
kadonotakashi | 0:8fdf9a60065b | 35 | def get_default_options_parser(add_clean=True, add_options=True, |
kadonotakashi | 0:8fdf9a60065b | 36 | add_app_config=False): |
kadonotakashi | 0:8fdf9a60065b | 37 | """Create a new options parser with the default compiler options added |
kadonotakashi | 0:8fdf9a60065b | 38 | |
kadonotakashi | 0:8fdf9a60065b | 39 | Keyword arguments: |
kadonotakashi | 0:8fdf9a60065b | 40 | add_clean - add the clean argument? |
kadonotakashi | 0:8fdf9a60065b | 41 | add_options - add the options argument? |
kadonotakashi | 0:8fdf9a60065b | 42 | """ |
kadonotakashi | 0:8fdf9a60065b | 43 | parser = ArgumentParser() |
kadonotakashi | 0:8fdf9a60065b | 44 | |
kadonotakashi | 0:8fdf9a60065b | 45 | targetnames = TARGET_NAMES |
kadonotakashi | 0:8fdf9a60065b | 46 | targetnames.sort() |
kadonotakashi | 0:8fdf9a60065b | 47 | toolchainlist = list(TOOLCHAINS) |
kadonotakashi | 0:8fdf9a60065b | 48 | toolchainlist.sort() |
kadonotakashi | 0:8fdf9a60065b | 49 | |
kadonotakashi | 0:8fdf9a60065b | 50 | parser.add_argument("-m", "--mcu", |
kadonotakashi | 0:8fdf9a60065b | 51 | help=("build for the given MCU (%s)" % |
kadonotakashi | 0:8fdf9a60065b | 52 | ', '.join(targetnames)), |
kadonotakashi | 0:8fdf9a60065b | 53 | metavar="MCU") |
kadonotakashi | 0:8fdf9a60065b | 54 | |
kadonotakashi | 0:8fdf9a60065b | 55 | parser.add_argument("-t", "--tool", |
kadonotakashi | 0:8fdf9a60065b | 56 | help=("build using the given TOOLCHAIN (%s)" % |
kadonotakashi | 0:8fdf9a60065b | 57 | ', '.join(toolchainlist)), |
kadonotakashi | 0:8fdf9a60065b | 58 | metavar="TOOLCHAIN", |
kadonotakashi | 0:8fdf9a60065b | 59 | type=argparse_many( |
kadonotakashi | 0:8fdf9a60065b | 60 | argparse_force_uppercase_type( |
kadonotakashi | 0:8fdf9a60065b | 61 | toolchainlist, "toolchain"))) |
kadonotakashi | 0:8fdf9a60065b | 62 | |
kadonotakashi | 0:8fdf9a60065b | 63 | parser.add_argument("--color", |
kadonotakashi | 0:8fdf9a60065b | 64 | help="print Warnings, and Errors in color", |
kadonotakashi | 0:8fdf9a60065b | 65 | action="store_true", default=False) |
kadonotakashi | 0:8fdf9a60065b | 66 | |
kadonotakashi | 0:8fdf9a60065b | 67 | parser.add_argument("--cflags", |
kadonotakashi | 0:8fdf9a60065b | 68 | type=argparse_deprecate(FLAGS_DEPRECATION_MESSAGE), |
kadonotakashi | 0:8fdf9a60065b | 69 | help="Deprecated. " + FLAGS_DEPRECATION_MESSAGE) |
kadonotakashi | 0:8fdf9a60065b | 70 | |
kadonotakashi | 0:8fdf9a60065b | 71 | parser.add_argument("--asmflags", |
kadonotakashi | 0:8fdf9a60065b | 72 | type=argparse_deprecate(FLAGS_DEPRECATION_MESSAGE), |
kadonotakashi | 0:8fdf9a60065b | 73 | help="Deprecated. " + FLAGS_DEPRECATION_MESSAGE) |
kadonotakashi | 0:8fdf9a60065b | 74 | |
kadonotakashi | 0:8fdf9a60065b | 75 | parser.add_argument("--ldflags", |
kadonotakashi | 0:8fdf9a60065b | 76 | type=argparse_deprecate(FLAGS_DEPRECATION_MESSAGE), |
kadonotakashi | 0:8fdf9a60065b | 77 | help="Deprecated. " + FLAGS_DEPRECATION_MESSAGE) |
kadonotakashi | 0:8fdf9a60065b | 78 | |
kadonotakashi | 0:8fdf9a60065b | 79 | if add_clean: |
kadonotakashi | 0:8fdf9a60065b | 80 | parser.add_argument("-c", "--clean", action="store_true", default=False, |
kadonotakashi | 0:8fdf9a60065b | 81 | help="clean the build directory") |
kadonotakashi | 0:8fdf9a60065b | 82 | |
kadonotakashi | 0:8fdf9a60065b | 83 | if add_options: |
kadonotakashi | 0:8fdf9a60065b | 84 | parser.add_argument("--profile", dest="profile", action="append", |
kadonotakashi | 0:8fdf9a60065b | 85 | type=argparse_profile_filestring_type, |
kadonotakashi | 0:8fdf9a60065b | 86 | help="Build profile to use. Can be either path to json" \ |
kadonotakashi | 0:8fdf9a60065b | 87 | "file or one of the default one ({})".format(", ".join(list_profiles())), |
kadonotakashi | 0:8fdf9a60065b | 88 | default=[]) |
kadonotakashi | 0:8fdf9a60065b | 89 | if add_app_config: |
kadonotakashi | 0:8fdf9a60065b | 90 | parser.add_argument("--app-config", default=None, dest="app_config", |
kadonotakashi | 0:8fdf9a60065b | 91 | type=argparse_filestring_type, |
kadonotakashi | 0:8fdf9a60065b | 92 | help="Path of an app configuration file (Default is to look for 'mbed_app.json')") |
kadonotakashi | 0:8fdf9a60065b | 93 | |
kadonotakashi | 0:8fdf9a60065b | 94 | return parser |
kadonotakashi | 0:8fdf9a60065b | 95 | |
kadonotakashi | 0:8fdf9a60065b | 96 | def list_profiles(): |
kadonotakashi | 0:8fdf9a60065b | 97 | """Lists available build profiles |
kadonotakashi | 0:8fdf9a60065b | 98 | |
kadonotakashi | 0:8fdf9a60065b | 99 | Checks default profile directory (mbed-os/tools/profiles/) for all the json files and return list of names only |
kadonotakashi | 0:8fdf9a60065b | 100 | """ |
kadonotakashi | 0:8fdf9a60065b | 101 | return [fn.replace(".json", "") for fn in listdir(join(dirname(__file__), "profiles")) if fn.endswith(".json")] |
kadonotakashi | 0:8fdf9a60065b | 102 | |
kadonotakashi | 0:8fdf9a60065b | 103 | def extract_profile(parser, options, toolchain, fallback="develop"): |
kadonotakashi | 0:8fdf9a60065b | 104 | """Extract a Toolchain profile from parsed options |
kadonotakashi | 0:8fdf9a60065b | 105 | |
kadonotakashi | 0:8fdf9a60065b | 106 | Positional arguments: |
kadonotakashi | 0:8fdf9a60065b | 107 | parser - parser used to parse the command line arguments |
kadonotakashi | 0:8fdf9a60065b | 108 | options - The parsed command line arguments |
kadonotakashi | 0:8fdf9a60065b | 109 | toolchain - the toolchain that the profile should be extracted for |
kadonotakashi | 0:8fdf9a60065b | 110 | """ |
kadonotakashi | 0:8fdf9a60065b | 111 | profiles = [] |
kadonotakashi | 0:8fdf9a60065b | 112 | filenames = options.profile or [join(dirname(__file__), "profiles", |
kadonotakashi | 0:8fdf9a60065b | 113 | fallback + ".json")] |
kadonotakashi | 0:8fdf9a60065b | 114 | for filename in filenames: |
kadonotakashi | 0:8fdf9a60065b | 115 | contents = load(open(filename)) |
kadonotakashi | 0:8fdf9a60065b | 116 | if toolchain not in contents: |
kadonotakashi | 0:8fdf9a60065b | 117 | args_error(parser, ("argument --profile: toolchain {} is not" |
kadonotakashi | 0:8fdf9a60065b | 118 | " supported by profile {}").format(toolchain, |
kadonotakashi | 0:8fdf9a60065b | 119 | filename)) |
kadonotakashi | 0:8fdf9a60065b | 120 | profiles.append(contents) |
kadonotakashi | 0:8fdf9a60065b | 121 | |
kadonotakashi | 0:8fdf9a60065b | 122 | return profiles |
kadonotakashi | 0:8fdf9a60065b | 123 | |
kadonotakashi | 0:8fdf9a60065b | 124 | def extract_mcus(parser, options): |
kadonotakashi | 0:8fdf9a60065b | 125 | try: |
kadonotakashi | 0:8fdf9a60065b | 126 | if options.source_dir: |
kadonotakashi | 0:8fdf9a60065b | 127 | for source_dir in options.source_dir: |
kadonotakashi | 0:8fdf9a60065b | 128 | Target.add_extra_targets(source_dir) |
kadonotakashi | 0:8fdf9a60065b | 129 | update_target_data() |
kadonotakashi | 0:8fdf9a60065b | 130 | except KeyError: |
kadonotakashi | 0:8fdf9a60065b | 131 | pass |
kadonotakashi | 0:8fdf9a60065b | 132 | targetnames = TARGET_NAMES |
kadonotakashi | 0:8fdf9a60065b | 133 | targetnames.sort() |
kadonotakashi | 0:8fdf9a60065b | 134 | try: |
kadonotakashi | 0:8fdf9a60065b | 135 | return argparse_many(argparse_force_uppercase_type(targetnames, "MCU"))(options.mcu) |
kadonotakashi | 0:8fdf9a60065b | 136 | except ArgumentTypeError as exc: |
kadonotakashi | 0:8fdf9a60065b | 137 | args_error(parser, "argument -m/--mcu: {}".format(str(exc))) |
kadonotakashi | 0:8fdf9a60065b | 138 |