mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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