Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

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