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 from shutil import copy
bryantaylor 0:eafc3fd41f75 24
bryantaylor 0:eafc3fd41f75 25 # Be sure that the tools directory is in the search path
bryantaylor 0:eafc3fd41f75 26 ROOT = abspath(join(dirname(__file__), ".."))
bryantaylor 0:eafc3fd41f75 27 sys.path.insert(0, ROOT)
bryantaylor 0:eafc3fd41f75 28
bryantaylor 0:eafc3fd41f75 29 from tools.build_api import build_mbed_libs
bryantaylor 0:eafc3fd41f75 30 from tools.build_api import write_build_report
bryantaylor 0:eafc3fd41f75 31 from tools.build_api import get_mbed_official_release
bryantaylor 0:eafc3fd41f75 32 from tools.targets import TARGET_MAP, TARGET_NAMES
bryantaylor 0:eafc3fd41f75 33 from tools.test_exporters import ReportExporter, ResultExporterType
bryantaylor 0:eafc3fd41f75 34 from tools.test_api import SingleTestRunner
bryantaylor 0:eafc3fd41f75 35 from tools.test_api import singletest_in_cli_mode
bryantaylor 0:eafc3fd41f75 36 from tools.paths import TEST_DIR, MBED_LIBRARIES
bryantaylor 0:eafc3fd41f75 37 from tools.tests import TEST_MAP
bryantaylor 0:eafc3fd41f75 38
bryantaylor 0:eafc3fd41f75 39 OFFICIAL_MBED_LIBRARY_BUILD = get_mbed_official_release('2')
bryantaylor 0:eafc3fd41f75 40
bryantaylor 0:eafc3fd41f75 41 if __name__ == '__main__':
bryantaylor 0:eafc3fd41f75 42 parser = OptionParser()
bryantaylor 0:eafc3fd41f75 43 parser.add_option('-o', '--official', dest="official_only", default=False, action="store_true",
bryantaylor 0:eafc3fd41f75 44 help="Build using only the official toolchain for each target")
bryantaylor 0:eafc3fd41f75 45 parser.add_option("-j", "--jobs", type="int", dest="jobs",
bryantaylor 0:eafc3fd41f75 46 default=1, help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs")
bryantaylor 0:eafc3fd41f75 47 parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
bryantaylor 0:eafc3fd41f75 48 default=False, help="Verbose diagnostic output")
bryantaylor 0:eafc3fd41f75 49 parser.add_option("-t", "--toolchains", dest="toolchains", help="Use toolchains names separated by comma")
bryantaylor 0:eafc3fd41f75 50
bryantaylor 0:eafc3fd41f75 51 parser.add_option("-p", "--platforms", dest="platforms", default="", help="Build only for the platform namesseparated by comma")
bryantaylor 0:eafc3fd41f75 52
bryantaylor 0:eafc3fd41f75 53 parser.add_option("-L", "--list-config", action="store_true", dest="list_config",
bryantaylor 0:eafc3fd41f75 54 default=False, help="List the platforms and toolchains in the release in JSON")
bryantaylor 0:eafc3fd41f75 55
bryantaylor 0:eafc3fd41f75 56 parser.add_option("", "--report-build", dest="report_build_file_name", help="Output the build results to an junit xml file")
bryantaylor 0:eafc3fd41f75 57
bryantaylor 0:eafc3fd41f75 58 parser.add_option("", "--build-tests", dest="build_tests", help="Build all tests in the given directories (relative to /libraries/tests)")
bryantaylor 0:eafc3fd41f75 59
bryantaylor 0:eafc3fd41f75 60
bryantaylor 0:eafc3fd41f75 61 options, args = parser.parse_args()
bryantaylor 0:eafc3fd41f75 62
bryantaylor 0:eafc3fd41f75 63
bryantaylor 0:eafc3fd41f75 64
bryantaylor 0:eafc3fd41f75 65 if options.list_config:
bryantaylor 0:eafc3fd41f75 66 print json.dumps(OFFICIAL_MBED_LIBRARY_BUILD, indent=4)
bryantaylor 0:eafc3fd41f75 67 sys.exit()
bryantaylor 0:eafc3fd41f75 68
bryantaylor 0:eafc3fd41f75 69 start = time()
bryantaylor 0:eafc3fd41f75 70 build_report = {}
bryantaylor 0:eafc3fd41f75 71 build_properties = {}
bryantaylor 0:eafc3fd41f75 72
bryantaylor 0:eafc3fd41f75 73 platforms = None
bryantaylor 0:eafc3fd41f75 74 if options.platforms != "":
bryantaylor 0:eafc3fd41f75 75 platforms = set(options.platforms.split(","))
bryantaylor 0:eafc3fd41f75 76
bryantaylor 0:eafc3fd41f75 77 if options.build_tests:
bryantaylor 0:eafc3fd41f75 78 # Get all paths
bryantaylor 0:eafc3fd41f75 79 directories = options.build_tests.split(',')
bryantaylor 0:eafc3fd41f75 80 for i in range(len(directories)):
bryantaylor 0:eafc3fd41f75 81 directories[i] = normpath(join(TEST_DIR, directories[i]))
bryantaylor 0:eafc3fd41f75 82
bryantaylor 0:eafc3fd41f75 83 test_names = []
bryantaylor 0:eafc3fd41f75 84
bryantaylor 0:eafc3fd41f75 85 for test_id in TEST_MAP.keys():
bryantaylor 0:eafc3fd41f75 86 # Prevents tests with multiple source dirs from being checked
bryantaylor 0:eafc3fd41f75 87 if isinstance( TEST_MAP[test_id].source_dir, basestring):
bryantaylor 0:eafc3fd41f75 88 test_path = normpath(TEST_MAP[test_id].source_dir)
bryantaylor 0:eafc3fd41f75 89 for directory in directories:
bryantaylor 0:eafc3fd41f75 90 if directory in test_path:
bryantaylor 0:eafc3fd41f75 91 test_names.append(test_id)
bryantaylor 0:eafc3fd41f75 92
bryantaylor 0:eafc3fd41f75 93 mut_counter = 1
bryantaylor 0:eafc3fd41f75 94 mut = {}
bryantaylor 0:eafc3fd41f75 95 test_spec = {
bryantaylor 0:eafc3fd41f75 96 "targets": {}
bryantaylor 0:eafc3fd41f75 97 }
bryantaylor 0:eafc3fd41f75 98
bryantaylor 0:eafc3fd41f75 99 if options.toolchains:
bryantaylor 0:eafc3fd41f75 100 print "Only building using the following toolchains: %s" % (options.toolchains)
bryantaylor 0:eafc3fd41f75 101
bryantaylor 0:eafc3fd41f75 102 for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD:
bryantaylor 0:eafc3fd41f75 103 toolchains = None
bryantaylor 0:eafc3fd41f75 104 if platforms is not None and not target_name in platforms:
bryantaylor 0:eafc3fd41f75 105 print("Excluding %s from release" % target_name)
bryantaylor 0:eafc3fd41f75 106 continue
bryantaylor 0:eafc3fd41f75 107
bryantaylor 0:eafc3fd41f75 108 if target_name not in TARGET_NAMES:
bryantaylor 0:eafc3fd41f75 109 print "Target '%s' is not a valid target. Excluding from release"
bryantaylor 0:eafc3fd41f75 110 continue
bryantaylor 0:eafc3fd41f75 111
bryantaylor 0:eafc3fd41f75 112 if options.official_only:
bryantaylor 0:eafc3fd41f75 113 toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),)
bryantaylor 0:eafc3fd41f75 114 else:
bryantaylor 0:eafc3fd41f75 115 toolchains = toolchain_list
bryantaylor 0:eafc3fd41f75 116
bryantaylor 0:eafc3fd41f75 117 if options.toolchains:
bryantaylor 0:eafc3fd41f75 118 toolchainSet = set(toolchains)
bryantaylor 0:eafc3fd41f75 119 toolchains = toolchainSet.intersection(set((options.toolchains).split(',')))
bryantaylor 0:eafc3fd41f75 120
bryantaylor 0:eafc3fd41f75 121 mut[str(mut_counter)] = {
bryantaylor 0:eafc3fd41f75 122 "mcu": target_name
bryantaylor 0:eafc3fd41f75 123 }
bryantaylor 0:eafc3fd41f75 124
bryantaylor 0:eafc3fd41f75 125 mut_counter += 1
bryantaylor 0:eafc3fd41f75 126
bryantaylor 0:eafc3fd41f75 127 test_spec["targets"][target_name] = toolchains
bryantaylor 0:eafc3fd41f75 128
bryantaylor 0:eafc3fd41f75 129 single_test = SingleTestRunner(_muts=mut,
bryantaylor 0:eafc3fd41f75 130 _opts_report_build_file_name=options.report_build_file_name,
bryantaylor 0:eafc3fd41f75 131 _test_spec=test_spec,
bryantaylor 0:eafc3fd41f75 132 _opts_test_by_names=",".join(test_names),
bryantaylor 0:eafc3fd41f75 133 _opts_verbose=options.verbose,
bryantaylor 0:eafc3fd41f75 134 _opts_only_build_tests=True,
bryantaylor 0:eafc3fd41f75 135 _opts_suppress_summary=True,
bryantaylor 0:eafc3fd41f75 136 _opts_jobs=options.jobs,
bryantaylor 0:eafc3fd41f75 137 _opts_include_non_automated=True,
bryantaylor 0:eafc3fd41f75 138 _opts_build_report=build_report,
bryantaylor 0:eafc3fd41f75 139 _opts_build_properties=build_properties)
bryantaylor 0:eafc3fd41f75 140 # Runs test suite in CLI mode
bryantaylor 0:eafc3fd41f75 141 test_summary, shuffle_seed, test_summary_ext, test_suite_properties_ext, new_build_report, new_build_properties = single_test.execute()
bryantaylor 0:eafc3fd41f75 142 else:
bryantaylor 0:eafc3fd41f75 143 for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD:
bryantaylor 0:eafc3fd41f75 144 if platforms is not None and not target_name in platforms:
bryantaylor 0:eafc3fd41f75 145 print("Excluding %s from release" % target_name)
bryantaylor 0:eafc3fd41f75 146 continue
bryantaylor 0:eafc3fd41f75 147
bryantaylor 0:eafc3fd41f75 148 if target_name not in TARGET_NAMES:
bryantaylor 0:eafc3fd41f75 149 print "Target '%s' is not a valid target. Excluding from release"
bryantaylor 0:eafc3fd41f75 150 continue
bryantaylor 0:eafc3fd41f75 151
bryantaylor 0:eafc3fd41f75 152 if options.official_only:
bryantaylor 0:eafc3fd41f75 153 toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),)
bryantaylor 0:eafc3fd41f75 154 else:
bryantaylor 0:eafc3fd41f75 155 toolchains = toolchain_list
bryantaylor 0:eafc3fd41f75 156
bryantaylor 0:eafc3fd41f75 157 if options.toolchains:
bryantaylor 0:eafc3fd41f75 158 print "Only building using the following toolchains: %s" % (options.toolchains)
bryantaylor 0:eafc3fd41f75 159 toolchainSet = set(toolchains)
bryantaylor 0:eafc3fd41f75 160 toolchains = toolchainSet.intersection(set((options.toolchains).split(',')))
bryantaylor 0:eafc3fd41f75 161
bryantaylor 0:eafc3fd41f75 162 for toolchain in toolchains:
bryantaylor 0:eafc3fd41f75 163 id = "%s::%s" % (target_name, toolchain)
bryantaylor 0:eafc3fd41f75 164
bryantaylor 0:eafc3fd41f75 165 try:
bryantaylor 0:eafc3fd41f75 166 built_mbed_lib = build_mbed_libs(TARGET_MAP[target_name], toolchain, verbose=options.verbose, jobs=options.jobs, report=build_report, properties=build_properties)
bryantaylor 0:eafc3fd41f75 167
bryantaylor 0:eafc3fd41f75 168 except Exception, e:
bryantaylor 0:eafc3fd41f75 169 print str(e)
bryantaylor 0:eafc3fd41f75 170
bryantaylor 0:eafc3fd41f75 171 # copy targets.json file as part of the release
bryantaylor 0:eafc3fd41f75 172 copy(join(dirname(abspath(__file__)), '..', 'hal', 'targets.json'), MBED_LIBRARIES)
bryantaylor 0:eafc3fd41f75 173
bryantaylor 0:eafc3fd41f75 174 # Write summary of the builds
bryantaylor 0:eafc3fd41f75 175 if options.report_build_file_name:
bryantaylor 0:eafc3fd41f75 176 file_report_exporter = ReportExporter(ResultExporterType.JUNIT, package="build")
bryantaylor 0:eafc3fd41f75 177 file_report_exporter.report_to_file(build_report, options.report_build_file_name, test_suite_properties=build_properties)
bryantaylor 0:eafc3fd41f75 178
bryantaylor 0:eafc3fd41f75 179 print "\n\nCompleted in: (%.2f)s" % (time() - start)
bryantaylor 0:eafc3fd41f75 180
bryantaylor 0:eafc3fd41f75 181 print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")
bryantaylor 0:eafc3fd41f75 182 status = print_report_exporter.report(build_report)
bryantaylor 0:eafc3fd41f75 183
bryantaylor 0:eafc3fd41f75 184 if not status:
bryantaylor 0:eafc3fd41f75 185 sys.exit(1)