Clone of official tools

Committer:
The Other Jimmy
Date:
Wed Feb 15 13:53:18 2017 -0600
Revision:
35:da9c89f8be7d
Parent:
31:8ea194f6145b
Child:
36:96847d42f010
Update tools to mbed-os 5.3.5

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
screamer 22:9e85236d8716 20 from argparse import ArgumentParser
screamer 0:66f3b5499f7f 21 from tools.toolchains import TOOLCHAINS
screamer 0:66f3b5499f7f 22 from tools.targets import TARGET_NAMES
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)),
screamer 29:1210849dba19 50 metavar="MCU",
screamer 29:1210849dba19 51 type=argparse_many(
screamer 29:1210849dba19 52 argparse_force_uppercase_type(
screamer 29:1210849dba19 53 targetnames, "MCU")))
screamer 0:66f3b5499f7f 54
screamer 22:9e85236d8716 55 parser.add_argument("-t", "--tool",
screamer 29:1210849dba19 56 help=("build using the given TOOLCHAIN (%s)" %
screamer 29:1210849dba19 57 ', '.join(toolchainlist)),
screamer 29:1210849dba19 58 metavar="TOOLCHAIN",
screamer 29:1210849dba19 59 type=argparse_many(
screamer 29:1210849dba19 60 argparse_force_uppercase_type(
screamer 29:1210849dba19 61 toolchainlist, "toolchain")))
screamer 22:9e85236d8716 62
screamer 22:9e85236d8716 63 parser.add_argument("--color",
screamer 22:9e85236d8716 64 help="print Warnings, and Errors in color",
screamer 22:9e85236d8716 65 action="store_true", default=False)
screamer 0:66f3b5499f7f 66
The Other Jimmy 31:8ea194f6145b 67 parser.add_argument("--cflags",
The Other Jimmy 31:8ea194f6145b 68 type=argparse_deprecate(FLAGS_DEPRECATION_MESSAGE),
The Other Jimmy 31:8ea194f6145b 69 help="Deprecated. " + FLAGS_DEPRECATION_MESSAGE)
screamer 29:1210849dba19 70
The Other Jimmy 31:8ea194f6145b 71 parser.add_argument("--asmflags",
The Other Jimmy 31:8ea194f6145b 72 type=argparse_deprecate(FLAGS_DEPRECATION_MESSAGE),
The Other Jimmy 31:8ea194f6145b 73 help="Deprecated. " + FLAGS_DEPRECATION_MESSAGE)
screamer 29:1210849dba19 74
The Other Jimmy 31:8ea194f6145b 75 parser.add_argument("--ldflags",
The Other Jimmy 31:8ea194f6145b 76 type=argparse_deprecate(FLAGS_DEPRECATION_MESSAGE),
The Other Jimmy 31:8ea194f6145b 77 help="Deprecated. " + FLAGS_DEPRECATION_MESSAGE)
screamer 29:1210849dba19 78
screamer 13:ab47a20b66f0 79 if add_clean:
screamer 22:9e85236d8716 80 parser.add_argument("-c", "--clean", action="store_true", default=False,
screamer 29:1210849dba19 81 help="clean the build directory")
screamer 0:66f3b5499f7f 82
screamer 13:ab47a20b66f0 83 if add_options:
The Other Jimmy 31:8ea194f6145b 84 parser.add_argument("--profile", dest="profile", action="append",
The Other Jimmy 31:8ea194f6145b 85 type=argparse_profile_filestring_type,
The Other Jimmy 31:8ea194f6145b 86 help="Build profile to use. Can be either path to json" \
The Other Jimmy 31:8ea194f6145b 87 "file or one of the default one ({})".format(", ".join(list_profiles())),
The Other Jimmy 31:8ea194f6145b 88 default=[])
The Other Jimmy 31:8ea194f6145b 89 if add_app_config:
The Other Jimmy 31:8ea194f6145b 90 parser.add_argument("--app-config", default=None, dest="app_config",
The Other Jimmy 31:8ea194f6145b 91 type=argparse_filestring_type,
The Other Jimmy 31:8ea194f6145b 92 help="Path of an app configuration file (Default is to look for 'mbed_app.json')")
screamer 0:66f3b5499f7f 93
screamer 0:66f3b5499f7f 94 return parser
The Other Jimmy 31:8ea194f6145b 95
The Other Jimmy 31:8ea194f6145b 96 def list_profiles():
The Other Jimmy 31:8ea194f6145b 97 """Lists available build profiles
The Other Jimmy 31:8ea194f6145b 98
The Other Jimmy 31:8ea194f6145b 99 Checks default profile directory (mbed-os/tools/profiles/) for all the json files and return list of names only
The Other Jimmy 31:8ea194f6145b 100 """
The Other Jimmy 31:8ea194f6145b 101 return [fn.replace(".json", "") for fn in listdir(join(dirname(__file__), "profiles")) if fn.endswith(".json")]
The Other Jimmy 31:8ea194f6145b 102
The Other Jimmy 35:da9c89f8be7d 103 def extract_profile(parser, options, toolchain, fallback="default"):
The Other Jimmy 31:8ea194f6145b 104 """Extract a Toolchain profile from parsed options
The Other Jimmy 31:8ea194f6145b 105
The Other Jimmy 31:8ea194f6145b 106 Positional arguments:
The Other Jimmy 31:8ea194f6145b 107 parser - parser used to parse the command line arguments
The Other Jimmy 31:8ea194f6145b 108 options - The parsed command line arguments
The Other Jimmy 31:8ea194f6145b 109 toolchain - the toolchain that the profile should be extracted for
The Other Jimmy 31:8ea194f6145b 110 """
The Other Jimmy 31:8ea194f6145b 111 profile = {'c': [], 'cxx': [], 'ld': [], 'common': [], 'asm': []}
The Other Jimmy 31:8ea194f6145b 112 filenames = options.profile or [join(dirname(__file__), "profiles",
The Other Jimmy 35:da9c89f8be7d 113 fallback + ".json")]
The Other Jimmy 31:8ea194f6145b 114 for filename in filenames:
The Other Jimmy 31:8ea194f6145b 115 contents = load(open(filename))
The Other Jimmy 31:8ea194f6145b 116 try:
The Other Jimmy 31:8ea194f6145b 117 for key in profile.iterkeys():
The Other Jimmy 31:8ea194f6145b 118 profile[key] += contents[toolchain][key]
The Other Jimmy 31:8ea194f6145b 119 except KeyError:
The Other Jimmy 31:8ea194f6145b 120 args_error(parser, ("argument --profile: toolchain {} is not"
The Other Jimmy 31:8ea194f6145b 121 " supported by profile {}").format(toolchain,
The Other Jimmy 31:8ea194f6145b 122 filename))
The Other Jimmy 31:8ea194f6145b 123 return profile