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