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.
Fork of mbed-tools by
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 00031 from tools.targets import TARGET_NAMES, TARGET_MAP 00032 from tools.options import get_default_options_parser 00033 from tools.build_api import build_mbed_libs, build_lib 00034 from tools.build_api import mcu_toolchain_matrix 00035 from tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library 00036 from tools.build_api import print_build_results 00037 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT 00038 00039 if __name__ == '__main__': 00040 start = time() 00041 00042 # Parse Options 00043 parser = get_default_options_parser() 00044 00045 # Extra libraries 00046 parser.add_option("-r", "--rtos", 00047 action="store_true", 00048 dest="rtos", 00049 default=False, 00050 help="Compile the rtos") 00051 00052 parser.add_option("--rpc", 00053 action="store_true", 00054 dest="rpc", 00055 default=False, 00056 help="Compile the rpc library") 00057 00058 parser.add_option("-e", "--eth", 00059 action="store_true", dest="eth", 00060 default=False, 00061 help="Compile the ethernet library") 00062 00063 parser.add_option("-U", "--usb_host", 00064 action="store_true", 00065 dest="usb_host", 00066 default=False, 00067 help="Compile the USB Host library") 00068 00069 parser.add_option("-u", "--usb", 00070 action="store_true", 00071 dest="usb", 00072 default=False, 00073 help="Compile the USB Device library") 00074 00075 parser.add_option("-d", "--dsp", 00076 action="store_true", 00077 dest="dsp", 00078 default=False, 00079 help="Compile the DSP library") 00080 00081 parser.add_option("-F", "--fat", 00082 action="store_true", 00083 dest="fat", 00084 default=False, 00085 help="Compile FS and SD card file system library") 00086 00087 parser.add_option("-b", "--ublox", 00088 action="store_true", 00089 dest="ublox", 00090 default=False, 00091 help="Compile the u-blox library") 00092 00093 parser.add_option("", "--cpputest", 00094 action="store_true", 00095 dest="cpputest_lib", 00096 default=False, 00097 help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)") 00098 00099 parser.add_option("-D", "", 00100 action="append", 00101 dest="macros", 00102 help="Add a macro definition") 00103 00104 parser.add_option("-S", "--supported-toolchains", 00105 action="store_true", 00106 dest="supported_toolchains", 00107 default=False, 00108 help="Displays supported matrix of MCUs and toolchains") 00109 00110 parser.add_option("", "--cppcheck", 00111 action="store_true", 00112 dest="cppcheck_validation", 00113 default=False, 00114 help="Forces 'cppcheck' static code analysis") 00115 00116 parser.add_option('-f', '--filter', 00117 dest='general_filter_regex', 00118 default=None, 00119 help='For some commands you can use filter to filter out results') 00120 00121 parser.add_option("-j", "--jobs", type="int", dest="jobs", 00122 default=1, help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs") 00123 00124 parser.add_option("-v", "--verbose", 00125 action="store_true", 00126 dest="verbose", 00127 default=False, 00128 help="Verbose diagnostic output") 00129 00130 parser.add_option("--silent", 00131 action="store_true", 00132 dest="silent", 00133 default=False, 00134 help="Silent diagnostic output (no copy, compile notification)") 00135 00136 parser.add_option("-x", "--extra-verbose-notifications", 00137 action="store_true", 00138 dest="extra_verbose_notify", 00139 default=False, 00140 help="Makes compiler more verbose, CI friendly.") 00141 00142 (options, args) = parser.parse_args() 00143 00144 # Only prints matrix of supported toolchains 00145 if options.supported_toolchains: 00146 print mcu_toolchain_matrix(platform_filter=options.general_filter_regex) 00147 exit(0) 00148 00149 # Get target list 00150 if options.mcu: 00151 mcu_list = (options.mcu).split(",") 00152 for mcu in mcu_list: 00153 if mcu not in TARGET_NAMES: 00154 print "Given MCU '%s' not into the supported list:\n%s" % (mcu, TARGET_NAMES) 00155 sys.exit(1) 00156 targets = mcu_list 00157 else: 00158 targets = TARGET_NAMES 00159 00160 # Get toolchains list 00161 if options.tool: 00162 toolchain_list = (options.tool).split(",") 00163 for tc in toolchain_list: 00164 if tc not in TOOLCHAINS: 00165 print "Given toolchain '%s' not into the supported list:\n%s" % (tc, TOOLCHAINS) 00166 sys.exit(1) 00167 toolchains = toolchain_list 00168 else: 00169 toolchains = TOOLCHAINS 00170 00171 # Get libraries list 00172 libraries = [] 00173 00174 # Additional Libraries 00175 if options.rtos: 00176 libraries.extend(["rtx", "rtos"]) 00177 if options.rpc: 00178 libraries.extend(["rpc"]) 00179 if options.eth: 00180 libraries.append("eth") 00181 if options.usb: 00182 libraries.append("usb") 00183 if options.usb_host: 00184 libraries.append("usb_host") 00185 if options.dsp: 00186 libraries.extend(["cmsis_dsp", "dsp"]) 00187 if options.fat: 00188 libraries.extend(["fat"]) 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 # CPPCHECK code validation 00200 if options.cppcheck_validation: 00201 for toolchain in toolchains: 00202 for target in targets: 00203 try: 00204 mcu = TARGET_MAP[target] 00205 # CMSIS and MBED libs analysis 00206 static_analysis_scan(mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, verbose=options.verbose, jobs=options.jobs) 00207 for lib_id in libraries: 00208 # Static check for library 00209 static_analysis_scan_lib(lib_id, mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, 00210 options=options.options, 00211 extra_verbose=options.extra_verbose_notify, verbose=options.verbose, jobs=options.jobs, clean=options.clean, 00212 macros=options.macros) 00213 pass 00214 except Exception, e: 00215 if options.verbose: 00216 import traceback 00217 traceback.print_exc(file=sys.stdout) 00218 sys.exit(1) 00219 print e 00220 else: 00221 # Build 00222 for toolchain in toolchains: 00223 for target in targets: 00224 tt_id = "%s::%s" % (toolchain, target) 00225 try: 00226 mcu = TARGET_MAP[target] 00227 lib_build_res = build_mbed_libs(mcu, toolchain, 00228 options=options.options, 00229 extra_verbose=options.extra_verbose_notify, 00230 verbose=options.verbose, 00231 silent=options.silent, 00232 jobs=options.jobs, 00233 clean=options.clean, 00234 macros=options.macros) 00235 for lib_id in libraries: 00236 build_lib(lib_id, mcu, toolchain, 00237 options=options.options, 00238 extra_verbose=options.extra_verbose_notify, 00239 verbose=options.verbose, 00240 silent=options.silent, 00241 clean=options.clean, 00242 macros=options.macros, 00243 jobs=options.jobs) 00244 if lib_build_res: 00245 successes.append(tt_id) 00246 else: 00247 skipped.append(tt_id) 00248 except Exception, e: 00249 if options.verbose: 00250 import traceback 00251 traceback.print_exc(file=sys.stdout) 00252 sys.exit(1) 00253 failures.append(tt_id) 00254 print e 00255 00256 # Write summary of the builds 00257 print 00258 print "Completed in: (%.2f)s" % (time() - start) 00259 print 00260 00261 for report, report_name in [(successes, "Build successes:"), 00262 (skipped, "Build skipped:"), 00263 (failures, "Build failures:"), 00264 ]: 00265 if report: 00266 print print_build_results(report, report_name), 00267 00268 if failures: 00269 sys.exit(1)
Generated on Thu Jun 15 2023 14:54:59 by
