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