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