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