|
17 | 17 | """
|
18 | 18 | import sys
|
19 | 19 | from time import time
|
20 |
| -from os.path import join, abspath, dirname |
| 20 | +from os.path import join, abspath, dirname, normpath |
21 | 21 | from optparse import OptionParser
|
| 22 | +import json |
22 | 23 |
|
23 | 24 | # Be sure that the tools directory is in the search path
|
24 | 25 | ROOT = abspath(join(dirname(__file__), ".."))
|
|
28 | 29 | from workspace_tools.build_api import write_build_report
|
29 | 30 | from workspace_tools.targets import TARGET_MAP
|
30 | 31 | from workspace_tools.test_exporters import ReportExporter, ResultExporterType
|
| 32 | +from workspace_tools.test_api import SingleTestRunner |
| 33 | +from workspace_tools.test_api import singletest_in_cli_mode |
| 34 | +from workspace_tools.paths import TEST_DIR |
| 35 | +from workspace_tools.tests import TEST_MAP |
31 | 36 |
|
32 | 37 | OFFICIAL_MBED_LIBRARY_BUILD = (
|
33 | 38 | ('LPC11U24', ('ARM', 'uARM', 'GCC_ARM', 'IAR')),
|
|
153 | 158 |
|
154 | 159 | parser.add_option("-p", "--platforms", dest="platforms", default="", help="Build only for the platform namesseparated by comma")
|
155 | 160 |
|
| 161 | + parser.add_option("-L", "--list-config", action="store_true", dest="list_config", |
| 162 | + default=False, help="List the platforms and toolchains in the release in JSON") |
| 163 | + |
156 | 164 | parser.add_option("", "--report-build", dest="report_build_file_name", help="Output the build results to an junit xml file")
|
157 | 165 |
|
| 166 | + parser.add_option("", "--build-tests", dest="build_tests", help="Build all tests in the given directories (relative to /libraries/tests)") |
158 | 167 |
|
159 |
| - options, args = parser.parse_args() |
160 |
| - start = time() |
161 |
| - report = {} |
162 |
| - properties = {} |
163 | 168 |
|
164 |
| - platforms = None |
165 |
| - if options.platforms != "": |
166 |
| - platforms = set(options.platforms.split(",")) |
| 169 | + options, args = parser.parse_args() |
167 | 170 |
|
168 |
| - for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD: |
169 |
| - if platforms is not None and not target_name in platforms: |
170 |
| - print("Excluding %s from release" % target_name) |
171 |
| - continue |
172 | 171 |
|
173 |
| - if options.official_only: |
174 |
| - toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),) |
175 |
| - else: |
176 |
| - toolchains = toolchain_list |
177 | 172 |
|
178 |
| - if options.toolchains: |
179 |
| - print "Only building using the following toolchains: %s" % (options.toolchains) |
180 |
| - toolchainSet = set(toolchains) |
181 |
| - toolchains = toolchainSet.intersection(set((options.toolchains).split(','))) |
| 173 | + if options.list_config: |
| 174 | + print json.dumps(OFFICIAL_MBED_LIBRARY_BUILD, indent=4) |
| 175 | + sys.exit() |
182 | 176 |
|
183 |
| - for toolchain in toolchains: |
184 |
| - id = "%s::%s" % (target_name, toolchain) |
| 177 | + start = time() |
| 178 | + build_report = {} |
| 179 | + build_properties = {} |
185 | 180 |
|
186 |
| - try: |
187 |
| - built_mbed_lib = build_mbed_libs(TARGET_MAP[target_name], toolchain, verbose=options.verbose, jobs=options.jobs, report=report, properties=properties) |
| 181 | + platforms = None |
| 182 | + if options.platforms != "": |
| 183 | + platforms = set(options.platforms.split(",")) |
188 | 184 |
|
189 |
| - except Exception, e: |
190 |
| - print str(e) |
| 185 | + if options.build_tests: |
| 186 | + # Get all paths |
| 187 | + directories = options.build_tests.split(',') |
| 188 | + for i in range(len(directories)): |
| 189 | + directories[i] = normpath(join(TEST_DIR, directories[i])) |
| 190 | + |
| 191 | + test_names = [] |
| 192 | + |
| 193 | + for test_id in TEST_MAP.keys(): |
| 194 | + # Prevents tests with multiple source dirs from being checked |
| 195 | + if isinstance( TEST_MAP[test_id].source_dir, basestring): |
| 196 | + test_path = normpath(TEST_MAP[test_id].source_dir) |
| 197 | + for directory in directories: |
| 198 | + if directory in test_path: |
| 199 | + test_names.append(test_id) |
| 200 | + |
| 201 | + mut_counter = 1 |
| 202 | + mut = {} |
| 203 | + test_spec = { |
| 204 | + "targets": {} |
| 205 | + } |
| 206 | + |
| 207 | + for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD: |
| 208 | + toolchains = None |
| 209 | + if platforms is not None and not target_name in platforms: |
| 210 | + print("Excluding %s from release" % target_name) |
| 211 | + continue |
| 212 | + |
| 213 | + if options.official_only: |
| 214 | + toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),) |
| 215 | + else: |
| 216 | + toolchains = toolchain_list |
| 217 | + |
| 218 | + if options.toolchains: |
| 219 | + print "Only building using the following toolchains: %s" % (options.toolchains) |
| 220 | + toolchainSet = set(toolchains) |
| 221 | + toolchains = toolchainSet.intersection(set((options.toolchains).split(','))) |
| 222 | + |
| 223 | + mut[str(mut_counter)] = { |
| 224 | + "mcu": target_name |
| 225 | + } |
| 226 | + |
| 227 | + mut_counter += 1 |
| 228 | + |
| 229 | + test_spec["targets"][target_name] = toolchains |
| 230 | + |
| 231 | + single_test = SingleTestRunner(_muts=mut, |
| 232 | + _opts_report_build_file_name=options.report_build_file_name, |
| 233 | + _test_spec=test_spec, |
| 234 | + _opts_test_by_names=",".join(test_names), |
| 235 | + _opts_verbose=options.verbose, |
| 236 | + _opts_only_build_tests=True, |
| 237 | + _opts_suppress_summary=True, |
| 238 | + _opts_jobs=options.jobs, |
| 239 | + _opts_include_non_automated=True, |
| 240 | + _opts_build_report=build_report, |
| 241 | + _opts_build_properties=build_properties) |
| 242 | + # Runs test suite in CLI mode |
| 243 | + test_summary, shuffle_seed, test_summary_ext, test_suite_properties_ext, new_build_report, new_build_properties = single_test.execute() |
| 244 | + else: |
| 245 | + for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD: |
| 246 | + if platforms is not None and not target_name in platforms: |
| 247 | + print("Excluding %s from release" % target_name) |
| 248 | + continue |
| 249 | + |
| 250 | + if options.official_only: |
| 251 | + toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),) |
| 252 | + else: |
| 253 | + toolchains = toolchain_list |
| 254 | + |
| 255 | + if options.toolchains: |
| 256 | + print "Only building using the following toolchains: %s" % (options.toolchains) |
| 257 | + toolchainSet = set(toolchains) |
| 258 | + toolchains = toolchainSet.intersection(set((options.toolchains).split(','))) |
| 259 | + |
| 260 | + for toolchain in toolchains: |
| 261 | + id = "%s::%s" % (target_name, toolchain) |
| 262 | + |
| 263 | + try: |
| 264 | + built_mbed_lib = build_mbed_libs(TARGET_MAP[target_name], toolchain, verbose=options.verbose, jobs=options.jobs, report=build_report, properties=build_properties) |
| 265 | + |
| 266 | + except Exception, e: |
| 267 | + print str(e) |
191 | 268 |
|
192 | 269 | # Write summary of the builds
|
193 | 270 | if options.report_build_file_name:
|
194 | 271 | file_report_exporter = ReportExporter(ResultExporterType.JUNIT, package="build")
|
195 |
| - file_report_exporter.report_to_file(report, options.report_build_file_name, test_suite_properties=properties) |
| 272 | + file_report_exporter.report_to_file(build_report, options.report_build_file_name, test_suite_properties=build_properties) |
196 | 273 |
|
197 | 274 | print "\n\nCompleted in: (%.2f)s" % (time() - start)
|
198 | 275 |
|
199 | 276 | print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")
|
200 |
| - status = print_report_exporter.report(report) |
| 277 | + status = print_report_exporter.report(build_report) |
201 | 278 |
|
202 | 279 | if not status:
|
203 | 280 | sys.exit(1)
|
0 commit comments