Clone of official tools

Committer:
The Other Jimmy
Date:
Thu Jul 13 15:26:26 2017 -0500
Revision:
38:399953da035d
Parent:
36:96847d42f010
Child:
43:2a7da56ebd24
Update to tools release 5.5.2

Who changed what in which revision?

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