Clone of official tools
build.py@13:ab47a20b66f0, 2016-07-14 (annotated)
- Committer:
- screamer
- Date:
- Thu Jul 14 20:21:19 2016 +0100
- Revision:
- 13:ab47a20b66f0
- Parent:
- 9:2d27d77ada5c
- Child:
- 22:9e85236d8716
Apply latest tools
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 | 0:66f3b5499f7f | 31 | from tools.targets import TARGET_NAMES, TARGET_MAP |
screamer | 0:66f3b5499f7f | 32 | from tools.options import get_default_options_parser |
screamer | 0:66f3b5499f7f | 33 | from tools.build_api import build_library, build_mbed_libs, build_lib |
screamer | 0:66f3b5499f7f | 34 | from tools.build_api import mcu_toolchain_matrix |
screamer | 0:66f3b5499f7f | 35 | from tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library |
screamer | 0:66f3b5499f7f | 36 | from tools.build_api import print_build_results |
screamer | 0:66f3b5499f7f | 37 | from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT |
screamer | 0:66f3b5499f7f | 38 | |
screamer | 0:66f3b5499f7f | 39 | if __name__ == '__main__': |
screamer | 0:66f3b5499f7f | 40 | start = time() |
screamer | 0:66f3b5499f7f | 41 | |
screamer | 0:66f3b5499f7f | 42 | # Parse Options |
screamer | 0:66f3b5499f7f | 43 | parser = get_default_options_parser() |
screamer | 0:66f3b5499f7f | 44 | |
screamer | 0:66f3b5499f7f | 45 | parser.add_option("--source", dest="source_dir", |
screamer | 0:66f3b5499f7f | 46 | default=None, help="The source (input) directory", action="append") |
screamer | 0:66f3b5499f7f | 47 | |
screamer | 0:66f3b5499f7f | 48 | parser.add_option("--build", dest="build_dir", |
screamer | 0:66f3b5499f7f | 49 | default=None, help="The build (output) directory") |
screamer | 0:66f3b5499f7f | 50 | |
screamer | 0:66f3b5499f7f | 51 | parser.add_option("--no-archive", dest="no_archive", action="store_true", |
screamer | 0:66f3b5499f7f | 52 | default=False, help="Do not produce archive (.ar) file, but rather .o") |
screamer | 0:66f3b5499f7f | 53 | |
screamer | 0:66f3b5499f7f | 54 | # Extra libraries |
screamer | 0:66f3b5499f7f | 55 | parser.add_option("-r", "--rtos", |
screamer | 0:66f3b5499f7f | 56 | action="store_true", |
screamer | 0:66f3b5499f7f | 57 | dest="rtos", |
screamer | 0:66f3b5499f7f | 58 | default=False, |
screamer | 0:66f3b5499f7f | 59 | help="Compile the rtos") |
screamer | 0:66f3b5499f7f | 60 | |
screamer | 0:66f3b5499f7f | 61 | parser.add_option("--rpc", |
screamer | 0:66f3b5499f7f | 62 | action="store_true", |
screamer | 0:66f3b5499f7f | 63 | dest="rpc", |
screamer | 0:66f3b5499f7f | 64 | default=False, |
screamer | 0:66f3b5499f7f | 65 | help="Compile the rpc library") |
screamer | 0:66f3b5499f7f | 66 | |
screamer | 0:66f3b5499f7f | 67 | parser.add_option("-e", "--eth", |
screamer | 0:66f3b5499f7f | 68 | action="store_true", dest="eth", |
screamer | 0:66f3b5499f7f | 69 | default=False, |
screamer | 0:66f3b5499f7f | 70 | help="Compile the ethernet library") |
screamer | 0:66f3b5499f7f | 71 | |
screamer | 0:66f3b5499f7f | 72 | parser.add_option("-U", "--usb_host", |
screamer | 0:66f3b5499f7f | 73 | action="store_true", |
screamer | 0:66f3b5499f7f | 74 | dest="usb_host", |
screamer | 0:66f3b5499f7f | 75 | default=False, |
screamer | 0:66f3b5499f7f | 76 | help="Compile the USB Host library") |
screamer | 0:66f3b5499f7f | 77 | |
screamer | 0:66f3b5499f7f | 78 | parser.add_option("-u", "--usb", |
screamer | 0:66f3b5499f7f | 79 | action="store_true", |
screamer | 0:66f3b5499f7f | 80 | dest="usb", |
screamer | 0:66f3b5499f7f | 81 | default=False, |
screamer | 0:66f3b5499f7f | 82 | help="Compile the USB Device library") |
screamer | 0:66f3b5499f7f | 83 | |
screamer | 0:66f3b5499f7f | 84 | parser.add_option("-d", "--dsp", |
screamer | 0:66f3b5499f7f | 85 | action="store_true", |
screamer | 0:66f3b5499f7f | 86 | dest="dsp", |
screamer | 0:66f3b5499f7f | 87 | default=False, |
screamer | 0:66f3b5499f7f | 88 | help="Compile the DSP library") |
screamer | 0:66f3b5499f7f | 89 | |
screamer | 0:66f3b5499f7f | 90 | parser.add_option("-F", "--fat", |
screamer | 0:66f3b5499f7f | 91 | action="store_true", |
screamer | 0:66f3b5499f7f | 92 | dest="fat", |
screamer | 0:66f3b5499f7f | 93 | default=False, |
screamer | 0:66f3b5499f7f | 94 | help="Compile FS and SD card file system library") |
screamer | 0:66f3b5499f7f | 95 | |
screamer | 0:66f3b5499f7f | 96 | parser.add_option("-b", "--ublox", |
screamer | 0:66f3b5499f7f | 97 | action="store_true", |
screamer | 0:66f3b5499f7f | 98 | dest="ublox", |
screamer | 0:66f3b5499f7f | 99 | default=False, |
screamer | 0:66f3b5499f7f | 100 | help="Compile the u-blox library") |
screamer | 0:66f3b5499f7f | 101 | |
screamer | 0:66f3b5499f7f | 102 | parser.add_option("", "--cpputest", |
screamer | 0:66f3b5499f7f | 103 | action="store_true", |
screamer | 0:66f3b5499f7f | 104 | dest="cpputest_lib", |
screamer | 0:66f3b5499f7f | 105 | default=False, |
screamer | 0:66f3b5499f7f | 106 | help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)") |
screamer | 0:66f3b5499f7f | 107 | |
screamer | 0:66f3b5499f7f | 108 | parser.add_option("-D", "", |
screamer | 0:66f3b5499f7f | 109 | action="append", |
screamer | 0:66f3b5499f7f | 110 | dest="macros", |
screamer | 0:66f3b5499f7f | 111 | help="Add a macro definition") |
screamer | 0:66f3b5499f7f | 112 | |
screamer | 0:66f3b5499f7f | 113 | parser.add_option("-S", "--supported-toolchains", |
screamer | 0:66f3b5499f7f | 114 | action="store_true", |
screamer | 0:66f3b5499f7f | 115 | dest="supported_toolchains", |
screamer | 0:66f3b5499f7f | 116 | default=False, |
screamer | 0:66f3b5499f7f | 117 | help="Displays supported matrix of MCUs and toolchains") |
screamer | 0:66f3b5499f7f | 118 | |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 119 | parser.add_option('-f', '--filter', |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 120 | dest='general_filter_regex', |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 121 | default=None, |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 122 | help='For some commands you can use filter to filter out results') |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 123 | |
screamer | 0:66f3b5499f7f | 124 | parser.add_option("", "--cppcheck", |
screamer | 0:66f3b5499f7f | 125 | action="store_true", |
screamer | 0:66f3b5499f7f | 126 | dest="cppcheck_validation", |
screamer | 0:66f3b5499f7f | 127 | default=False, |
screamer | 0:66f3b5499f7f | 128 | help="Forces 'cppcheck' static code analysis") |
screamer | 0:66f3b5499f7f | 129 | |
screamer | 0:66f3b5499f7f | 130 | parser.add_option("-j", "--jobs", type="int", dest="jobs", |
screamer | 0:66f3b5499f7f | 131 | default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)") |
screamer | 13:ab47a20b66f0 | 132 | parser.add_option("-N", "--artifact-name", dest="artifact_name", |
screamer | 13:ab47a20b66f0 | 133 | default=None, help="The built project's name") |
screamer | 0:66f3b5499f7f | 134 | |
screamer | 0:66f3b5499f7f | 135 | parser.add_option("-v", "--verbose", |
screamer | 0:66f3b5499f7f | 136 | action="store_true", |
screamer | 0:66f3b5499f7f | 137 | dest="verbose", |
screamer | 0:66f3b5499f7f | 138 | default=False, |
screamer | 0:66f3b5499f7f | 139 | help="Verbose diagnostic output") |
screamer | 0:66f3b5499f7f | 140 | |
screamer | 0:66f3b5499f7f | 141 | parser.add_option("--silent", |
screamer | 0:66f3b5499f7f | 142 | action="store_true", |
screamer | 0:66f3b5499f7f | 143 | dest="silent", |
screamer | 0:66f3b5499f7f | 144 | default=False, |
screamer | 0:66f3b5499f7f | 145 | help="Silent diagnostic output (no copy, compile notification)") |
screamer | 0:66f3b5499f7f | 146 | |
screamer | 0:66f3b5499f7f | 147 | parser.add_option("-x", "--extra-verbose-notifications", |
screamer | 0:66f3b5499f7f | 148 | action="store_true", |
screamer | 0:66f3b5499f7f | 149 | dest="extra_verbose_notify", |
screamer | 0:66f3b5499f7f | 150 | default=False, |
screamer | 0:66f3b5499f7f | 151 | help="Makes compiler more verbose, CI friendly.") |
screamer | 0:66f3b5499f7f | 152 | |
screamer | 0:66f3b5499f7f | 153 | (options, args) = parser.parse_args() |
screamer | 0:66f3b5499f7f | 154 | |
screamer | 0:66f3b5499f7f | 155 | # Only prints matrix of supported toolchains |
screamer | 0:66f3b5499f7f | 156 | if options.supported_toolchains: |
screamer | 0:66f3b5499f7f | 157 | print mcu_toolchain_matrix(platform_filter=options.general_filter_regex) |
screamer | 0:66f3b5499f7f | 158 | exit(0) |
screamer | 0:66f3b5499f7f | 159 | |
screamer | 0:66f3b5499f7f | 160 | # Get target list |
screamer | 0:66f3b5499f7f | 161 | if options.mcu: |
screamer | 0:66f3b5499f7f | 162 | mcu_list = (options.mcu).split(",") |
screamer | 0:66f3b5499f7f | 163 | for mcu in mcu_list: |
screamer | 0:66f3b5499f7f | 164 | if mcu not in TARGET_NAMES: |
screamer | 0:66f3b5499f7f | 165 | print "Given MCU '%s' not into the supported list:\n%s" % (mcu, TARGET_NAMES) |
screamer | 0:66f3b5499f7f | 166 | sys.exit(1) |
screamer | 0:66f3b5499f7f | 167 | targets = mcu_list |
screamer | 0:66f3b5499f7f | 168 | else: |
screamer | 0:66f3b5499f7f | 169 | targets = TARGET_NAMES |
screamer | 0:66f3b5499f7f | 170 | |
screamer | 0:66f3b5499f7f | 171 | # Get toolchains list |
screamer | 0:66f3b5499f7f | 172 | if options.tool: |
screamer | 0:66f3b5499f7f | 173 | toolchain_list = (options.tool).split(",") |
screamer | 0:66f3b5499f7f | 174 | for tc in toolchain_list: |
screamer | 0:66f3b5499f7f | 175 | if tc not in TOOLCHAINS: |
screamer | 0:66f3b5499f7f | 176 | print "Given toolchain '%s' not into the supported list:\n%s" % (tc, TOOLCHAINS) |
screamer | 0:66f3b5499f7f | 177 | sys.exit(1) |
screamer | 0:66f3b5499f7f | 178 | toolchains = toolchain_list |
screamer | 0:66f3b5499f7f | 179 | else: |
screamer | 0:66f3b5499f7f | 180 | toolchains = TOOLCHAINS |
screamer | 0:66f3b5499f7f | 181 | |
screamer | 0:66f3b5499f7f | 182 | # Get libraries list |
screamer | 0:66f3b5499f7f | 183 | libraries = [] |
screamer | 0:66f3b5499f7f | 184 | |
screamer | 0:66f3b5499f7f | 185 | # Additional Libraries |
screamer | 0:66f3b5499f7f | 186 | if options.rtos: |
screamer | 0:66f3b5499f7f | 187 | libraries.extend(["rtx", "rtos"]) |
screamer | 0:66f3b5499f7f | 188 | if options.rpc: |
screamer | 0:66f3b5499f7f | 189 | libraries.extend(["rpc"]) |
screamer | 0:66f3b5499f7f | 190 | if options.eth: |
screamer | 0:66f3b5499f7f | 191 | libraries.append("eth") |
screamer | 0:66f3b5499f7f | 192 | if options.usb: |
screamer | 0:66f3b5499f7f | 193 | libraries.append("usb") |
screamer | 0:66f3b5499f7f | 194 | if options.usb_host: |
screamer | 0:66f3b5499f7f | 195 | libraries.append("usb_host") |
screamer | 0:66f3b5499f7f | 196 | if options.dsp: |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 197 | libraries.extend(["dsp"]) |
screamer | 0:66f3b5499f7f | 198 | if options.fat: |
screamer | 0:66f3b5499f7f | 199 | libraries.extend(["fat"]) |
screamer | 0:66f3b5499f7f | 200 | if options.ublox: |
screamer | 0:66f3b5499f7f | 201 | libraries.extend(["rtx", "rtos", "usb_host", "ublox"]) |
screamer | 0:66f3b5499f7f | 202 | if options.cpputest_lib: |
screamer | 0:66f3b5499f7f | 203 | libraries.extend(["cpputest"]) |
screamer | 0:66f3b5499f7f | 204 | |
screamer | 0:66f3b5499f7f | 205 | # Build results |
screamer | 0:66f3b5499f7f | 206 | failures = [] |
screamer | 0:66f3b5499f7f | 207 | successes = [] |
screamer | 0:66f3b5499f7f | 208 | skipped = [] |
screamer | 0:66f3b5499f7f | 209 | |
screamer | 0:66f3b5499f7f | 210 | # CPPCHECK code validation |
screamer | 0:66f3b5499f7f | 211 | if options.cppcheck_validation: |
screamer | 0:66f3b5499f7f | 212 | for toolchain in toolchains: |
screamer | 0:66f3b5499f7f | 213 | for target in targets: |
screamer | 0:66f3b5499f7f | 214 | try: |
screamer | 0:66f3b5499f7f | 215 | mcu = TARGET_MAP[target] |
screamer | 0:66f3b5499f7f | 216 | # CMSIS and MBED libs analysis |
screamer | 0:66f3b5499f7f | 217 | static_analysis_scan(mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, verbose=options.verbose, jobs=options.jobs) |
screamer | 0:66f3b5499f7f | 218 | for lib_id in libraries: |
screamer | 0:66f3b5499f7f | 219 | # Static check for library |
screamer | 0:66f3b5499f7f | 220 | static_analysis_scan_lib(lib_id, mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, |
screamer | 0:66f3b5499f7f | 221 | options=options.options, |
screamer | 0:66f3b5499f7f | 222 | extra_verbose=options.extra_verbose_notify, verbose=options.verbose, jobs=options.jobs, clean=options.clean, |
screamer | 0:66f3b5499f7f | 223 | macros=options.macros) |
screamer | 0:66f3b5499f7f | 224 | pass |
screamer | 0:66f3b5499f7f | 225 | except Exception, e: |
screamer | 0:66f3b5499f7f | 226 | if options.verbose: |
screamer | 0:66f3b5499f7f | 227 | import traceback |
screamer | 0:66f3b5499f7f | 228 | traceback.print_exc(file=sys.stdout) |
screamer | 0:66f3b5499f7f | 229 | sys.exit(1) |
screamer | 0:66f3b5499f7f | 230 | print e |
screamer | 0:66f3b5499f7f | 231 | else: |
screamer | 0:66f3b5499f7f | 232 | # Build |
screamer | 0:66f3b5499f7f | 233 | for toolchain in toolchains: |
screamer | 0:66f3b5499f7f | 234 | for target in targets: |
screamer | 0:66f3b5499f7f | 235 | tt_id = "%s::%s" % (toolchain, target) |
screamer | 0:66f3b5499f7f | 236 | try: |
screamer | 0:66f3b5499f7f | 237 | mcu = TARGET_MAP[target] |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 238 | if options.source_dir: |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 239 | lib_build_res = build_library(options.source_dir, options.build_dir, mcu, toolchain, |
screamer | 0:66f3b5499f7f | 240 | options=options.options, |
screamer | 0:66f3b5499f7f | 241 | extra_verbose=options.extra_verbose_notify, |
screamer | 0:66f3b5499f7f | 242 | verbose=options.verbose, |
screamer | 0:66f3b5499f7f | 243 | silent=options.silent, |
screamer | 0:66f3b5499f7f | 244 | jobs=options.jobs, |
screamer | 0:66f3b5499f7f | 245 | clean=options.clean, |
screamer | 0:66f3b5499f7f | 246 | archive=(not options.no_archive), |
screamer | 13:ab47a20b66f0 | 247 | macros=options.macros, |
screamer | 13:ab47a20b66f0 | 248 | name=options.artifact_name) |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 249 | else: |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 250 | lib_build_res = build_mbed_libs(mcu, toolchain, |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 251 | options=options.options, |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 252 | extra_verbose=options.extra_verbose_notify, |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 253 | verbose=options.verbose, |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 254 | silent=options.silent, |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 255 | jobs=options.jobs, |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 256 | clean=options.clean, |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 257 | macros=options.macros) |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 258 | |
screamer | 0:66f3b5499f7f | 259 | for lib_id in libraries: |
screamer | 0:66f3b5499f7f | 260 | build_lib(lib_id, mcu, toolchain, |
screamer | 0:66f3b5499f7f | 261 | options=options.options, |
screamer | 0:66f3b5499f7f | 262 | extra_verbose=options.extra_verbose_notify, |
screamer | 0:66f3b5499f7f | 263 | verbose=options.verbose, |
screamer | 0:66f3b5499f7f | 264 | silent=options.silent, |
screamer | 0:66f3b5499f7f | 265 | clean=options.clean, |
screamer | 0:66f3b5499f7f | 266 | macros=options.macros, |
screamer | 0:66f3b5499f7f | 267 | jobs=options.jobs) |
screamer | 0:66f3b5499f7f | 268 | if lib_build_res: |
screamer | 0:66f3b5499f7f | 269 | successes.append(tt_id) |
screamer | 0:66f3b5499f7f | 270 | else: |
screamer | 0:66f3b5499f7f | 271 | skipped.append(tt_id) |
screamer | 0:66f3b5499f7f | 272 | except Exception, e: |
screamer | 0:66f3b5499f7f | 273 | if options.verbose: |
screamer | 0:66f3b5499f7f | 274 | import traceback |
screamer | 0:66f3b5499f7f | 275 | traceback.print_exc(file=sys.stdout) |
screamer | 0:66f3b5499f7f | 276 | sys.exit(1) |
screamer | 0:66f3b5499f7f | 277 | failures.append(tt_id) |
screamer | 0:66f3b5499f7f | 278 | print e |
screamer | 0:66f3b5499f7f | 279 | |
screamer | 0:66f3b5499f7f | 280 | # Write summary of the builds |
screamer | 0:66f3b5499f7f | 281 | |
screamer | 0:66f3b5499f7f | 282 | print "Completed in: (%.2f)s" % (time() - start) |
screamer | 0:66f3b5499f7f | 283 | |
screamer | 0:66f3b5499f7f | 284 | |
screamer | 0:66f3b5499f7f | 285 | for report, report_name in [(successes, "Build successes:"), |
screamer | 0:66f3b5499f7f | 286 | (skipped, "Build skipped:"), |
screamer | 0:66f3b5499f7f | 287 | (failures, "Build failures:"), |
screamer | 0:66f3b5499f7f | 288 | ]: |
screamer | 0:66f3b5499f7f | 289 | if report: |
screamer | 0:66f3b5499f7f | 290 | print print_build_results(report, report_name), |
screamer | 0:66f3b5499f7f | 291 | |
screamer | 0:66f3b5499f7f | 292 | if failures: |
screamer | 0:66f3b5499f7f | 293 | sys.exit(1) |