]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/workspace_tools/build.py
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / workspace_tools / build.py
1 #! /usr/bin/env python2
2 """
3 mbed SDK
4 Copyright (c) 2011-2013 ARM Limited
5
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
9
10     http://www.apache.org/licenses/LICENSE-2.0
11
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.
17
18 LIBRARIES BUILD
19 """
20 import sys
21 from time import time
22 from os.path import join, abspath, dirname
23
24
25 # Be sure that the tools directory is in the search path
26 ROOT = abspath(join(dirname(__file__), ".."))
27 sys.path.insert(0, ROOT)
28
29
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
39
40 if __name__ == '__main__':
41     start = time()
42
43     # Parse Options
44     parser = get_default_options_parser()
45
46     # Extra libraries
47     parser.add_option("-r", "--rtos",
48                       action="store_true",
49                       dest="rtos",
50                       default=False,
51                       help="Compile the rtos")
52
53     parser.add_option("-e", "--eth",
54                       action="store_true", dest="eth",
55                       default=False,
56                       help="Compile the ethernet library")
57
58     parser.add_option("-U", "--usb_host",
59                       action="store_true",
60                       dest="usb_host",
61                       default=False,
62                       help="Compile the USB Host library")
63
64     parser.add_option("-u", "--usb",
65                       action="store_true",
66                       dest="usb",
67                       default=False,
68                       help="Compile the USB Device library")
69
70     parser.add_option("-d", "--dsp",
71                       action="store_true",
72                       dest="dsp",
73                       default=False,
74                       help="Compile the DSP library")
75
76     parser.add_option("-F", "--fat",
77                       action="store_true",
78                       dest="fat",
79                       default=False,
80                       help="Compile FS ad SD card file system library")
81
82     parser.add_option("-b", "--ublox",
83                       action="store_true",
84                       dest="ublox",
85                       default=False,
86                       help="Compile the u-blox library")
87
88     parser.add_option("", "--cpputest",
89                       action="store_true",
90                       dest="cpputest_lib",
91                       default=False,
92                       help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)")
93
94     parser.add_option("-D", "",
95                       action="append",
96                       dest="macros",
97                       help="Add a macro definition")
98
99     parser.add_option("-S", "--supported-toolchains",
100                       action="store_true",
101                       dest="supported_toolchains",
102                       default=False,
103                       help="Displays supported matrix of MCUs and toolchains")
104
105     parser.add_option("", "--cppcheck",
106                       action="store_true",
107                       dest="cppcheck_validation",
108                       default=False,
109                       help="Forces 'cppcheck' static code analysis")
110
111     parser.add_option('-f', '--filter',
112                       dest='general_filter_regex',
113                       default=None,
114                       help='For some commands you can use filter to filter out results')
115
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")
118
119     parser.add_option("-v", "--verbose",
120                       action="store_true",
121                       dest="verbose",
122                       default=False,
123                       help="Verbose diagnostic output")
124
125     parser.add_option("--silent",
126                       action="store_true",
127                       dest="silent",
128                       default=False,
129                       help="Silent diagnostic output (no copy, compile notification)")
130
131     parser.add_option("-x", "--extra-verbose-notifications",
132                       action="store_true",
133                       dest="extra_verbose_notify",
134                       default=False,
135                       help="Makes compiler more verbose, CI friendly.")
136
137     (options, args) = parser.parse_args()
138
139     # Only prints matrix of supported toolchains
140     if options.supported_toolchains:
141         print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
142         exit(0)
143
144     # Get target list
145     if options.mcu:
146         mcu_list = (options.mcu).split(",")
147         for mcu in mcu_list:
148             if mcu not in TARGET_NAMES:
149                 print "Given MCU '%s' not into the supported list:\n%s" % (mcu, TARGET_NAMES)
150                 sys.exit(1)
151         targets = mcu_list
152     else:
153         targets = TARGET_NAMES
154
155     # Get toolchains list
156     if options.tool:
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)
161                 sys.exit(1)
162         toolchains = toolchain_list
163     else:
164         toolchains = TOOLCHAINS
165
166     # Get libraries list
167     libraries = []
168
169     # Additional Libraries
170     if options.rtos:
171         libraries.extend(["rtx", "rtos"])
172     if options.eth:
173         libraries.append("eth")
174     if options.usb:
175         libraries.append("usb")
176     if options.usb_host:
177         libraries.append("usb_host")
178     if options.dsp:
179         libraries.extend(["cmsis_dsp", "dsp"])
180     if options.fat:
181         libraries.extend(["fat"])
182     if options.ublox:
183         libraries.extend(["rtx", "rtos", "usb_host", "ublox"])
184     if options.cpputest_lib:
185         libraries.extend(["cpputest"])
186
187     notify = print_notify_verbose if options.extra_verbose_notify else None  # Special notify for CI (more verbose)
188
189     # Build results
190     failures = []
191     successes = []
192     skipped = []
193
194     # CPPCHECK code validation
195     if options.cppcheck_validation:
196         for toolchain in toolchains:
197             for target in targets:
198                 try:
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)
208                         pass
209                 except Exception, e:
210                     if options.verbose:
211                         import traceback
212                         traceback.print_exc(file=sys.stdout)
213                         sys.exit(1)
214                     print e
215     else:
216         # Build
217         for toolchain in toolchains:
218             for target in targets:
219                 tt_id = "%s::%s" % (toolchain, target)
220                 try:
221                     mcu = TARGET_MAP[target]
222                     lib_build_res = build_mbed_libs(mcu, toolchain,
223                                                     options=options.options,
224                                                     notify=notify,
225                                                     verbose=options.verbose,
226                                                     silent=options.silent,
227                                                     jobs=options.jobs,
228                                                     clean=options.clean,
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,
234                                   notify=notify,
235                                   verbose=options.verbose,
236                                   silent=options.silent,
237                                   clean=options.clean,
238                                   macros=options.macros,
239                                   jobs=options.jobs)
240                     if lib_build_res:
241                         successes.append(tt_id)
242                     else:
243                         skipped.append(tt_id)
244                 except Exception, e:
245                     if options.verbose:
246                         import traceback
247                         traceback.print_exc(file=sys.stdout)
248                         sys.exit(1)
249                     failures.append(tt_id)
250                     print e
251
252     # Write summary of the builds
253     print
254     print "Completed in: (%.2f)s" % (time() - start)
255     print
256
257     print print_build_results(successes, "Build successes:"),
258     print print_build_results(skipped, "Build skipped:"),
259     print print_build_results(failures, "Build failures:"),
260
261     if failures:
262         sys.exit(1)