Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

Who changed what in which revision?

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