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