Clone of official tools
build.py@24:25bff2709c20, 2016-08-01 (annotated)
- Committer:
- screamer
- Date:
- Mon Aug 01 09:10:17 2016 +0100
- Revision:
- 24:25bff2709c20
- Parent:
- 22:9e85236d8716
- Child:
- 31:8ea194f6145b
Major update to tools from ARMmbed/mbed-os
Who changed what in which revision?
User | Revision | Line number | New 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 | |
screamer | 0:66f3b5499f7f | 30 | from tools.toolchains import TOOLCHAINS |
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 |
screamer | 0:66f3b5499f7f | 34 | from tools.build_api import build_library, build_mbed_libs, build_lib |
screamer | 0:66f3b5499f7f | 35 | from tools.build_api import mcu_toolchain_matrix |
screamer | 0:66f3b5499f7f | 36 | from tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library |
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 |
screamer | 22:9e85236d8716 | 39 | from utils import argparse_filestring_type |
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("-e", "--eth", |
screamer | 0:66f3b5499f7f | 72 | action="store_true", dest="eth", |
screamer | 0:66f3b5499f7f | 73 | default=False, |
screamer | 0:66f3b5499f7f | 74 | help="Compile the ethernet library") |
screamer | 0:66f3b5499f7f | 75 | |
screamer | 22:9e85236d8716 | 76 | parser.add_argument("-U", "--usb_host", |
screamer | 0:66f3b5499f7f | 77 | action="store_true", |
screamer | 0:66f3b5499f7f | 78 | dest="usb_host", |
screamer | 0:66f3b5499f7f | 79 | default=False, |
screamer | 0:66f3b5499f7f | 80 | help="Compile the USB Host library") |
screamer | 0:66f3b5499f7f | 81 | |
screamer | 22:9e85236d8716 | 82 | parser.add_argument("-u", "--usb", |
screamer | 0:66f3b5499f7f | 83 | action="store_true", |
screamer | 0:66f3b5499f7f | 84 | dest="usb", |
screamer | 0:66f3b5499f7f | 85 | default=False, |
screamer | 0:66f3b5499f7f | 86 | help="Compile the USB Device library") |
screamer | 0:66f3b5499f7f | 87 | |
screamer | 22:9e85236d8716 | 88 | parser.add_argument("-d", "--dsp", |
screamer | 0:66f3b5499f7f | 89 | action="store_true", |
screamer | 0:66f3b5499f7f | 90 | dest="dsp", |
screamer | 0:66f3b5499f7f | 91 | default=False, |
screamer | 0:66f3b5499f7f | 92 | help="Compile the DSP library") |
screamer | 0:66f3b5499f7f | 93 | |
screamer | 22:9e85236d8716 | 94 | parser.add_argument("-F", "--fat", |
screamer | 0:66f3b5499f7f | 95 | action="store_true", |
screamer | 0:66f3b5499f7f | 96 | dest="fat", |
screamer | 0:66f3b5499f7f | 97 | default=False, |
screamer | 0:66f3b5499f7f | 98 | help="Compile FS and SD card file system library") |
screamer | 0:66f3b5499f7f | 99 | |
screamer | 22:9e85236d8716 | 100 | parser.add_argument("-b", "--ublox", |
screamer | 0:66f3b5499f7f | 101 | action="store_true", |
screamer | 0:66f3b5499f7f | 102 | dest="ublox", |
screamer | 0:66f3b5499f7f | 103 | default=False, |
screamer | 0:66f3b5499f7f | 104 | help="Compile the u-blox library") |
screamer | 0:66f3b5499f7f | 105 | |
screamer | 22:9e85236d8716 | 106 | parser.add_argument( "--cpputest", |
screamer | 0:66f3b5499f7f | 107 | action="store_true", |
screamer | 0:66f3b5499f7f | 108 | dest="cpputest_lib", |
screamer | 0:66f3b5499f7f | 109 | default=False, |
screamer | 0:66f3b5499f7f | 110 | help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)") |
screamer | 0:66f3b5499f7f | 111 | |
screamer | 22:9e85236d8716 | 112 | parser.add_argument("-D", |
screamer | 0:66f3b5499f7f | 113 | action="append", |
screamer | 0:66f3b5499f7f | 114 | dest="macros", |
screamer | 0:66f3b5499f7f | 115 | help="Add a macro definition") |
screamer | 0:66f3b5499f7f | 116 | |
screamer | 22:9e85236d8716 | 117 | parser.add_argument("-S", "--supported-toolchains", |
screamer | 0:66f3b5499f7f | 118 | action="store_true", |
screamer | 0:66f3b5499f7f | 119 | dest="supported_toolchains", |
screamer | 0:66f3b5499f7f | 120 | default=False, |
screamer | 0:66f3b5499f7f | 121 | help="Displays supported matrix of MCUs and toolchains") |
screamer | 0:66f3b5499f7f | 122 | |
screamer | 22:9e85236d8716 | 123 | parser.add_argument('-f', '--filter', |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 124 | dest='general_filter_regex', |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 125 | default=None, |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 126 | help='For some commands you can use filter to filter out results') |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 127 | |
screamer | 22:9e85236d8716 | 128 | parser.add_argument("--cppcheck", |
screamer | 0:66f3b5499f7f | 129 | action="store_true", |
screamer | 0:66f3b5499f7f | 130 | dest="cppcheck_validation", |
screamer | 0:66f3b5499f7f | 131 | default=False, |
screamer | 0:66f3b5499f7f | 132 | help="Forces 'cppcheck' static code analysis") |
screamer | 0:66f3b5499f7f | 133 | |
screamer | 22:9e85236d8716 | 134 | parser.add_argument("-j", "--jobs", type=int, dest="jobs", |
screamer | 0:66f3b5499f7f | 135 | default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)") |
screamer | 22:9e85236d8716 | 136 | parser.add_argument("-N", "--artifact-name", dest="artifact_name", |
screamer | 13:ab47a20b66f0 | 137 | default=None, help="The built project's name") |
screamer | 0:66f3b5499f7f | 138 | |
screamer | 22:9e85236d8716 | 139 | parser.add_argument("-v", "--verbose", |
screamer | 0:66f3b5499f7f | 140 | action="store_true", |
screamer | 0:66f3b5499f7f | 141 | dest="verbose", |
screamer | 0:66f3b5499f7f | 142 | default=False, |
screamer | 0:66f3b5499f7f | 143 | help="Verbose diagnostic output") |
screamer | 0:66f3b5499f7f | 144 | |
screamer | 22:9e85236d8716 | 145 | parser.add_argument("--silent", |
screamer | 0:66f3b5499f7f | 146 | action="store_true", |
screamer | 0:66f3b5499f7f | 147 | dest="silent", |
screamer | 0:66f3b5499f7f | 148 | default=False, |
screamer | 0:66f3b5499f7f | 149 | help="Silent diagnostic output (no copy, compile notification)") |
screamer | 0:66f3b5499f7f | 150 | |
screamer | 22:9e85236d8716 | 151 | parser.add_argument("-x", "--extra-verbose-notifications", |
screamer | 0:66f3b5499f7f | 152 | action="store_true", |
screamer | 0:66f3b5499f7f | 153 | dest="extra_verbose_notify", |
screamer | 0:66f3b5499f7f | 154 | default=False, |
screamer | 0:66f3b5499f7f | 155 | help="Makes compiler more verbose, CI friendly.") |
screamer | 0:66f3b5499f7f | 156 | |
screamer | 22:9e85236d8716 | 157 | options = parser.parse_args() |
screamer | 0:66f3b5499f7f | 158 | |
screamer | 0:66f3b5499f7f | 159 | # Only prints matrix of supported toolchains |
screamer | 0:66f3b5499f7f | 160 | if options.supported_toolchains: |
screamer | 0:66f3b5499f7f | 161 | print mcu_toolchain_matrix(platform_filter=options.general_filter_regex) |
screamer | 0:66f3b5499f7f | 162 | exit(0) |
screamer | 0:66f3b5499f7f | 163 | |
screamer | 0:66f3b5499f7f | 164 | # Get target list |
screamer | 22:9e85236d8716 | 165 | targets = options.mcu if options.mcu else TARGET_NAMES |
screamer | 0:66f3b5499f7f | 166 | |
screamer | 0:66f3b5499f7f | 167 | # Get toolchains list |
screamer | 22:9e85236d8716 | 168 | toolchains = options.tool if options.tool else TOOLCHAINS |
screamer | 22:9e85236d8716 | 169 | |
screamer | 22:9e85236d8716 | 170 | if options.color: |
screamer | 22:9e85236d8716 | 171 | # This import happens late to prevent initializing colorization when we don't need it |
screamer | 22:9e85236d8716 | 172 | import colorize |
screamer | 22:9e85236d8716 | 173 | if options.verbose: |
screamer | 22:9e85236d8716 | 174 | notify = mbedToolchain.print_notify_verbose |
screamer | 22:9e85236d8716 | 175 | else: |
screamer | 22:9e85236d8716 | 176 | notify = mbedToolchain.print_notify |
screamer | 22:9e85236d8716 | 177 | notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify) |
screamer | 0:66f3b5499f7f | 178 | else: |
screamer | 22:9e85236d8716 | 179 | notify = None |
screamer | 0:66f3b5499f7f | 180 | |
screamer | 0:66f3b5499f7f | 181 | # Get libraries list |
screamer | 0:66f3b5499f7f | 182 | libraries = [] |
screamer | 0:66f3b5499f7f | 183 | |
screamer | 0:66f3b5499f7f | 184 | # Additional Libraries |
screamer | 0:66f3b5499f7f | 185 | if options.rtos: |
screamer | 0:66f3b5499f7f | 186 | libraries.extend(["rtx", "rtos"]) |
screamer | 0:66f3b5499f7f | 187 | if options.rpc: |
screamer | 0:66f3b5499f7f | 188 | libraries.extend(["rpc"]) |
screamer | 0:66f3b5499f7f | 189 | if options.eth: |
screamer | 0:66f3b5499f7f | 190 | libraries.append("eth") |
screamer | 0:66f3b5499f7f | 191 | if options.usb: |
screamer | 0:66f3b5499f7f | 192 | libraries.append("usb") |
screamer | 0:66f3b5499f7f | 193 | if options.usb_host: |
screamer | 0:66f3b5499f7f | 194 | libraries.append("usb_host") |
screamer | 0:66f3b5499f7f | 195 | if options.dsp: |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 196 | libraries.extend(["dsp"]) |
screamer | 0:66f3b5499f7f | 197 | if options.fat: |
screamer | 0:66f3b5499f7f | 198 | libraries.extend(["fat"]) |
screamer | 0:66f3b5499f7f | 199 | if options.ublox: |
screamer | 0:66f3b5499f7f | 200 | libraries.extend(["rtx", "rtos", "usb_host", "ublox"]) |
screamer | 0:66f3b5499f7f | 201 | if options.cpputest_lib: |
screamer | 0:66f3b5499f7f | 202 | libraries.extend(["cpputest"]) |
screamer | 0:66f3b5499f7f | 203 | |
screamer | 0:66f3b5499f7f | 204 | # Build results |
screamer | 0:66f3b5499f7f | 205 | failures = [] |
screamer | 0:66f3b5499f7f | 206 | successes = [] |
screamer | 0:66f3b5499f7f | 207 | skipped = [] |
screamer | 0:66f3b5499f7f | 208 | |
screamer | 0:66f3b5499f7f | 209 | # CPPCHECK code validation |
screamer | 0:66f3b5499f7f | 210 | if options.cppcheck_validation: |
screamer | 0:66f3b5499f7f | 211 | for toolchain in toolchains: |
screamer | 0:66f3b5499f7f | 212 | for target in targets: |
screamer | 0:66f3b5499f7f | 213 | try: |
screamer | 0:66f3b5499f7f | 214 | mcu = TARGET_MAP[target] |
screamer | 0:66f3b5499f7f | 215 | # CMSIS and MBED libs analysis |
screamer | 0:66f3b5499f7f | 216 | static_analysis_scan(mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, verbose=options.verbose, jobs=options.jobs) |
screamer | 0:66f3b5499f7f | 217 | for lib_id in libraries: |
screamer | 0:66f3b5499f7f | 218 | # Static check for library |
screamer | 0:66f3b5499f7f | 219 | static_analysis_scan_lib(lib_id, mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, |
screamer | 0:66f3b5499f7f | 220 | options=options.options, |
screamer | 0:66f3b5499f7f | 221 | extra_verbose=options.extra_verbose_notify, verbose=options.verbose, jobs=options.jobs, clean=options.clean, |
screamer | 0:66f3b5499f7f | 222 | macros=options.macros) |
screamer | 0:66f3b5499f7f | 223 | pass |
screamer | 0:66f3b5499f7f | 224 | except Exception, e: |
screamer | 0:66f3b5499f7f | 225 | if options.verbose: |
screamer | 0:66f3b5499f7f | 226 | import traceback |
screamer | 0:66f3b5499f7f | 227 | traceback.print_exc(file=sys.stdout) |
screamer | 0:66f3b5499f7f | 228 | sys.exit(1) |
screamer | 0:66f3b5499f7f | 229 | print e |
screamer | 0:66f3b5499f7f | 230 | else: |
screamer | 0:66f3b5499f7f | 231 | # Build |
screamer | 0:66f3b5499f7f | 232 | for toolchain in toolchains: |
screamer | 0:66f3b5499f7f | 233 | for target in targets: |
screamer | 0:66f3b5499f7f | 234 | tt_id = "%s::%s" % (toolchain, target) |
screamer | 22:9e85236d8716 | 235 | if toolchain not in TARGET_MAP[target].supported_toolchains: |
screamer | 22:9e85236d8716 | 236 | # Log this later |
screamer | 22:9e85236d8716 | 237 | print "%s skipped: toolchain not supported" % tt_id |
screamer | 22:9e85236d8716 | 238 | skipped.append(tt_id) |
screamer | 22:9e85236d8716 | 239 | else: |
screamer | 22:9e85236d8716 | 240 | try: |
screamer | 22:9e85236d8716 | 241 | mcu = TARGET_MAP[target] |
screamer | 22:9e85236d8716 | 242 | if options.source_dir: |
screamer | 22:9e85236d8716 | 243 | lib_build_res = build_library(options.source_dir, options.build_dir, mcu, toolchain, |
screamer | 22:9e85236d8716 | 244 | options=options.options, |
screamer | 22:9e85236d8716 | 245 | extra_verbose=options.extra_verbose_notify, |
screamer | 22:9e85236d8716 | 246 | verbose=options.verbose, |
screamer | 22:9e85236d8716 | 247 | silent=options.silent, |
screamer | 22:9e85236d8716 | 248 | jobs=options.jobs, |
screamer | 22:9e85236d8716 | 249 | clean=options.clean, |
screamer | 22:9e85236d8716 | 250 | archive=(not options.no_archive), |
screamer | 22:9e85236d8716 | 251 | macros=options.macros, |
screamer | 22:9e85236d8716 | 252 | name=options.artifact_name) |
screamer | 22:9e85236d8716 | 253 | else: |
screamer | 22:9e85236d8716 | 254 | lib_build_res = build_mbed_libs(mcu, toolchain, |
screamer | 22:9e85236d8716 | 255 | options=options.options, |
screamer | 22:9e85236d8716 | 256 | extra_verbose=options.extra_verbose_notify, |
screamer | 22:9e85236d8716 | 257 | verbose=options.verbose, |
screamer | 22:9e85236d8716 | 258 | silent=options.silent, |
screamer | 22:9e85236d8716 | 259 | jobs=options.jobs, |
screamer | 22:9e85236d8716 | 260 | clean=options.clean, |
screamer | 22:9e85236d8716 | 261 | macros=options.macros) |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 262 | |
screamer | 22:9e85236d8716 | 263 | for lib_id in libraries: |
screamer | 22:9e85236d8716 | 264 | build_lib(lib_id, mcu, toolchain, |
screamer | 22:9e85236d8716 | 265 | options=options.options, |
screamer | 22:9e85236d8716 | 266 | extra_verbose=options.extra_verbose_notify, |
screamer | 22:9e85236d8716 | 267 | verbose=options.verbose, |
screamer | 22:9e85236d8716 | 268 | silent=options.silent, |
screamer | 22:9e85236d8716 | 269 | clean=options.clean, |
screamer | 22:9e85236d8716 | 270 | macros=options.macros, |
screamer | 22:9e85236d8716 | 271 | jobs=options.jobs) |
screamer | 22:9e85236d8716 | 272 | if lib_build_res: |
screamer | 22:9e85236d8716 | 273 | successes.append(tt_id) |
screamer | 22:9e85236d8716 | 274 | else: |
screamer | 22:9e85236d8716 | 275 | skipped.append(tt_id) |
screamer | 22:9e85236d8716 | 276 | except Exception, e: |
screamer | 22:9e85236d8716 | 277 | if options.verbose: |
screamer | 22:9e85236d8716 | 278 | import traceback |
screamer | 22:9e85236d8716 | 279 | traceback.print_exc(file=sys.stdout) |
screamer | 22:9e85236d8716 | 280 | sys.exit(1) |
screamer | 22:9e85236d8716 | 281 | failures.append(tt_id) |
screamer | 22:9e85236d8716 | 282 | print e |
screamer | 0:66f3b5499f7f | 283 | |
screamer | 0:66f3b5499f7f | 284 | # Write summary of the builds |
screamer | 0:66f3b5499f7f | 285 | |
screamer | 0:66f3b5499f7f | 286 | print "Completed in: (%.2f)s" % (time() - start) |
screamer | 0:66f3b5499f7f | 287 | |
screamer | 0:66f3b5499f7f | 288 | |
screamer | 0:66f3b5499f7f | 289 | for report, report_name in [(successes, "Build successes:"), |
screamer | 0:66f3b5499f7f | 290 | (skipped, "Build skipped:"), |
screamer | 0:66f3b5499f7f | 291 | (failures, "Build failures:"), |
screamer | 0:66f3b5499f7f | 292 | ]: |
screamer | 0:66f3b5499f7f | 293 | if report: |
screamer | 0:66f3b5499f7f | 294 | print print_build_results(report, report_name), |
screamer | 0:66f3b5499f7f | 295 | |
screamer | 0:66f3b5499f7f | 296 | if failures: |
screamer | 0:66f3b5499f7f | 297 | sys.exit(1) |