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.
Dependents: mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more
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 import sys 00021 from time import time 00022 from os.path import join, abspath, dirname 00023 00024 00025 # Be sure that the tools directory is in the search path 00026 ROOT = abspath(join(dirname(__file__), "..")) 00027 sys.path.insert(0, ROOT) 00028 00029 00030 from tools.toolchains import TOOLCHAINS, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS 00031 from tools.toolchains import mbedToolchain 00032 from tools.targets import TARGET_NAMES, TARGET_MAP 00033 from tools.options import get_default_options_parser 00034 from tools.options import extract_profile 00035 from tools.build_api import build_library, build_mbed_libs, build_lib 00036 from tools.build_api import mcu_toolchain_matrix 00037 from tools.build_api import print_build_results 00038 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT 00039 from utils import argparse_filestring_type, args_error 00040 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, CLI_COLOR_MAP 00041 from utils import argparse_filestring_type, argparse_dir_not_parent 00042 00043 if __name__ == '__main__': 00044 start = time() 00045 00046 # Parse Options 00047 parser = get_default_options_parser() 00048 00049 parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, 00050 default=None, help="The source (input) directory", action="append") 00051 00052 parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT), 00053 default=None, help="The build (output) directory") 00054 00055 parser.add_argument("--no-archive", dest="no_archive", action="store_true", 00056 default=False, help="Do not produce archive (.ar) file, but rather .o") 00057 00058 # Extra libraries 00059 parser.add_argument("-r", "--rtos", 00060 action="store_true", 00061 dest="rtos", 00062 default=False, 00063 help="Compile the rtos") 00064 00065 parser.add_argument("--rpc", 00066 action="store_true", 00067 dest="rpc", 00068 default=False, 00069 help="Compile the rpc library") 00070 00071 parser.add_argument("-e", "--eth", 00072 action="store_true", dest="eth", 00073 default=False, 00074 help="Compile the ethernet library") 00075 00076 parser.add_argument("-U", "--usb_host", 00077 action="store_true", 00078 dest="usb_host", 00079 default=False, 00080 help="Compile the USB Host library") 00081 00082 parser.add_argument("-u", "--usb", 00083 action="store_true", 00084 dest="usb", 00085 default=False, 00086 help="Compile the USB Device library") 00087 00088 parser.add_argument("-d", "--dsp", 00089 action="store_true", 00090 dest="dsp", 00091 default=False, 00092 help="Compile the DSP library") 00093 00094 parser.add_argument("-b", "--ublox", 00095 action="store_true", 00096 dest="ublox", 00097 default=False, 00098 help="Compile the u-blox library") 00099 00100 parser.add_argument( "--cpputest", 00101 action="store_true", 00102 dest="cpputest_lib", 00103 default=False, 00104 help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)") 00105 00106 parser.add_argument("-D", 00107 action="append", 00108 dest="macros", 00109 help="Add a macro definition") 00110 00111 parser.add_argument("-S", "--supported-toolchains", 00112 action="store_true", 00113 dest="supported_toolchains", 00114 default=False, 00115 help="Displays supported matrix of MCUs and toolchains") 00116 00117 parser.add_argument('-f', '--filter', 00118 dest='general_filter_regex', 00119 default=None, 00120 help='For some commands you can use filter to filter out results') 00121 00122 parser.add_argument("-j", "--jobs", type=int, dest="jobs", 00123 default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)") 00124 parser.add_argument("-N", "--artifact-name", dest="artifact_name", 00125 default=None, help="The built project's name") 00126 00127 parser.add_argument("-v", "--verbose", 00128 action="store_true", 00129 dest="verbose", 00130 default=False, 00131 help="Verbose diagnostic output") 00132 00133 parser.add_argument("--silent", 00134 action="store_true", 00135 dest="silent", 00136 default=False, 00137 help="Silent diagnostic output (no copy, compile notification)") 00138 00139 parser.add_argument("-x", "--extra-verbose-notifications", 00140 action="store_true", 00141 dest="extra_verbose_notify", 00142 default=False, 00143 help="Makes compiler more verbose, CI friendly.") 00144 00145 options = parser.parse_args() 00146 00147 # Only prints matrix of supported toolchains 00148 if options.supported_toolchains: 00149 print mcu_toolchain_matrix(platform_filter=options.general_filter_regex) 00150 exit(0) 00151 00152 00153 # Get target list 00154 targets = options.mcu if options.mcu else TARGET_NAMES 00155 00156 # Get toolchains list 00157 toolchains = options.tool if options.tool else TOOLCHAINS 00158 00159 if options.source_dir and not options.build_dir: 00160 args_error(parser, "argument --build is required by argument --source") 00161 00162 if options.color: 00163 # This import happens late to prevent initializing colorization when we don't need it 00164 import colorize 00165 if options.verbose: 00166 notify = mbedToolchain.print_notify_verbose 00167 else: 00168 notify = mbedToolchain.print_notify 00169 notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify) 00170 else: 00171 notify = None 00172 00173 # Get libraries list 00174 libraries = [] 00175 00176 # Additional Libraries 00177 if options.rtos: 00178 libraries.extend(["rtx", "rtos"]) 00179 if options.rpc: 00180 libraries.extend(["rpc"]) 00181 if options.eth: 00182 libraries.append("eth") 00183 if options.usb: 00184 libraries.append("usb") 00185 if options.usb_host: 00186 libraries.append("usb_host") 00187 if options.dsp: 00188 libraries.extend(["dsp"]) 00189 if options.ublox: 00190 libraries.extend(["rtx", "rtos", "usb_host", "ublox"]) 00191 if options.cpputest_lib: 00192 libraries.extend(["cpputest"]) 00193 00194 # Build results 00195 failures = [] 00196 successes = [] 00197 skipped = [] 00198 00199 for toolchain in toolchains: 00200 if not TOOLCHAIN_CLASSES[toolchain].check_executable(): 00201 search_path = TOOLCHAIN_PATHS[toolchain] or "No path set" 00202 args_error(parser, "Could not find executable for %s.\n" 00203 "Currently set search path: %s" 00204 % (toolchain, search_path)) 00205 00206 for toolchain in toolchains: 00207 for target in targets: 00208 tt_id = "%s::%s" % (toolchain, target) 00209 if toolchain not in TARGET_MAP[target].supported_toolchains: 00210 # Log this later 00211 print "%s skipped: toolchain not supported" % tt_id 00212 skipped.append(tt_id) 00213 else: 00214 try: 00215 mcu = TARGET_MAP[target] 00216 profile = extract_profile(parser, options, toolchain) 00217 if options.source_dir: 00218 lib_build_res = build_library(options.source_dir, options.build_dir, mcu, toolchain, 00219 extra_verbose=options.extra_verbose_notify, 00220 verbose=options.verbose, 00221 silent=options.silent, 00222 jobs=options.jobs, 00223 clean=options.clean, 00224 archive=(not options.no_archive), 00225 macros=options.macros, 00226 name=options.artifact_name, 00227 build_profile=profile) 00228 else: 00229 lib_build_res = build_mbed_libs(mcu, toolchain, 00230 extra_verbose=options.extra_verbose_notify, 00231 verbose=options.verbose, 00232 silent=options.silent, 00233 jobs=options.jobs, 00234 clean=options.clean, 00235 macros=options.macros, 00236 build_profile=profile) 00237 00238 for lib_id in libraries: 00239 build_lib(lib_id, mcu, toolchain, 00240 extra_verbose=options.extra_verbose_notify, 00241 verbose=options.verbose, 00242 silent=options.silent, 00243 clean=options.clean, 00244 macros=options.macros, 00245 jobs=options.jobs, 00246 build_profile=profile) 00247 if lib_build_res: 00248 successes.append(tt_id) 00249 else: 00250 skipped.append(tt_id) 00251 except Exception, e: 00252 if options.verbose: 00253 import traceback 00254 traceback.print_exc(file=sys.stdout) 00255 sys.exit(1) 00256 failures.append(tt_id) 00257 print e 00258 00259 00260 # Write summary of the builds 00261 print 00262 print "Completed in: (%.2f)s" % (time() - start) 00263 print 00264 00265 for report, report_name in [(successes, "Build successes:"), 00266 (skipped, "Build skipped:"), 00267 (failures, "Build failures:"), 00268 ]: 00269 if report: 00270 print print_build_results(report, report_name), 00271 00272 if failures: 00273 sys.exit(1)
Generated on Tue Jul 12 2022 11:02:21 by
1.7.2