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