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