Knight KE / Mbed OS Game_Master
Committer:
WFKnight
Date:
Thu Jun 21 13:51:43 2018 +0000
Revision:
0:9b3d4731edbb
UART, RTOS, LED

Who changed what in which revision?

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