Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
build.py
00001 #! /usr/bin/env python2 00002 """ 00003 mbed SDK 00004 Copyright (c) 2011-2013 ARM Limited 00005 00006 Licensed under the Apache License, Version 2.0 (the "License"); 00007 you may not use this file except in compliance with the License. 00008 You may obtain a copy of the License at 00009 00010 http://www.apache.org/licenses/LICENSE-2.0 00011 00012 Unless required by applicable law or agreed to in writing, software 00013 distributed under the License is distributed on an "AS IS" BASIS, 00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 See the License for the specific language governing permissions and 00016 limitations under the License. 00017 00018 LIBRARIES BUILD 00019 """ 00020 from __future__ import print_function, division, absolute_import 00021 00022 import sys 00023 from time import time 00024 from os.path import join, abspath, dirname 00025 00026 00027 # Be sure that the tools directory is in the search path 00028 ROOT = abspath(join(dirname(__file__), "..")) 00029 sys.path.insert(0, ROOT) 00030 00031 00032 from tools.toolchains import TOOLCHAINS, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS 00033 from tools.toolchains import mbedToolchain 00034 from tools.targets import TARGET_NAMES, TARGET_MAP 00035 from tools.options import get_default_options_parser 00036 from tools.options import extract_profile 00037 from tools.options import extract_mcus 00038 from tools.build_api import build_library, build_mbed_libs, build_lib 00039 from tools.build_api import mcu_toolchain_matrix 00040 from tools.build_api import print_build_results 00041 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT 00042 from utils import argparse_filestring_type, args_error 00043 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, CLI_COLOR_MAP 00044 from utils import argparse_filestring_type, argparse_dir_not_parent 00045 00046 if __name__ == '__main__': 00047 start = time() 00048 00049 # Parse Options 00050 parser = get_default_options_parser() 00051 00052 parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, 00053 default=None, help="The source (input) directory", action="append") 00054 00055 parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT), 00056 default=None, help="The build (output) directory") 00057 00058 parser.add_argument("--no-archive", dest="no_archive", action="store_true", 00059 default=False, help="Do not produce archive (.ar) file, but rather .o") 00060 00061 # Extra libraries 00062 parser.add_argument("-r", "--rtos", 00063 action="store_true", 00064 dest="rtos", 00065 default=False, 00066 help="Compile the rtos") 00067 00068 parser.add_argument("--rpc", 00069 action="store_true", 00070 dest="rpc", 00071 default=False, 00072 help="Compile the rpc library") 00073 00074 parser.add_argument("-u", "--usb", 00075 action="store_true", 00076 dest="usb", 00077 default=False, 00078 help="Compile the USB Device library") 00079 00080 parser.add_argument("-d", "--dsp", 00081 action="store_true", 00082 dest="dsp", 00083 default=False, 00084 help="Compile the DSP library") 00085 00086 parser.add_argument( "--cpputest", 00087 action="store_true", 00088 dest="cpputest_lib", 00089 default=False, 00090 help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)") 00091 00092 parser.add_argument("-D", 00093 action="append", 00094 dest="macros", 00095 help="Add a macro definition") 00096 00097 parser.add_argument("-S", "--supported-toolchains", 00098 action="store_true", 00099 dest="supported_toolchains", 00100 default=False, 00101 help="Displays supported matrix of MCUs and toolchains") 00102 00103 parser.add_argument('-f', '--filter', 00104 dest='general_filter_regex', 00105 default=None, 00106 help='For some commands you can use filter to filter out results') 00107 00108 parser.add_argument("-j", "--jobs", type=int, dest="jobs", 00109 default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)") 00110 parser.add_argument("-N", "--artifact-name", dest="artifact_name", 00111 default=None, help="The built project's name") 00112 00113 parser.add_argument("-v", "--verbose", 00114 action="store_true", 00115 dest="verbose", 00116 default=False, 00117 help="Verbose diagnostic output") 00118 00119 parser.add_argument("--silent", 00120 action="store_true", 00121 dest="silent", 00122 default=False, 00123 help="Silent diagnostic output (no copy, compile notification)") 00124 00125 parser.add_argument("-x", "--extra-verbose-notifications", 00126 action="store_true", 00127 dest="extra_verbose_notify", 00128 default=False, 00129 help="Makes compiler more verbose, CI friendly.") 00130 00131 options = parser.parse_args() 00132 00133 # Only prints matrix of supported toolchains 00134 if options.supported_toolchains: 00135 print(mcu_toolchain_matrix(platform_filter=options.general_filter_regex)) 00136 exit(0) 00137 00138 00139 # Get target list 00140 targets = extract_mcus(parser, options) if options.mcu else TARGET_NAMES 00141 00142 # Get toolchains list 00143 toolchains = options.tool if options.tool else TOOLCHAINS 00144 00145 if options.source_dir and not options.build_dir: 00146 args_error(parser, "argument --build is required by argument --source") 00147 00148 if options.color: 00149 # This import happens late to prevent initializing colorization when we don't need it 00150 import colorize 00151 if options.verbose: 00152 notify = mbedToolchain.print_notify_verbose 00153 else: 00154 notify = mbedToolchain.print_notify 00155 notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify) 00156 else: 00157 notify = None 00158 00159 # Get libraries list 00160 libraries = [] 00161 00162 # Additional Libraries 00163 if options.rpc: 00164 libraries.extend(["rpc"]) 00165 if options.usb: 00166 libraries.append("usb") 00167 if options.dsp: 00168 libraries.extend(["dsp"]) 00169 if options.cpputest_lib: 00170 libraries.extend(["cpputest"]) 00171 00172 # Build results 00173 failures = [] 00174 successes = [] 00175 skipped = [] 00176 00177 for toolchain in toolchains: 00178 if not TOOLCHAIN_CLASSES[toolchain].check_executable(): 00179 search_path = TOOLCHAIN_PATHS[toolchain] or "No path set" 00180 args_error(parser, "Could not find executable for %s.\n" 00181 "Currently set search path: %s" 00182 % (toolchain, search_path)) 00183 00184 for toolchain in toolchains: 00185 for target in targets: 00186 tt_id = "%s::%s" % (toolchain, target) 00187 if toolchain not in TARGET_MAP[target].supported_toolchains: 00188 # Log this later 00189 print("%s skipped: toolchain not supported" % tt_id) 00190 skipped.append(tt_id) 00191 else: 00192 try: 00193 mcu = TARGET_MAP[target] 00194 profile = extract_profile(parser, options, toolchain) 00195 if options.source_dir: 00196 lib_build_res = build_library(options.source_dir, options.build_dir, mcu, toolchain, 00197 extra_verbose=options.extra_verbose_notify, 00198 verbose=options.verbose, 00199 silent=options.silent, 00200 jobs=options.jobs, 00201 clean=options.clean, 00202 archive=(not options.no_archive), 00203 macros=options.macros, 00204 name=options.artifact_name, 00205 build_profile=profile) 00206 else: 00207 lib_build_res = build_mbed_libs(mcu, toolchain, 00208 extra_verbose=options.extra_verbose_notify, 00209 verbose=options.verbose, 00210 silent=options.silent, 00211 jobs=options.jobs, 00212 clean=options.clean, 00213 macros=options.macros, 00214 build_profile=profile) 00215 00216 for lib_id in libraries: 00217 build_lib(lib_id, mcu, toolchain, 00218 extra_verbose=options.extra_verbose_notify, 00219 verbose=options.verbose, 00220 silent=options.silent, 00221 clean=options.clean, 00222 macros=options.macros, 00223 jobs=options.jobs, 00224 build_profile=profile) 00225 if lib_build_res: 00226 successes.append(tt_id) 00227 else: 00228 skipped.append(tt_id) 00229 except Exception as e: 00230 if options.verbose: 00231 import traceback 00232 traceback.print_exc(file=sys.stdout) 00233 sys.exit(1) 00234 failures.append(tt_id) 00235 print(e) 00236 00237 00238 # Write summary of the builds 00239 print("\nCompleted in: (%.2f)s\n" % (time() - start)) 00240 00241 for report, report_name in [(successes, "Build successes:"), 00242 (skipped, "Build skipped:"), 00243 (failures, "Build failures:"), 00244 ]: 00245 if report: 00246 print(print_build_results(report, report_name)) 00247 00248 if failures: 00249 sys.exit(1)
Generated on Tue Jul 12 2022 14:23:26 by
