1 #! /usr/bin/env python2
4 Copyright (c) 2011-2013 ARM Limited
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
22 from os.path import join, abspath, dirname
25 # Be sure that the tools directory is in the search path
26 ROOT = abspath(join(dirname(__file__), ".."))
27 sys.path.insert(0, ROOT)
30 from workspace_tools.toolchains import TOOLCHAINS
31 from workspace_tools.toolchains import print_notify_verbose
32 from workspace_tools.targets import TARGET_NAMES, TARGET_MAP
33 from workspace_tools.options import get_default_options_parser
34 from workspace_tools.build_api import build_mbed_libs, build_lib
35 from workspace_tools.build_api import mcu_toolchain_matrix
36 from workspace_tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library
37 from workspace_tools.build_api import print_build_results
38 from workspace_tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
40 if __name__ == '__main__':
44 parser = get_default_options_parser()
47 parser.add_option("-r", "--rtos",
51 help="Compile the rtos")
53 parser.add_option("-e", "--eth",
54 action="store_true", dest="eth",
56 help="Compile the ethernet library")
58 parser.add_option("-U", "--usb_host",
62 help="Compile the USB Host library")
64 parser.add_option("-u", "--usb",
68 help="Compile the USB Device library")
70 parser.add_option("-d", "--dsp",
74 help="Compile the DSP library")
76 parser.add_option("-F", "--fat",
80 help="Compile FS ad SD card file system library")
82 parser.add_option("-b", "--ublox",
86 help="Compile the u-blox library")
88 parser.add_option("", "--cpputest",
92 help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)")
94 parser.add_option("-D", "",
97 help="Add a macro definition")
99 parser.add_option("-S", "--supported-toolchains",
101 dest="supported_toolchains",
103 help="Displays supported matrix of MCUs and toolchains")
105 parser.add_option("", "--cppcheck",
107 dest="cppcheck_validation",
109 help="Forces 'cppcheck' static code analysis")
111 parser.add_option('-f', '--filter',
112 dest='general_filter_regex',
114 help='For some commands you can use filter to filter out results')
116 parser.add_option("-j", "--jobs", type="int", dest="jobs",
117 default=1, help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs")
119 parser.add_option("-v", "--verbose",
123 help="Verbose diagnostic output")
125 parser.add_option("--silent",
129 help="Silent diagnostic output (no copy, compile notification)")
131 parser.add_option("-x", "--extra-verbose-notifications",
133 dest="extra_verbose_notify",
135 help="Makes compiler more verbose, CI friendly.")
137 (options, args) = parser.parse_args()
139 # Only prints matrix of supported toolchains
140 if options.supported_toolchains:
141 print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
146 mcu_list = (options.mcu).split(",")
148 if mcu not in TARGET_NAMES:
149 print "Given MCU '%s' not into the supported list:\n%s" % (mcu, TARGET_NAMES)
153 targets = TARGET_NAMES
155 # Get toolchains list
157 toolchain_list = (options.tool).split(",")
158 for tc in toolchain_list:
159 if tc not in TOOLCHAINS:
160 print "Given toolchain '%s' not into the supported list:\n%s" % (tc, TOOLCHAINS)
162 toolchains = toolchain_list
164 toolchains = TOOLCHAINS
169 # Additional Libraries
171 libraries.extend(["rtx", "rtos"])
173 libraries.append("eth")
175 libraries.append("usb")
177 libraries.append("usb_host")
179 libraries.extend(["cmsis_dsp", "dsp"])
181 libraries.extend(["fat"])
183 libraries.extend(["rtx", "rtos", "usb_host", "ublox"])
184 if options.cpputest_lib:
185 libraries.extend(["cpputest"])
187 notify = print_notify_verbose if options.extra_verbose_notify else None # Special notify for CI (more verbose)
194 # CPPCHECK code validation
195 if options.cppcheck_validation:
196 for toolchain in toolchains:
197 for target in targets:
199 mcu = TARGET_MAP[target]
200 # CMSIS and MBED libs analysis
201 static_analysis_scan(mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, verbose=options.verbose, jobs=options.jobs)
202 for lib_id in libraries:
203 # Static check for library
204 static_analysis_scan_lib(lib_id, mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT,
205 options=options.options,
206 notify=notify, verbose=options.verbose, jobs=options.jobs, clean=options.clean,
207 macros=options.macros)
212 traceback.print_exc(file=sys.stdout)
217 for toolchain in toolchains:
218 for target in targets:
219 tt_id = "%s::%s" % (toolchain, target)
221 mcu = TARGET_MAP[target]
222 lib_build_res = build_mbed_libs(mcu, toolchain,
223 options=options.options,
225 verbose=options.verbose,
226 silent=options.silent,
229 macros=options.macros)
230 for lib_id in libraries:
231 notify = print_notify_verbose if options.extra_verbose_notify else None # Special notify for CI (more verbose)
232 build_lib(lib_id, mcu, toolchain,
233 options=options.options,
235 verbose=options.verbose,
236 silent=options.silent,
238 macros=options.macros,
241 successes.append(tt_id)
243 skipped.append(tt_id)
247 traceback.print_exc(file=sys.stdout)
249 failures.append(tt_id)
252 # Write summary of the builds
254 print "Completed in: (%.2f)s" % (time() - start)
257 print print_build_results(successes, "Build successes:"),
258 print print_build_results(skipped, "Build skipped:"),
259 print print_build_results(failures, "Build failures:"),