mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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