nkjnm

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
nitsshukla
Date:
Fri Nov 04 12:06:04 2016 +0000
Revision:
7:3a65ef12ba31
Parent:
1:55a6170b404f
kghj;

Who changed what in which revision?

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