BA
/
BaBoRo_test2
Backup 1
mbed-os/tools/build_everything.py@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:02dd72d1d465 | 1 | #! /usr/bin/env python |
borlanic | 0:02dd72d1d465 | 2 | """ |
borlanic | 0:02dd72d1d465 | 3 | mbed SDK |
borlanic | 0:02dd72d1d465 | 4 | Copyright (c) 2011-2013 ARM Limited |
borlanic | 0:02dd72d1d465 | 5 | |
borlanic | 0:02dd72d1d465 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:02dd72d1d465 | 7 | you may not use this file except in compliance with the License. |
borlanic | 0:02dd72d1d465 | 8 | You may obtain a copy of the License at |
borlanic | 0:02dd72d1d465 | 9 | |
borlanic | 0:02dd72d1d465 | 10 | http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:02dd72d1d465 | 11 | |
borlanic | 0:02dd72d1d465 | 12 | Unless required by applicable law or agreed to in writing, software |
borlanic | 0:02dd72d1d465 | 13 | distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:02dd72d1d465 | 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:02dd72d1d465 | 15 | See the License for the specific language governing permissions and |
borlanic | 0:02dd72d1d465 | 16 | limitations under the License. |
borlanic | 0:02dd72d1d465 | 17 | """ |
borlanic | 0:02dd72d1d465 | 18 | import sys |
borlanic | 0:02dd72d1d465 | 19 | from time import time |
borlanic | 0:02dd72d1d465 | 20 | from os.path import join, abspath, dirname, normpath |
borlanic | 0:02dd72d1d465 | 21 | from optparse import OptionParser |
borlanic | 0:02dd72d1d465 | 22 | import json |
borlanic | 0:02dd72d1d465 | 23 | |
borlanic | 0:02dd72d1d465 | 24 | # Be sure that the tools directory is in the search path |
borlanic | 0:02dd72d1d465 | 25 | ROOT = abspath(join(dirname(__file__), "..")) |
borlanic | 0:02dd72d1d465 | 26 | sys.path.insert(0, ROOT) |
borlanic | 0:02dd72d1d465 | 27 | |
borlanic | 0:02dd72d1d465 | 28 | from tools.build_api import build_library |
borlanic | 0:02dd72d1d465 | 29 | from tools.build_api import write_build_report |
borlanic | 0:02dd72d1d465 | 30 | from tools.targets import TARGET_MAP, TARGET_NAMES |
borlanic | 0:02dd72d1d465 | 31 | from tools.toolchains import TOOLCHAINS |
borlanic | 0:02dd72d1d465 | 32 | from tools.test_exporters import ReportExporter, ResultExporterType |
borlanic | 0:02dd72d1d465 | 33 | from tools.test_api import find_tests, build_tests, test_spec_from_test_builds |
borlanic | 0:02dd72d1d465 | 34 | from tools.build_release import OFFICIAL_MBED_LIBRARY_BUILD |
borlanic | 0:02dd72d1d465 | 35 | |
borlanic | 0:02dd72d1d465 | 36 | if __name__ == '__main__': |
borlanic | 0:02dd72d1d465 | 37 | try: |
borlanic | 0:02dd72d1d465 | 38 | parser = OptionParser() |
borlanic | 0:02dd72d1d465 | 39 | |
borlanic | 0:02dd72d1d465 | 40 | parser.add_option("--source", dest="source_dir", |
borlanic | 0:02dd72d1d465 | 41 | default=None, help="The source (input) directory (for sources other than tests). Defaults to current directory.", action="append") |
borlanic | 0:02dd72d1d465 | 42 | |
borlanic | 0:02dd72d1d465 | 43 | parser.add_option("--build", dest="build_dir", |
borlanic | 0:02dd72d1d465 | 44 | default=None, help="The build (output) directory") |
borlanic | 0:02dd72d1d465 | 45 | |
borlanic | 0:02dd72d1d465 | 46 | parser.add_option('-c', '--clean', |
borlanic | 0:02dd72d1d465 | 47 | dest='clean', |
borlanic | 0:02dd72d1d465 | 48 | metavar=False, |
borlanic | 0:02dd72d1d465 | 49 | action="store_true", |
borlanic | 0:02dd72d1d465 | 50 | help='Clean the build directory') |
borlanic | 0:02dd72d1d465 | 51 | |
borlanic | 0:02dd72d1d465 | 52 | parser.add_option('-a', '--all', dest="all", default=False, action="store_true", |
borlanic | 0:02dd72d1d465 | 53 | help="Build every target (including unofficial targets) and with each of the supported toolchains") |
borlanic | 0:02dd72d1d465 | 54 | |
borlanic | 0:02dd72d1d465 | 55 | parser.add_option('-o', '--official', dest="official_only", default=False, action="store_true", |
borlanic | 0:02dd72d1d465 | 56 | help="Build using only the official toolchain for each target") |
borlanic | 0:02dd72d1d465 | 57 | |
borlanic | 0:02dd72d1d465 | 58 | parser.add_option("-D", "", |
borlanic | 0:02dd72d1d465 | 59 | action="append", |
borlanic | 0:02dd72d1d465 | 60 | dest="macros", |
borlanic | 0:02dd72d1d465 | 61 | help="Add a macro definition") |
borlanic | 0:02dd72d1d465 | 62 | |
borlanic | 0:02dd72d1d465 | 63 | parser.add_option("-j", "--jobs", type="int", dest="jobs", |
borlanic | 0:02dd72d1d465 | 64 | default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)") |
borlanic | 0:02dd72d1d465 | 65 | |
borlanic | 0:02dd72d1d465 | 66 | parser.add_option("-v", "--verbose", action="store_true", dest="verbose", |
borlanic | 0:02dd72d1d465 | 67 | default=False, help="Verbose diagnostic output") |
borlanic | 0:02dd72d1d465 | 68 | |
borlanic | 0:02dd72d1d465 | 69 | parser.add_option("-t", "--toolchains", dest="toolchains", help="Use toolchains names separated by comma") |
borlanic | 0:02dd72d1d465 | 70 | |
borlanic | 0:02dd72d1d465 | 71 | parser.add_option("-p", "--platforms", dest="platforms", default="", help="Build only for the platform namesseparated by comma") |
borlanic | 0:02dd72d1d465 | 72 | |
borlanic | 0:02dd72d1d465 | 73 | parser.add_option("", "--config", action="store_true", dest="list_config", |
borlanic | 0:02dd72d1d465 | 74 | default=False, help="List the platforms and toolchains in the release in JSON") |
borlanic | 0:02dd72d1d465 | 75 | |
borlanic | 0:02dd72d1d465 | 76 | parser.add_option("", "--test-spec", dest="test_spec", |
borlanic | 0:02dd72d1d465 | 77 | default=None, help="Destination path for a test spec file that can be used by the Greentea automated test tool") |
borlanic | 0:02dd72d1d465 | 78 | |
borlanic | 0:02dd72d1d465 | 79 | parser.add_option("", "--build-report-junit", dest="build_report_junit", help="Output the build results to an junit xml file") |
borlanic | 0:02dd72d1d465 | 80 | |
borlanic | 0:02dd72d1d465 | 81 | parser.add_option("--continue-on-build-fail", action="store_true", dest="continue_on_build_fail", |
borlanic | 0:02dd72d1d465 | 82 | default=False, help="Continue trying to build all tests if a build failure occurs") |
borlanic | 0:02dd72d1d465 | 83 | |
borlanic | 0:02dd72d1d465 | 84 | options, args = parser.parse_args() |
borlanic | 0:02dd72d1d465 | 85 | |
borlanic | 0:02dd72d1d465 | 86 | # Get set of valid targets |
borlanic | 0:02dd72d1d465 | 87 | all_platforms = set(TARGET_NAMES) |
borlanic | 0:02dd72d1d465 | 88 | bad_platforms = set() |
borlanic | 0:02dd72d1d465 | 89 | platforms = set() |
borlanic | 0:02dd72d1d465 | 90 | if options.platforms != "": |
borlanic | 0:02dd72d1d465 | 91 | platforms = set(options.platforms.split(",")) |
borlanic | 0:02dd72d1d465 | 92 | bad_platforms = platforms.difference(all_platforms) |
borlanic | 0:02dd72d1d465 | 93 | platforms = platforms.intersection(all_platforms) |
borlanic | 0:02dd72d1d465 | 94 | elif options.all: |
borlanic | 0:02dd72d1d465 | 95 | platforms = all_platforms |
borlanic | 0:02dd72d1d465 | 96 | else: |
borlanic | 0:02dd72d1d465 | 97 | platforms = set(x[0] for x in OFFICIAL_MBED_LIBRARY_BUILD) |
borlanic | 0:02dd72d1d465 | 98 | bad_platforms = platforms.difference(all_platforms) |
borlanic | 0:02dd72d1d465 | 99 | platforms = platforms.intersection(all_platforms) |
borlanic | 0:02dd72d1d465 | 100 | |
borlanic | 0:02dd72d1d465 | 101 | for bad_platform in bad_platforms: |
borlanic | 0:02dd72d1d465 | 102 | print "Platform '%s' is not a valid platform. Skipping." % bad_platform |
borlanic | 0:02dd72d1d465 | 103 | |
borlanic | 0:02dd72d1d465 | 104 | if options.platforms: |
borlanic | 0:02dd72d1d465 | 105 | print "Limiting build to the following platforms: %s" % ",".join(platforms) |
borlanic | 0:02dd72d1d465 | 106 | |
borlanic | 0:02dd72d1d465 | 107 | # Get set of valid toolchains |
borlanic | 0:02dd72d1d465 | 108 | all_toolchains = set(TOOLCHAINS) |
borlanic | 0:02dd72d1d465 | 109 | bad_toolchains = set() |
borlanic | 0:02dd72d1d465 | 110 | toolchains = set() |
borlanic | 0:02dd72d1d465 | 111 | |
borlanic | 0:02dd72d1d465 | 112 | if options.toolchains: |
borlanic | 0:02dd72d1d465 | 113 | toolchains = set(options.toolchains.split(",")) |
borlanic | 0:02dd72d1d465 | 114 | bad_toolchains = toolchains.difference(all_toolchains) |
borlanic | 0:02dd72d1d465 | 115 | toolchains = toolchains.intersection(all_toolchains) |
borlanic | 0:02dd72d1d465 | 116 | else: |
borlanic | 0:02dd72d1d465 | 117 | toolchains = all_toolchains |
borlanic | 0:02dd72d1d465 | 118 | |
borlanic | 0:02dd72d1d465 | 119 | for bad_toolchain in bad_toolchains: |
borlanic | 0:02dd72d1d465 | 120 | print "Toolchain '%s' is not a valid toolchain. Skipping." % bad_toolchain |
borlanic | 0:02dd72d1d465 | 121 | |
borlanic | 0:02dd72d1d465 | 122 | if options.toolchains: |
borlanic | 0:02dd72d1d465 | 123 | print "Limiting build to the following toolchains: %s" % ",".join(toolchains) |
borlanic | 0:02dd72d1d465 | 124 | |
borlanic | 0:02dd72d1d465 | 125 | build_config = {} |
borlanic | 0:02dd72d1d465 | 126 | |
borlanic | 0:02dd72d1d465 | 127 | for platform in platforms: |
borlanic | 0:02dd72d1d465 | 128 | target = TARGET_MAP[platform] |
borlanic | 0:02dd72d1d465 | 129 | |
borlanic | 0:02dd72d1d465 | 130 | if options.official_only: |
borlanic | 0:02dd72d1d465 | 131 | default_toolchain = getattr(target, 'default_toolchain', 'ARM') |
borlanic | 0:02dd72d1d465 | 132 | build_config[platform] = list(toolchains.intersection(set([default_toolchain]))) |
borlanic | 0:02dd72d1d465 | 133 | else: |
borlanic | 0:02dd72d1d465 | 134 | build_config[platform] = list(toolchains.intersection(set(target.supported_toolchains))) |
borlanic | 0:02dd72d1d465 | 135 | |
borlanic | 0:02dd72d1d465 | 136 | if options.list_config: |
borlanic | 0:02dd72d1d465 | 137 | print json.dumps(build_config, indent=4) |
borlanic | 0:02dd72d1d465 | 138 | sys.exit(0) |
borlanic | 0:02dd72d1d465 | 139 | |
borlanic | 0:02dd72d1d465 | 140 | # Ensure build directory is set |
borlanic | 0:02dd72d1d465 | 141 | if not options.build_dir: |
borlanic | 0:02dd72d1d465 | 142 | print "[ERROR] You must specify a build path" |
borlanic | 0:02dd72d1d465 | 143 | sys.exit(1) |
borlanic | 0:02dd72d1d465 | 144 | |
borlanic | 0:02dd72d1d465 | 145 | # Default base source path is the current directory |
borlanic | 0:02dd72d1d465 | 146 | base_source_paths = options.source_dir |
borlanic | 0:02dd72d1d465 | 147 | if not base_source_paths: |
borlanic | 0:02dd72d1d465 | 148 | base_source_paths = ['.'] |
borlanic | 0:02dd72d1d465 | 149 | |
borlanic | 0:02dd72d1d465 | 150 | |
borlanic | 0:02dd72d1d465 | 151 | start = time() |
borlanic | 0:02dd72d1d465 | 152 | build_report = {} |
borlanic | 0:02dd72d1d465 | 153 | build_properties = {} |
borlanic | 0:02dd72d1d465 | 154 | test_builds = {} |
borlanic | 0:02dd72d1d465 | 155 | total_build_success = True |
borlanic | 0:02dd72d1d465 | 156 | |
borlanic | 0:02dd72d1d465 | 157 | for target_name, target_toolchains in build_config.items(): |
borlanic | 0:02dd72d1d465 | 158 | target = TARGET_MAP[target_name] |
borlanic | 0:02dd72d1d465 | 159 | |
borlanic | 0:02dd72d1d465 | 160 | for target_toolchain in target_toolchains: |
borlanic | 0:02dd72d1d465 | 161 | library_build_success = True |
borlanic | 0:02dd72d1d465 | 162 | |
borlanic | 0:02dd72d1d465 | 163 | try: |
borlanic | 0:02dd72d1d465 | 164 | build_directory = join(options.build_dir, target_name, target_toolchain) |
borlanic | 0:02dd72d1d465 | 165 | # Build sources |
borlanic | 0:02dd72d1d465 | 166 | build_library(base_source_paths, build_directory, target, target_toolchain, |
borlanic | 0:02dd72d1d465 | 167 | jobs=options.jobs, |
borlanic | 0:02dd72d1d465 | 168 | clean=options.clean, |
borlanic | 0:02dd72d1d465 | 169 | report=build_report, |
borlanic | 0:02dd72d1d465 | 170 | properties=build_properties, |
borlanic | 0:02dd72d1d465 | 171 | name="mbed-os", |
borlanic | 0:02dd72d1d465 | 172 | macros=options.macros, |
borlanic | 0:02dd72d1d465 | 173 | verbose=options.verbose, |
borlanic | 0:02dd72d1d465 | 174 | archive=False) |
borlanic | 0:02dd72d1d465 | 175 | except Exception, e: |
borlanic | 0:02dd72d1d465 | 176 | library_build_success = False |
borlanic | 0:02dd72d1d465 | 177 | print "Failed to build library" |
borlanic | 0:02dd72d1d465 | 178 | print e |
borlanic | 0:02dd72d1d465 | 179 | |
borlanic | 0:02dd72d1d465 | 180 | if options.continue_on_build_fail or library_build_success: |
borlanic | 0:02dd72d1d465 | 181 | # Build all the tests |
borlanic | 0:02dd72d1d465 | 182 | all_tests = find_tests(base_source_paths[0], target_name, toolchain_name) |
borlanic | 0:02dd72d1d465 | 183 | test_build_success, test_build = build_tests(all_tests, [build_directory], build_directory, target, target_toolchain, |
borlanic | 0:02dd72d1d465 | 184 | clean=options.clean, |
borlanic | 0:02dd72d1d465 | 185 | report=build_report, |
borlanic | 0:02dd72d1d465 | 186 | properties=build_properties, |
borlanic | 0:02dd72d1d465 | 187 | macros=options.macros, |
borlanic | 0:02dd72d1d465 | 188 | verbose=options.verbose, |
borlanic | 0:02dd72d1d465 | 189 | jobs=options.jobs, |
borlanic | 0:02dd72d1d465 | 190 | continue_on_build_fail=options.continue_on_build_fail) |
borlanic | 0:02dd72d1d465 | 191 | |
borlanic | 0:02dd72d1d465 | 192 | if not test_build_success: |
borlanic | 0:02dd72d1d465 | 193 | total_build_success = False |
borlanic | 0:02dd72d1d465 | 194 | print "Failed to build some tests, check build log for details" |
borlanic | 0:02dd72d1d465 | 195 | |
borlanic | 0:02dd72d1d465 | 196 | test_builds.update(test_build) |
borlanic | 0:02dd72d1d465 | 197 | else: |
borlanic | 0:02dd72d1d465 | 198 | total_build_success = False |
borlanic | 0:02dd72d1d465 | 199 | break |
borlanic | 0:02dd72d1d465 | 200 | |
borlanic | 0:02dd72d1d465 | 201 | # If a path to a test spec is provided, write it to a file |
borlanic | 0:02dd72d1d465 | 202 | if options.test_spec: |
borlanic | 0:02dd72d1d465 | 203 | test_spec_data = test_spec_from_test_builds(test_builds) |
borlanic | 0:02dd72d1d465 | 204 | |
borlanic | 0:02dd72d1d465 | 205 | # Create the target dir for the test spec if necessary |
borlanic | 0:02dd72d1d465 | 206 | # mkdir will not create the dir if it already exists |
borlanic | 0:02dd72d1d465 | 207 | test_spec_dir = dirname(options.test_spec) |
borlanic | 0:02dd72d1d465 | 208 | if test_spec_dir: |
borlanic | 0:02dd72d1d465 | 209 | mkdir(test_spec_dir) |
borlanic | 0:02dd72d1d465 | 210 | |
borlanic | 0:02dd72d1d465 | 211 | try: |
borlanic | 0:02dd72d1d465 | 212 | with open(options.test_spec, 'w') as f: |
borlanic | 0:02dd72d1d465 | 213 | f.write(json.dumps(test_spec_data, indent=2)) |
borlanic | 0:02dd72d1d465 | 214 | except IOError, e: |
borlanic | 0:02dd72d1d465 | 215 | print "[ERROR] Error writing test spec to file" |
borlanic | 0:02dd72d1d465 | 216 | print e |
borlanic | 0:02dd72d1d465 | 217 | |
borlanic | 0:02dd72d1d465 | 218 | # If a path to a JUnit build report spec is provided, write it to a file |
borlanic | 0:02dd72d1d465 | 219 | if options.build_report_junit: |
borlanic | 0:02dd72d1d465 | 220 | report_exporter = ReportExporter(ResultExporterType.JUNIT) |
borlanic | 0:02dd72d1d465 | 221 | report_exporter.report_to_file(build_report, options.build_report_junit, test_suite_properties=build_properties) |
borlanic | 0:02dd72d1d465 | 222 | |
borlanic | 0:02dd72d1d465 | 223 | print "\n\nCompleted in: (%.2f)s" % (time() - start) |
borlanic | 0:02dd72d1d465 | 224 | |
borlanic | 0:02dd72d1d465 | 225 | print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build") |
borlanic | 0:02dd72d1d465 | 226 | status = print_report_exporter.report(build_report) |
borlanic | 0:02dd72d1d465 | 227 | |
borlanic | 0:02dd72d1d465 | 228 | if status: |
borlanic | 0:02dd72d1d465 | 229 | sys.exit(0) |
borlanic | 0:02dd72d1d465 | 230 | else: |
borlanic | 0:02dd72d1d465 | 231 | sys.exit(1) |
borlanic | 0:02dd72d1d465 | 232 | |
borlanic | 0:02dd72d1d465 | 233 | except KeyboardInterrupt, e: |
borlanic | 0:02dd72d1d465 | 234 | print "\n[CTRL+c] exit" |
borlanic | 0:02dd72d1d465 | 235 | except Exception,e: |
borlanic | 0:02dd72d1d465 | 236 | import traceback |
borlanic | 0:02dd72d1d465 | 237 | traceback.print_exc(file=sys.stdout) |
borlanic | 0:02dd72d1d465 | 238 | print "[ERROR] %s" % str(e) |
borlanic | 0:02dd72d1d465 | 239 | sys.exit(1) |