nkjnm

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
nexpaq
Date:
Sat Sep 17 16:32:05 2016 +0000
Revision:
1:55a6170b404f
checking in for sharing

Who changed what in which revision?

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