BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

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