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 #! /usr/bin/env python2
dkato 0:f782d9c66c49 2 """
dkato 0:f782d9c66c49 3 mbed SDK
dkato 0:f782d9c66c49 4 Copyright (c) 2011-2013 ARM Limited
dkato 0:f782d9c66c49 5
dkato 0:f782d9c66c49 6 Licensed under the Apache License, Version 2.0 (the "License");
dkato 0:f782d9c66c49 7 you may not use this file except in compliance with the License.
dkato 0:f782d9c66c49 8 You may obtain a copy of the License at
dkato 0:f782d9c66c49 9
dkato 0:f782d9c66c49 10 http://www.apache.org/licenses/LICENSE-2.0
dkato 0:f782d9c66c49 11
dkato 0:f782d9c66c49 12 Unless required by applicable law or agreed to in writing, software
dkato 0:f782d9c66c49 13 distributed under the License is distributed on an "AS IS" BASIS,
dkato 0:f782d9c66c49 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dkato 0:f782d9c66c49 15 See the License for the specific language governing permissions and
dkato 0:f782d9c66c49 16 limitations under the License.
dkato 0:f782d9c66c49 17
dkato 0:f782d9c66c49 18 LIBRARIES BUILD
dkato 0:f782d9c66c49 19 """
dkato 0:f782d9c66c49 20 import sys
dkato 0:f782d9c66c49 21 from time import time
dkato 0:f782d9c66c49 22 from os.path import join, abspath, dirname
dkato 0:f782d9c66c49 23
dkato 0:f782d9c66c49 24
dkato 0:f782d9c66c49 25 # Be sure that the tools directory is in the search path
dkato 0:f782d9c66c49 26 ROOT = abspath(join(dirname(__file__), ".."))
dkato 0:f782d9c66c49 27 sys.path.insert(0, ROOT)
dkato 0:f782d9c66c49 28
dkato 0:f782d9c66c49 29
dkato 0:f782d9c66c49 30 from tools.toolchains import TOOLCHAINS, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
dkato 0:f782d9c66c49 31 from tools.toolchains import mbedToolchain
dkato 0:f782d9c66c49 32 from tools.targets import TARGET_NAMES, TARGET_MAP
dkato 0:f782d9c66c49 33 from tools.options import get_default_options_parser
dkato 0:f782d9c66c49 34 from tools.options import extract_profile
dkato 0:f782d9c66c49 35 from tools.build_api import build_library, build_mbed_libs, build_lib
dkato 0:f782d9c66c49 36 from tools.build_api import mcu_toolchain_matrix
dkato 0:f782d9c66c49 37 from tools.build_api import print_build_results
dkato 0:f782d9c66c49 38 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
dkato 0:f782d9c66c49 39 from utils import argparse_filestring_type, args_error
dkato 0:f782d9c66c49 40 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, CLI_COLOR_MAP
dkato 0:f782d9c66c49 41 from utils import argparse_filestring_type, argparse_dir_not_parent
dkato 0:f782d9c66c49 42
dkato 0:f782d9c66c49 43 if __name__ == '__main__':
dkato 0:f782d9c66c49 44 start = time()
dkato 0:f782d9c66c49 45
dkato 0:f782d9c66c49 46 # Parse Options
dkato 0:f782d9c66c49 47 parser = get_default_options_parser()
dkato 0:f782d9c66c49 48
dkato 0:f782d9c66c49 49 parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
dkato 0:f782d9c66c49 50 default=None, help="The source (input) directory", action="append")
dkato 0:f782d9c66c49 51
dkato 0:f782d9c66c49 52 parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT),
dkato 0:f782d9c66c49 53 default=None, help="The build (output) directory")
dkato 0:f782d9c66c49 54
dkato 0:f782d9c66c49 55 parser.add_argument("--no-archive", dest="no_archive", action="store_true",
dkato 0:f782d9c66c49 56 default=False, help="Do not produce archive (.ar) file, but rather .o")
dkato 0:f782d9c66c49 57
dkato 0:f782d9c66c49 58 # Extra libraries
dkato 0:f782d9c66c49 59 parser.add_argument("-r", "--rtos",
dkato 0:f782d9c66c49 60 action="store_true",
dkato 0:f782d9c66c49 61 dest="rtos",
dkato 0:f782d9c66c49 62 default=False,
dkato 0:f782d9c66c49 63 help="Compile the rtos")
dkato 0:f782d9c66c49 64
dkato 0:f782d9c66c49 65 parser.add_argument("--rpc",
dkato 0:f782d9c66c49 66 action="store_true",
dkato 0:f782d9c66c49 67 dest="rpc",
dkato 0:f782d9c66c49 68 default=False,
dkato 0:f782d9c66c49 69 help="Compile the rpc library")
dkato 0:f782d9c66c49 70
dkato 0:f782d9c66c49 71 parser.add_argument("-e", "--eth",
dkato 0:f782d9c66c49 72 action="store_true", dest="eth",
dkato 0:f782d9c66c49 73 default=False,
dkato 0:f782d9c66c49 74 help="Compile the ethernet library")
dkato 0:f782d9c66c49 75
dkato 0:f782d9c66c49 76 parser.add_argument("-U", "--usb_host",
dkato 0:f782d9c66c49 77 action="store_true",
dkato 0:f782d9c66c49 78 dest="usb_host",
dkato 0:f782d9c66c49 79 default=False,
dkato 0:f782d9c66c49 80 help="Compile the USB Host library")
dkato 0:f782d9c66c49 81
dkato 0:f782d9c66c49 82 parser.add_argument("-u", "--usb",
dkato 0:f782d9c66c49 83 action="store_true",
dkato 0:f782d9c66c49 84 dest="usb",
dkato 0:f782d9c66c49 85 default=False,
dkato 0:f782d9c66c49 86 help="Compile the USB Device library")
dkato 0:f782d9c66c49 87
dkato 0:f782d9c66c49 88 parser.add_argument("-d", "--dsp",
dkato 0:f782d9c66c49 89 action="store_true",
dkato 0:f782d9c66c49 90 dest="dsp",
dkato 0:f782d9c66c49 91 default=False,
dkato 0:f782d9c66c49 92 help="Compile the DSP library")
dkato 0:f782d9c66c49 93
dkato 0:f782d9c66c49 94 parser.add_argument("-b", "--ublox",
dkato 0:f782d9c66c49 95 action="store_true",
dkato 0:f782d9c66c49 96 dest="ublox",
dkato 0:f782d9c66c49 97 default=False,
dkato 0:f782d9c66c49 98 help="Compile the u-blox library")
dkato 0:f782d9c66c49 99
dkato 0:f782d9c66c49 100 parser.add_argument( "--cpputest",
dkato 0:f782d9c66c49 101 action="store_true",
dkato 0:f782d9c66c49 102 dest="cpputest_lib",
dkato 0:f782d9c66c49 103 default=False,
dkato 0:f782d9c66c49 104 help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)")
dkato 0:f782d9c66c49 105
dkato 0:f782d9c66c49 106 parser.add_argument("-D",
dkato 0:f782d9c66c49 107 action="append",
dkato 0:f782d9c66c49 108 dest="macros",
dkato 0:f782d9c66c49 109 help="Add a macro definition")
dkato 0:f782d9c66c49 110
dkato 0:f782d9c66c49 111 parser.add_argument("-S", "--supported-toolchains",
dkato 0:f782d9c66c49 112 action="store_true",
dkato 0:f782d9c66c49 113 dest="supported_toolchains",
dkato 0:f782d9c66c49 114 default=False,
dkato 0:f782d9c66c49 115 help="Displays supported matrix of MCUs and toolchains")
dkato 0:f782d9c66c49 116
dkato 0:f782d9c66c49 117 parser.add_argument('-f', '--filter',
dkato 0:f782d9c66c49 118 dest='general_filter_regex',
dkato 0:f782d9c66c49 119 default=None,
dkato 0:f782d9c66c49 120 help='For some commands you can use filter to filter out results')
dkato 0:f782d9c66c49 121
dkato 0:f782d9c66c49 122 parser.add_argument("-j", "--jobs", type=int, dest="jobs",
dkato 0:f782d9c66c49 123 default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
dkato 0:f782d9c66c49 124 parser.add_argument("-N", "--artifact-name", dest="artifact_name",
dkato 0:f782d9c66c49 125 default=None, help="The built project's name")
dkato 0:f782d9c66c49 126
dkato 0:f782d9c66c49 127 parser.add_argument("-v", "--verbose",
dkato 0:f782d9c66c49 128 action="store_true",
dkato 0:f782d9c66c49 129 dest="verbose",
dkato 0:f782d9c66c49 130 default=False,
dkato 0:f782d9c66c49 131 help="Verbose diagnostic output")
dkato 0:f782d9c66c49 132
dkato 0:f782d9c66c49 133 parser.add_argument("--silent",
dkato 0:f782d9c66c49 134 action="store_true",
dkato 0:f782d9c66c49 135 dest="silent",
dkato 0:f782d9c66c49 136 default=False,
dkato 0:f782d9c66c49 137 help="Silent diagnostic output (no copy, compile notification)")
dkato 0:f782d9c66c49 138
dkato 0:f782d9c66c49 139 parser.add_argument("-x", "--extra-verbose-notifications",
dkato 0:f782d9c66c49 140 action="store_true",
dkato 0:f782d9c66c49 141 dest="extra_verbose_notify",
dkato 0:f782d9c66c49 142 default=False,
dkato 0:f782d9c66c49 143 help="Makes compiler more verbose, CI friendly.")
dkato 0:f782d9c66c49 144
dkato 0:f782d9c66c49 145 options = parser.parse_args()
dkato 0:f782d9c66c49 146
dkato 0:f782d9c66c49 147 # Only prints matrix of supported toolchains
dkato 0:f782d9c66c49 148 if options.supported_toolchains:
dkato 0:f782d9c66c49 149 print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
dkato 0:f782d9c66c49 150 exit(0)
dkato 0:f782d9c66c49 151
dkato 0:f782d9c66c49 152
dkato 0:f782d9c66c49 153 # Get target list
dkato 0:f782d9c66c49 154 targets = options.mcu if options.mcu else TARGET_NAMES
dkato 0:f782d9c66c49 155
dkato 0:f782d9c66c49 156 # Get toolchains list
dkato 0:f782d9c66c49 157 toolchains = options.tool if options.tool else TOOLCHAINS
dkato 0:f782d9c66c49 158
dkato 0:f782d9c66c49 159 if options.source_dir and not options.build_dir:
dkato 0:f782d9c66c49 160 args_error(parser, "argument --build is required by argument --source")
dkato 0:f782d9c66c49 161
dkato 0:f782d9c66c49 162 if options.color:
dkato 0:f782d9c66c49 163 # This import happens late to prevent initializing colorization when we don't need it
dkato 0:f782d9c66c49 164 import colorize
dkato 0:f782d9c66c49 165 if options.verbose:
dkato 0:f782d9c66c49 166 notify = mbedToolchain.print_notify_verbose
dkato 0:f782d9c66c49 167 else:
dkato 0:f782d9c66c49 168 notify = mbedToolchain.print_notify
dkato 0:f782d9c66c49 169 notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify)
dkato 0:f782d9c66c49 170 else:
dkato 0:f782d9c66c49 171 notify = None
dkato 0:f782d9c66c49 172
dkato 0:f782d9c66c49 173 # Get libraries list
dkato 0:f782d9c66c49 174 libraries = []
dkato 0:f782d9c66c49 175
dkato 0:f782d9c66c49 176 # Additional Libraries
dkato 0:f782d9c66c49 177 if options.rtos:
dkato 0:f782d9c66c49 178 libraries.extend(["rtx", "rtos"])
dkato 0:f782d9c66c49 179 if options.rpc:
dkato 0:f782d9c66c49 180 libraries.extend(["rpc"])
dkato 0:f782d9c66c49 181 if options.eth:
dkato 0:f782d9c66c49 182 libraries.append("eth")
dkato 0:f782d9c66c49 183 if options.usb:
dkato 0:f782d9c66c49 184 libraries.append("usb")
dkato 0:f782d9c66c49 185 if options.usb_host:
dkato 0:f782d9c66c49 186 libraries.append("usb_host")
dkato 0:f782d9c66c49 187 if options.dsp:
dkato 0:f782d9c66c49 188 libraries.extend(["dsp"])
dkato 0:f782d9c66c49 189 if options.ublox:
dkato 0:f782d9c66c49 190 libraries.extend(["rtx", "rtos", "usb_host", "ublox"])
dkato 0:f782d9c66c49 191 if options.cpputest_lib:
dkato 0:f782d9c66c49 192 libraries.extend(["cpputest"])
dkato 0:f782d9c66c49 193
dkato 0:f782d9c66c49 194 # Build results
dkato 0:f782d9c66c49 195 failures = []
dkato 0:f782d9c66c49 196 successes = []
dkato 0:f782d9c66c49 197 skipped = []
dkato 0:f782d9c66c49 198
dkato 0:f782d9c66c49 199 for toolchain in toolchains:
dkato 0:f782d9c66c49 200 if not TOOLCHAIN_CLASSES[toolchain].check_executable():
dkato 0:f782d9c66c49 201 search_path = TOOLCHAIN_PATHS[toolchain] or "No path set"
dkato 0:f782d9c66c49 202 args_error(parser, "Could not find executable for %s.\n"
dkato 0:f782d9c66c49 203 "Currently set search path: %s"
dkato 0:f782d9c66c49 204 % (toolchain, search_path))
dkato 0:f782d9c66c49 205
dkato 0:f782d9c66c49 206 for toolchain in toolchains:
dkato 0:f782d9c66c49 207 for target in targets:
dkato 0:f782d9c66c49 208 tt_id = "%s::%s" % (toolchain, target)
dkato 0:f782d9c66c49 209 if toolchain not in TARGET_MAP[target].supported_toolchains:
dkato 0:f782d9c66c49 210 # Log this later
dkato 0:f782d9c66c49 211 print "%s skipped: toolchain not supported" % tt_id
dkato 0:f782d9c66c49 212 skipped.append(tt_id)
dkato 0:f782d9c66c49 213 else:
dkato 0:f782d9c66c49 214 try:
dkato 0:f782d9c66c49 215 mcu = TARGET_MAP[target]
dkato 0:f782d9c66c49 216 profile = extract_profile(parser, options, toolchain)
dkato 0:f782d9c66c49 217 if options.source_dir:
dkato 0:f782d9c66c49 218 lib_build_res = build_library(options.source_dir, options.build_dir, mcu, toolchain,
dkato 0:f782d9c66c49 219 extra_verbose=options.extra_verbose_notify,
dkato 0:f782d9c66c49 220 verbose=options.verbose,
dkato 0:f782d9c66c49 221 silent=options.silent,
dkato 0:f782d9c66c49 222 jobs=options.jobs,
dkato 0:f782d9c66c49 223 clean=options.clean,
dkato 0:f782d9c66c49 224 archive=(not options.no_archive),
dkato 0:f782d9c66c49 225 macros=options.macros,
dkato 0:f782d9c66c49 226 name=options.artifact_name,
dkato 0:f782d9c66c49 227 build_profile=profile)
dkato 0:f782d9c66c49 228 else:
dkato 0:f782d9c66c49 229 lib_build_res = build_mbed_libs(mcu, toolchain,
dkato 0:f782d9c66c49 230 extra_verbose=options.extra_verbose_notify,
dkato 0:f782d9c66c49 231 verbose=options.verbose,
dkato 0:f782d9c66c49 232 silent=options.silent,
dkato 0:f782d9c66c49 233 jobs=options.jobs,
dkato 0:f782d9c66c49 234 clean=options.clean,
dkato 0:f782d9c66c49 235 macros=options.macros,
dkato 0:f782d9c66c49 236 build_profile=profile)
dkato 0:f782d9c66c49 237
dkato 0:f782d9c66c49 238 for lib_id in libraries:
dkato 0:f782d9c66c49 239 build_lib(lib_id, mcu, toolchain,
dkato 0:f782d9c66c49 240 extra_verbose=options.extra_verbose_notify,
dkato 0:f782d9c66c49 241 verbose=options.verbose,
dkato 0:f782d9c66c49 242 silent=options.silent,
dkato 0:f782d9c66c49 243 clean=options.clean,
dkato 0:f782d9c66c49 244 macros=options.macros,
dkato 0:f782d9c66c49 245 jobs=options.jobs,
dkato 0:f782d9c66c49 246 build_profile=profile)
dkato 0:f782d9c66c49 247 if lib_build_res:
dkato 0:f782d9c66c49 248 successes.append(tt_id)
dkato 0:f782d9c66c49 249 else:
dkato 0:f782d9c66c49 250 skipped.append(tt_id)
dkato 0:f782d9c66c49 251 except Exception, e:
dkato 0:f782d9c66c49 252 if options.verbose:
dkato 0:f782d9c66c49 253 import traceback
dkato 0:f782d9c66c49 254 traceback.print_exc(file=sys.stdout)
dkato 0:f782d9c66c49 255 sys.exit(1)
dkato 0:f782d9c66c49 256 failures.append(tt_id)
dkato 0:f782d9c66c49 257 print e
dkato 0:f782d9c66c49 258
dkato 0:f782d9c66c49 259
dkato 0:f782d9c66c49 260 # Write summary of the builds
dkato 0:f782d9c66c49 261 print
dkato 0:f782d9c66c49 262 print "Completed in: (%.2f)s" % (time() - start)
dkato 0:f782d9c66c49 263 print
dkato 0:f782d9c66c49 264
dkato 0:f782d9c66c49 265 for report, report_name in [(successes, "Build successes:"),
dkato 0:f782d9c66c49 266 (skipped, "Build skipped:"),
dkato 0:f782d9c66c49 267 (failures, "Build failures:"),
dkato 0:f782d9c66c49 268 ]:
dkato 0:f782d9c66c49 269 if report:
dkato 0:f782d9c66c49 270 print print_build_results(report, report_name),
dkato 0:f782d9c66c49 271
dkato 0:f782d9c66c49 272 if failures:
dkato 0:f782d9c66c49 273 sys.exit(1)