Maxim mbed development library

Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

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