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