Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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