Clone of official tools

Committer:
The Other Jimmy
Date:
Thu Jun 22 11:12:28 2017 -0500
Revision:
36:96847d42f010
Parent:
35:da9c89f8be7d
Child:
38:399953da035d
Tools release 5.5.1

Who changed what in which revision?

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