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