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 tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, CLI_COLOR_MAP 00043 from tools.notifier.term import TerminalNotifier 00044 from tools.utils import argparse_filestring_type, args_error, argparse_many 00045 from tools.utils import argparse_filestring_type, argparse_dir_not_parent 00046 00047 if __name__ == '__main__': 00048 start = time() 00049 00050 # Parse Options 00051 parser = get_default_options_parser() 00052 00053 parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, 00054 default=None, help="The source (input) directory", action="append") 00055 00056 parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT), 00057 default=None, help="The build (output) directory") 00058 00059 parser.add_argument("--no-archive", dest="no_archive", action="store_true", 00060 default=False, help="Do not produce archive (.ar) file, but rather .o") 00061 00062 # Extra libraries 00063 parser.add_argument("-r", "--rtos", 00064 action="store_true", 00065 dest="rtos", 00066 default=False, 00067 help="Compile the rtos") 00068 00069 parser.add_argument("--rpc", 00070 action="store_true", 00071 dest="rpc", 00072 default=False, 00073 help="Compile the rpc library") 00074 00075 parser.add_argument("-u", "--usb", 00076 action="store_true", 00077 dest="usb", 00078 default=False, 00079 help="Compile the USB Device library") 00080 00081 parser.add_argument("-d", "--dsp", 00082 action="store_true", 00083 dest="dsp", 00084 default=False, 00085 help="Compile the DSP library") 00086 00087 parser.add_argument( "--cpputest", 00088 action="store_true", 00089 dest="cpputest_lib", 00090 default=False, 00091 help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)") 00092 00093 parser.add_argument("-D", 00094 action="append", 00095 dest="macros", 00096 help="Add a macro definition") 00097 00098 parser.add_argument("-S", "--supported-toolchains", 00099 action="store_true", 00100 dest="supported_toolchains", 00101 default=False, 00102 help="Displays supported matrix of MCUs and toolchains") 00103 00104 parser.add_argument('-f', '--filter', 00105 dest='general_filter_regex', 00106 default=None, 00107 help='For some commands you can use filter to filter out results') 00108 00109 parser.add_argument("-j", "--jobs", type=int, dest="jobs", 00110 default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)") 00111 parser.add_argument("-N", "--artifact-name", dest="artifact_name", 00112 default=None, help="The built project's name") 00113 00114 parser.add_argument("-v", "--verbose", 00115 action="store_true", 00116 dest="verbose", 00117 default=False, 00118 help="Verbose diagnostic output") 00119 00120 parser.add_argument("--silent", 00121 action="store_true", 00122 dest="silent", 00123 default=False, 00124 help="Silent diagnostic output (no copy, compile notification)") 00125 00126 parser.add_argument("-x", "--extra-verbose-notifications", 00127 action="store_true", 00128 dest="extra_verbose_notify", 00129 default=False, 00130 help="Makes compiler more verbose, CI friendly.") 00131 00132 parser.add_argument("--ignore", dest="ignore", type=argparse_many(str), 00133 default=None, help="Comma separated list of patterns to add to mbedignore (eg. ./main.cpp)") 00134 00135 options = parser.parse_args() 00136 00137 # Only prints matrix of supported toolchains 00138 if options.supported_toolchains: 00139 print(mcu_toolchain_matrix(platform_filter=options.general_filter_regex)) 00140 exit(0) 00141 00142 00143 # Get target list 00144 targets = extract_mcus(parser, options) if options.mcu else TARGET_NAMES 00145 00146 # Get toolchains list 00147 toolchains = options.tool if options.tool else TOOLCHAINS 00148 00149 if options.source_dir and not options.build_dir: 00150 args_error(parser, "argument --build is required by argument --source") 00151 00152 00153 # Get libraries list 00154 libraries = [] 00155 00156 # Additional Libraries 00157 if options.rpc: 00158 libraries.extend(["rpc"]) 00159 if options.usb: 00160 libraries.append("usb") 00161 if options.dsp: 00162 libraries.extend(["dsp"]) 00163 if options.cpputest_lib: 00164 libraries.extend(["cpputest"]) 00165 00166 # Build results 00167 failures = [] 00168 successes = [] 00169 skipped = [] 00170 00171 for toolchain in toolchains: 00172 if not TOOLCHAIN_CLASSES[toolchain].check_executable(): 00173 search_path = TOOLCHAIN_PATHS[toolchain] or "No path set" 00174 args_error(parser, "Could not find executable for %s.\n" 00175 "Currently set search path: %s" 00176 % (toolchain, search_path)) 00177 00178 for toolchain in toolchains: 00179 for target in targets: 00180 tt_id = "%s::%s" % (toolchain, target) 00181 if toolchain not in TARGET_MAP[target].supported_toolchains: 00182 # Log this later 00183 print("%s skipped: toolchain not supported" % tt_id) 00184 skipped.append(tt_id) 00185 else: 00186 try: 00187 notify = TerminalNotifer(options.verbose, options.silent) 00188 mcu = TARGET_MAP[target] 00189 profile = extract_profile(parser, options, toolchain) 00190 if options.source_dir: 00191 lib_build_res = build_library( 00192 options.source_dir, options.build_dir, mcu, toolchain, 00193 jobs=options.jobs, 00194 clean=options.clean, 00195 archive=(not options.no_archive), 00196 macros=options.macros, 00197 name=options.artifact_name, 00198 build_profile=profile, 00199 ignore=options.ignore, 00200 ) 00201 else: 00202 lib_build_res = build_mbed_libs( 00203 mcu, toolchain, 00204 jobs=options.jobs, 00205 clean=options.clean, 00206 macros=options.macros, 00207 build_profile=profile, 00208 ignore=options.ignore, 00209 ) 00210 00211 for lib_id in libraries: 00212 build_lib( 00213 lib_id, mcu, toolchain, 00214 clean=options.clean, 00215 macros=options.macros, 00216 jobs=options.jobs, 00217 build_profile=profile, 00218 ignore=options.ignore, 00219 ) 00220 if lib_build_res: 00221 successes.append(tt_id) 00222 else: 00223 skipped.append(tt_id) 00224 except Exception as e: 00225 if options.verbose: 00226 import traceback 00227 traceback.print_exc(file=sys.stdout) 00228 sys.exit(1) 00229 failures.append(tt_id) 00230 print(e) 00231 00232 # Write summary of the builds 00233 print("\nCompleted in: (%.2f)s\n" % (time() - start)) 00234 00235 for report, report_name in [(successes, "Build successes:"), 00236 (skipped, "Build skipped:"), 00237 (failures, "Build failures:"), 00238 ]: 00239 if report: 00240 print(print_build_results(report, report_name)) 00241 00242 if failures: 00243 sys.exit(1)
Generated on Tue Jul 12 2022 12:32:22 by
