BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

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