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