Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
build_release.py
00001 #! /usr/bin/env python 00002 """ 00003 mbed SDK 00004 Copyright (c) 2011-2013 ARM Limited 00005 00006 Licensed under the Apache License, Version 2.0 (the "License"); 00007 you may not use this file except in compliance with the License. 00008 You may obtain a copy of the License at 00009 00010 http://www.apache.org/licenses/LICENSE-2.0 00011 00012 Unless required by applicable law or agreed to in writing, software 00013 distributed under the License is distributed on an "AS IS" BASIS, 00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 See the License for the specific language governing permissions and 00016 limitations under the License. 00017 """ 00018 import sys 00019 from time import time 00020 from os.path import join, abspath, dirname, normpath 00021 from optparse import OptionParser 00022 import json 00023 from shutil import copy 00024 00025 # Be sure that the tools directory is in the search path 00026 ROOT = abspath(join(dirname(__file__), "..")) 00027 sys.path.insert(0, ROOT) 00028 00029 from tools.build_api import build_mbed_libs 00030 from tools.build_api import write_build_report 00031 from tools.build_api import get_mbed_official_release 00032 from tools.options import extract_profile 00033 from tools.targets import TARGET_MAP, TARGET_NAMES 00034 from tools.test_exporters import ReportExporter, ResultExporterType 00035 from tools.test_api import SingleTestRunner 00036 from tools.test_api import singletest_in_cli_mode 00037 from tools.paths import TEST_DIR, MBED_LIBRARIES 00038 from tools.tests import TEST_MAP 00039 from tools.notifier.term import TerminalNotifier 00040 00041 OFFICIAL_MBED_LIBRARY_BUILD = get_mbed_official_release('2') 00042 00043 if __name__ == '__main__': 00044 parser = OptionParser() 00045 parser.add_option('-o', '--official', dest="official_only", default=False, action="store_true", 00046 help="Build using only the official toolchain for each target") 00047 parser.add_option("-j", "--jobs", type="int", dest="jobs", 00048 default=1, help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs") 00049 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", 00050 default=False, help="Verbose diagnostic output") 00051 parser.add_option("-t", "--toolchains", dest="toolchains", help="Use toolchains names separated by comma") 00052 00053 parser.add_option("--profile", dest="profile", action="append", default=[]) 00054 00055 parser.add_option("-p", "--platforms", dest="platforms", default="", help="Build only for the platform namesseparated by comma") 00056 00057 parser.add_option("-L", "--list-config", action="store_true", dest="list_config", 00058 default=False, help="List the platforms and toolchains in the release in JSON") 00059 00060 parser.add_option("", "--report-build", dest="report_build_file_name", help="Output the build results to an junit xml file") 00061 00062 parser.add_option("", "--build-tests", dest="build_tests", help="Build all tests in the given directories (relative to /libraries/tests)") 00063 00064 00065 options, args = parser.parse_args() 00066 00067 00068 00069 if options.list_config: 00070 print json.dumps(OFFICIAL_MBED_LIBRARY_BUILD, indent=4) 00071 sys.exit() 00072 00073 start = time() 00074 build_report = {} 00075 build_properties = {} 00076 00077 platforms = None 00078 if options.platforms != "": 00079 platforms = set(options.platforms.split(",")) 00080 00081 status = True 00082 00083 if options.build_tests: 00084 # Get all paths 00085 directories = options.build_tests.split(',') 00086 for i in range(len(directories)): 00087 directories[i] = normpath(join(TEST_DIR, directories[i])) 00088 00089 test_names = [] 00090 00091 for test_id in TEST_MAP.keys(): 00092 # Prevents tests with multiple source dirs from being checked 00093 if isinstance( TEST_MAP[test_id].source_dir, basestring): 00094 test_path = normpath(TEST_MAP[test_id].source_dir) 00095 for directory in directories: 00096 if directory in test_path: 00097 test_names.append(test_id) 00098 00099 mut_counter = 1 00100 mut = {} 00101 test_spec = { 00102 "targets": {} 00103 } 00104 00105 if options.toolchains: 00106 print "Only building using the following toolchains: %s" % (options.toolchains) 00107 00108 for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD: 00109 toolchains = None 00110 if platforms is not None and not target_name in platforms: 00111 print("Excluding %s from release" % target_name) 00112 continue 00113 00114 if target_name not in TARGET_NAMES: 00115 print "Target '%s' is not a valid target. Excluding from release" 00116 continue 00117 00118 if options.official_only: 00119 toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),) 00120 else: 00121 toolchains = toolchain_list 00122 00123 if options.toolchains: 00124 toolchainSet = set(toolchains) 00125 toolchains = toolchainSet.intersection(set((options.toolchains).split(','))) 00126 00127 mut[str(mut_counter)] = { 00128 "mcu": target_name 00129 } 00130 00131 mut_counter += 1 00132 00133 test_spec["targets"][target_name] = toolchains 00134 00135 single_test = SingleTestRunner(_muts=mut, 00136 _parser=parser, 00137 _opts=options, 00138 _opts_report_build_file_name=options.report_build_file_name, 00139 _test_spec=test_spec, 00140 _opts_test_by_names=",".join(test_names), 00141 _opts_verbose=options.verbose, 00142 _opts_only_build_tests=True, 00143 _opts_suppress_summary=True, 00144 _opts_jobs=options.jobs, 00145 _opts_include_non_automated=True, 00146 _opts_build_report=build_report, 00147 _opts_build_properties=build_properties) 00148 # Runs test suite in CLI mode 00149 test_summary, shuffle_seed, test_summary_ext, test_suite_properties_ext, new_build_report, new_build_properties = single_test.execute() 00150 else: 00151 for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD: 00152 if platforms is not None and not target_name in platforms: 00153 print("Excluding %s from release" % target_name) 00154 continue 00155 00156 if target_name not in TARGET_NAMES: 00157 print "Target '%s' is not a valid target. Excluding from release" 00158 continue 00159 00160 if options.official_only: 00161 toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),) 00162 else: 00163 toolchains = toolchain_list 00164 00165 if options.toolchains: 00166 print "Only building using the following toolchains: %s" % (options.toolchains) 00167 toolchainSet = set(toolchains) 00168 toolchains = toolchainSet.intersection(set((options.toolchains).split(','))) 00169 00170 for toolchain in toolchains: 00171 built_mbed_lib = build_mbed_libs( 00172 TARGET_MAP[target_name], 00173 toolchain, 00174 notify=TerminalNotifier(options.verbose), 00175 jobs=options.jobs, 00176 report=build_report, 00177 properties=build_properties, 00178 build_profile=extract_profile(parser, options, toolchain), 00179 ) 00180 00181 00182 # copy targets.json file as part of the release 00183 copy(join(dirname(abspath(__file__)), '..', 'targets', 'targets.json'), MBED_LIBRARIES) 00184 00185 # Write summary of the builds 00186 if options.report_build_file_name: 00187 file_report_exporter = ReportExporter(ResultExporterType.JUNIT, package="build") 00188 file_report_exporter.report_to_file(build_report, options.report_build_file_name, test_suite_properties=build_properties) 00189 00190 print "\n\nCompleted in: (%.2f)s" % (time() - start) 00191 00192 print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build") 00193 status = status and print_report_exporter.report(build_report) 00194 00195 if not status: 00196 sys.exit(1)
Generated on Tue Aug 9 2022 00:37:03 by
1.7.2