Development mbed library for MAX32630FTHR
Dependents: blinky_max32630fthr
tools/build_release.py@0:5c4d7b2438d3, 2016-11-11 (annotated)
- Committer:
- switches
- Date:
- Fri Nov 11 20:59:50 2016 +0000
- Revision:
- 0:5c4d7b2438d3
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:5c4d7b2438d3 | 1 | #! /usr/bin/env python |
switches | 0:5c4d7b2438d3 | 2 | """ |
switches | 0:5c4d7b2438d3 | 3 | mbed SDK |
switches | 0:5c4d7b2438d3 | 4 | Copyright (c) 2011-2013 ARM Limited |
switches | 0:5c4d7b2438d3 | 5 | |
switches | 0:5c4d7b2438d3 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
switches | 0:5c4d7b2438d3 | 7 | you may not use this file except in compliance with the License. |
switches | 0:5c4d7b2438d3 | 8 | You may obtain a copy of the License at |
switches | 0:5c4d7b2438d3 | 9 | |
switches | 0:5c4d7b2438d3 | 10 | http://www.apache.org/licenses/LICENSE-2.0 |
switches | 0:5c4d7b2438d3 | 11 | |
switches | 0:5c4d7b2438d3 | 12 | Unless required by applicable law or agreed to in writing, software |
switches | 0:5c4d7b2438d3 | 13 | distributed under the License is distributed on an "AS IS" BASIS, |
switches | 0:5c4d7b2438d3 | 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
switches | 0:5c4d7b2438d3 | 15 | See the License for the specific language governing permissions and |
switches | 0:5c4d7b2438d3 | 16 | limitations under the License. |
switches | 0:5c4d7b2438d3 | 17 | """ |
switches | 0:5c4d7b2438d3 | 18 | import sys |
switches | 0:5c4d7b2438d3 | 19 | from time import time |
switches | 0:5c4d7b2438d3 | 20 | from os.path import join, abspath, dirname, normpath |
switches | 0:5c4d7b2438d3 | 21 | from optparse import OptionParser |
switches | 0:5c4d7b2438d3 | 22 | import json |
switches | 0:5c4d7b2438d3 | 23 | from shutil import copy |
switches | 0:5c4d7b2438d3 | 24 | |
switches | 0:5c4d7b2438d3 | 25 | # Be sure that the tools directory is in the search path |
switches | 0:5c4d7b2438d3 | 26 | ROOT = abspath(join(dirname(__file__), "..")) |
switches | 0:5c4d7b2438d3 | 27 | sys.path.insert(0, ROOT) |
switches | 0:5c4d7b2438d3 | 28 | |
switches | 0:5c4d7b2438d3 | 29 | from tools.build_api import build_mbed_libs |
switches | 0:5c4d7b2438d3 | 30 | from tools.build_api import write_build_report |
switches | 0:5c4d7b2438d3 | 31 | from tools.build_api import get_mbed_official_release |
switches | 0:5c4d7b2438d3 | 32 | from tools.options import extract_profile |
switches | 0:5c4d7b2438d3 | 33 | from tools.targets import TARGET_MAP, TARGET_NAMES |
switches | 0:5c4d7b2438d3 | 34 | from tools.test_exporters import ReportExporter, ResultExporterType |
switches | 0:5c4d7b2438d3 | 35 | from tools.test_api import SingleTestRunner |
switches | 0:5c4d7b2438d3 | 36 | from tools.test_api import singletest_in_cli_mode |
switches | 0:5c4d7b2438d3 | 37 | from tools.paths import TEST_DIR, MBED_LIBRARIES |
switches | 0:5c4d7b2438d3 | 38 | from tools.tests import TEST_MAP |
switches | 0:5c4d7b2438d3 | 39 | |
switches | 0:5c4d7b2438d3 | 40 | OFFICIAL_MBED_LIBRARY_BUILD = get_mbed_official_release('2') |
switches | 0:5c4d7b2438d3 | 41 | |
switches | 0:5c4d7b2438d3 | 42 | if __name__ == '__main__': |
switches | 0:5c4d7b2438d3 | 43 | parser = OptionParser() |
switches | 0:5c4d7b2438d3 | 44 | parser.add_option('-o', '--official', dest="official_only", default=False, action="store_true", |
switches | 0:5c4d7b2438d3 | 45 | help="Build using only the official toolchain for each target") |
switches | 0:5c4d7b2438d3 | 46 | parser.add_option("-j", "--jobs", type="int", dest="jobs", |
switches | 0:5c4d7b2438d3 | 47 | default=1, help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs") |
switches | 0:5c4d7b2438d3 | 48 | parser.add_option("-v", "--verbose", action="store_true", dest="verbose", |
switches | 0:5c4d7b2438d3 | 49 | default=False, help="Verbose diagnostic output") |
switches | 0:5c4d7b2438d3 | 50 | parser.add_option("-t", "--toolchains", dest="toolchains", help="Use toolchains names separated by comma") |
switches | 0:5c4d7b2438d3 | 51 | |
switches | 0:5c4d7b2438d3 | 52 | parser.add_option("--profile", dest="profile", action="append", default=[]) |
switches | 0:5c4d7b2438d3 | 53 | |
switches | 0:5c4d7b2438d3 | 54 | parser.add_option("-p", "--platforms", dest="platforms", default="", help="Build only for the platform namesseparated by comma") |
switches | 0:5c4d7b2438d3 | 55 | |
switches | 0:5c4d7b2438d3 | 56 | parser.add_option("-L", "--list-config", action="store_true", dest="list_config", |
switches | 0:5c4d7b2438d3 | 57 | default=False, help="List the platforms and toolchains in the release in JSON") |
switches | 0:5c4d7b2438d3 | 58 | |
switches | 0:5c4d7b2438d3 | 59 | parser.add_option("", "--report-build", dest="report_build_file_name", help="Output the build results to an junit xml file") |
switches | 0:5c4d7b2438d3 | 60 | |
switches | 0:5c4d7b2438d3 | 61 | parser.add_option("", "--build-tests", dest="build_tests", help="Build all tests in the given directories (relative to /libraries/tests)") |
switches | 0:5c4d7b2438d3 | 62 | |
switches | 0:5c4d7b2438d3 | 63 | |
switches | 0:5c4d7b2438d3 | 64 | options, args = parser.parse_args() |
switches | 0:5c4d7b2438d3 | 65 | |
switches | 0:5c4d7b2438d3 | 66 | |
switches | 0:5c4d7b2438d3 | 67 | |
switches | 0:5c4d7b2438d3 | 68 | if options.list_config: |
switches | 0:5c4d7b2438d3 | 69 | print json.dumps(OFFICIAL_MBED_LIBRARY_BUILD, indent=4) |
switches | 0:5c4d7b2438d3 | 70 | sys.exit() |
switches | 0:5c4d7b2438d3 | 71 | |
switches | 0:5c4d7b2438d3 | 72 | start = time() |
switches | 0:5c4d7b2438d3 | 73 | build_report = {} |
switches | 0:5c4d7b2438d3 | 74 | build_properties = {} |
switches | 0:5c4d7b2438d3 | 75 | |
switches | 0:5c4d7b2438d3 | 76 | platforms = None |
switches | 0:5c4d7b2438d3 | 77 | if options.platforms != "": |
switches | 0:5c4d7b2438d3 | 78 | platforms = set(options.platforms.split(",")) |
switches | 0:5c4d7b2438d3 | 79 | |
switches | 0:5c4d7b2438d3 | 80 | if options.build_tests: |
switches | 0:5c4d7b2438d3 | 81 | # Get all paths |
switches | 0:5c4d7b2438d3 | 82 | directories = options.build_tests.split(',') |
switches | 0:5c4d7b2438d3 | 83 | for i in range(len(directories)): |
switches | 0:5c4d7b2438d3 | 84 | directories[i] = normpath(join(TEST_DIR, directories[i])) |
switches | 0:5c4d7b2438d3 | 85 | |
switches | 0:5c4d7b2438d3 | 86 | test_names = [] |
switches | 0:5c4d7b2438d3 | 87 | |
switches | 0:5c4d7b2438d3 | 88 | for test_id in TEST_MAP.keys(): |
switches | 0:5c4d7b2438d3 | 89 | # Prevents tests with multiple source dirs from being checked |
switches | 0:5c4d7b2438d3 | 90 | if isinstance( TEST_MAP[test_id].source_dir, basestring): |
switches | 0:5c4d7b2438d3 | 91 | test_path = normpath(TEST_MAP[test_id].source_dir) |
switches | 0:5c4d7b2438d3 | 92 | for directory in directories: |
switches | 0:5c4d7b2438d3 | 93 | if directory in test_path: |
switches | 0:5c4d7b2438d3 | 94 | test_names.append(test_id) |
switches | 0:5c4d7b2438d3 | 95 | |
switches | 0:5c4d7b2438d3 | 96 | mut_counter = 1 |
switches | 0:5c4d7b2438d3 | 97 | mut = {} |
switches | 0:5c4d7b2438d3 | 98 | test_spec = { |
switches | 0:5c4d7b2438d3 | 99 | "targets": {} |
switches | 0:5c4d7b2438d3 | 100 | } |
switches | 0:5c4d7b2438d3 | 101 | |
switches | 0:5c4d7b2438d3 | 102 | if options.toolchains: |
switches | 0:5c4d7b2438d3 | 103 | print "Only building using the following toolchains: %s" % (options.toolchains) |
switches | 0:5c4d7b2438d3 | 104 | |
switches | 0:5c4d7b2438d3 | 105 | for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD: |
switches | 0:5c4d7b2438d3 | 106 | toolchains = None |
switches | 0:5c4d7b2438d3 | 107 | if platforms is not None and not target_name in platforms: |
switches | 0:5c4d7b2438d3 | 108 | print("Excluding %s from release" % target_name) |
switches | 0:5c4d7b2438d3 | 109 | continue |
switches | 0:5c4d7b2438d3 | 110 | |
switches | 0:5c4d7b2438d3 | 111 | if target_name not in TARGET_NAMES: |
switches | 0:5c4d7b2438d3 | 112 | print "Target '%s' is not a valid target. Excluding from release" |
switches | 0:5c4d7b2438d3 | 113 | continue |
switches | 0:5c4d7b2438d3 | 114 | |
switches | 0:5c4d7b2438d3 | 115 | if options.official_only: |
switches | 0:5c4d7b2438d3 | 116 | toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),) |
switches | 0:5c4d7b2438d3 | 117 | else: |
switches | 0:5c4d7b2438d3 | 118 | toolchains = toolchain_list |
switches | 0:5c4d7b2438d3 | 119 | |
switches | 0:5c4d7b2438d3 | 120 | if options.toolchains: |
switches | 0:5c4d7b2438d3 | 121 | toolchainSet = set(toolchains) |
switches | 0:5c4d7b2438d3 | 122 | toolchains = toolchainSet.intersection(set((options.toolchains).split(','))) |
switches | 0:5c4d7b2438d3 | 123 | |
switches | 0:5c4d7b2438d3 | 124 | mut[str(mut_counter)] = { |
switches | 0:5c4d7b2438d3 | 125 | "mcu": target_name |
switches | 0:5c4d7b2438d3 | 126 | } |
switches | 0:5c4d7b2438d3 | 127 | |
switches | 0:5c4d7b2438d3 | 128 | mut_counter += 1 |
switches | 0:5c4d7b2438d3 | 129 | |
switches | 0:5c4d7b2438d3 | 130 | test_spec["targets"][target_name] = toolchains |
switches | 0:5c4d7b2438d3 | 131 | |
switches | 0:5c4d7b2438d3 | 132 | single_test = SingleTestRunner(_muts=mut, |
switches | 0:5c4d7b2438d3 | 133 | _parser=parser, |
switches | 0:5c4d7b2438d3 | 134 | _opts=options, |
switches | 0:5c4d7b2438d3 | 135 | _opts_report_build_file_name=options.report_build_file_name, |
switches | 0:5c4d7b2438d3 | 136 | _test_spec=test_spec, |
switches | 0:5c4d7b2438d3 | 137 | _opts_test_by_names=",".join(test_names), |
switches | 0:5c4d7b2438d3 | 138 | _opts_verbose=options.verbose, |
switches | 0:5c4d7b2438d3 | 139 | _opts_only_build_tests=True, |
switches | 0:5c4d7b2438d3 | 140 | _opts_suppress_summary=True, |
switches | 0:5c4d7b2438d3 | 141 | _opts_jobs=options.jobs, |
switches | 0:5c4d7b2438d3 | 142 | _opts_include_non_automated=True, |
switches | 0:5c4d7b2438d3 | 143 | _opts_build_report=build_report, |
switches | 0:5c4d7b2438d3 | 144 | _opts_build_properties=build_properties) |
switches | 0:5c4d7b2438d3 | 145 | # Runs test suite in CLI mode |
switches | 0:5c4d7b2438d3 | 146 | test_summary, shuffle_seed, test_summary_ext, test_suite_properties_ext, new_build_report, new_build_properties = single_test.execute() |
switches | 0:5c4d7b2438d3 | 147 | else: |
switches | 0:5c4d7b2438d3 | 148 | for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD: |
switches | 0:5c4d7b2438d3 | 149 | if platforms is not None and not target_name in platforms: |
switches | 0:5c4d7b2438d3 | 150 | print("Excluding %s from release" % target_name) |
switches | 0:5c4d7b2438d3 | 151 | continue |
switches | 0:5c4d7b2438d3 | 152 | |
switches | 0:5c4d7b2438d3 | 153 | if target_name not in TARGET_NAMES: |
switches | 0:5c4d7b2438d3 | 154 | print "Target '%s' is not a valid target. Excluding from release" |
switches | 0:5c4d7b2438d3 | 155 | continue |
switches | 0:5c4d7b2438d3 | 156 | |
switches | 0:5c4d7b2438d3 | 157 | if options.official_only: |
switches | 0:5c4d7b2438d3 | 158 | toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),) |
switches | 0:5c4d7b2438d3 | 159 | else: |
switches | 0:5c4d7b2438d3 | 160 | toolchains = toolchain_list |
switches | 0:5c4d7b2438d3 | 161 | |
switches | 0:5c4d7b2438d3 | 162 | if options.toolchains: |
switches | 0:5c4d7b2438d3 | 163 | print "Only building using the following toolchains: %s" % (options.toolchains) |
switches | 0:5c4d7b2438d3 | 164 | toolchainSet = set(toolchains) |
switches | 0:5c4d7b2438d3 | 165 | toolchains = toolchainSet.intersection(set((options.toolchains).split(','))) |
switches | 0:5c4d7b2438d3 | 166 | |
switches | 0:5c4d7b2438d3 | 167 | for toolchain in toolchains: |
switches | 0:5c4d7b2438d3 | 168 | id = "%s::%s" % (target_name, toolchain) |
switches | 0:5c4d7b2438d3 | 169 | |
switches | 0:5c4d7b2438d3 | 170 | profile = extract_profile(parser, options, toolchain) |
switches | 0:5c4d7b2438d3 | 171 | |
switches | 0:5c4d7b2438d3 | 172 | try: |
switches | 0:5c4d7b2438d3 | 173 | built_mbed_lib = build_mbed_libs(TARGET_MAP[target_name], |
switches | 0:5c4d7b2438d3 | 174 | toolchain, |
switches | 0:5c4d7b2438d3 | 175 | verbose=options.verbose, |
switches | 0:5c4d7b2438d3 | 176 | jobs=options.jobs, |
switches | 0:5c4d7b2438d3 | 177 | report=build_report, |
switches | 0:5c4d7b2438d3 | 178 | properties=build_properties, |
switches | 0:5c4d7b2438d3 | 179 | build_profile=profile) |
switches | 0:5c4d7b2438d3 | 180 | |
switches | 0:5c4d7b2438d3 | 181 | except Exception, e: |
switches | 0:5c4d7b2438d3 | 182 | print str(e) |
switches | 0:5c4d7b2438d3 | 183 | |
switches | 0:5c4d7b2438d3 | 184 | # copy targets.json file as part of the release |
switches | 0:5c4d7b2438d3 | 185 | copy(join(dirname(abspath(__file__)), '..', 'targets', 'targets.json'), MBED_LIBRARIES) |
switches | 0:5c4d7b2438d3 | 186 | |
switches | 0:5c4d7b2438d3 | 187 | # Write summary of the builds |
switches | 0:5c4d7b2438d3 | 188 | if options.report_build_file_name: |
switches | 0:5c4d7b2438d3 | 189 | file_report_exporter = ReportExporter(ResultExporterType.JUNIT, package="build") |
switches | 0:5c4d7b2438d3 | 190 | file_report_exporter.report_to_file(build_report, options.report_build_file_name, test_suite_properties=build_properties) |
switches | 0:5c4d7b2438d3 | 191 | |
switches | 0:5c4d7b2438d3 | 192 | print "\n\nCompleted in: (%.2f)s" % (time() - start) |
switches | 0:5c4d7b2438d3 | 193 | |
switches | 0:5c4d7b2438d3 | 194 | print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build") |
switches | 0:5c4d7b2438d3 | 195 | status = print_report_exporter.report(build_report) |
switches | 0:5c4d7b2438d3 | 196 | |
switches | 0:5c4d7b2438d3 | 197 | if not status: |
switches | 0:5c4d7b2438d3 | 198 | sys.exit(1) |