Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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