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