init

Dependencies:   mbed

Committer:
Nathan Yonkee
Date:
Fri Mar 02 07:16:49 2018 -0700
Revision:
10:46a4cf51ee38
Parent:
9:d58e77ebd769
remove mbed-os

Who changed what in which revision?

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