Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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