joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers build_release.py Source File

build_release.py

00001 #! /usr/bin/env python
00002 """
00003 mbed SDK
00004 Copyright (c) 2011-2013 ARM Limited
00005 
00006 Licensed under the Apache License, Version 2.0 (the "License");
00007 you may not use this file except in compliance with the License.
00008 You may obtain a copy of the License at
00009 
00010     http://www.apache.org/licenses/LICENSE-2.0
00011 
00012 Unless required by applicable law or agreed to in writing, software
00013 distributed under the License is distributed on an "AS IS" BASIS,
00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 See the License for the specific language governing permissions and
00016 limitations under the License.
00017 """
00018 import sys
00019 from time import time
00020 from os.path import join, abspath, dirname, normpath
00021 from optparse import OptionParser
00022 import json
00023 from shutil import copy
00024 
00025 # Be sure that the tools directory is in the search path
00026 ROOT = abspath(join(dirname(__file__), ".."))
00027 sys.path.insert(0, ROOT)
00028 
00029 from tools.build_api import build_mbed_libs
00030 from tools.build_api import write_build_report
00031 from tools.build_api import get_mbed_official_release
00032 from tools.targets import TARGET_MAP, TARGET_NAMES
00033 from tools.test_exporters import ReportExporter, ResultExporterType
00034 from tools.test_api import SingleTestRunner
00035 from tools.test_api import singletest_in_cli_mode
00036 from tools.paths import TEST_DIR, MBED_LIBRARIES
00037 from tools.tests import TEST_MAP
00038 
00039 OFFICIAL_MBED_LIBRARY_BUILD = get_mbed_official_release('2')
00040 
00041 if __name__ == '__main__':
00042     parser = OptionParser()
00043     parser.add_option('-o', '--official', dest="official_only", default=False, action="store_true",
00044                       help="Build using only the official toolchain for each target")
00045     parser.add_option("-j", "--jobs", type="int", dest="jobs",
00046                       default=1, help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs")
00047     parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
00048                       default=False, help="Verbose diagnostic output")
00049     parser.add_option("-t", "--toolchains", dest="toolchains", help="Use toolchains names separated by comma")
00050 
00051     parser.add_option("-p", "--platforms", dest="platforms", default="", help="Build only for the platform namesseparated by comma")
00052 
00053     parser.add_option("-L", "--list-config", action="store_true", dest="list_config",
00054                       default=False, help="List the platforms and toolchains in the release in JSON")
00055 
00056     parser.add_option("", "--report-build", dest="report_build_file_name", help="Output the build results to an junit xml file")
00057 
00058     parser.add_option("", "--build-tests", dest="build_tests", help="Build all tests in the given directories (relative to /libraries/tests)")
00059 
00060 
00061     options, args = parser.parse_args()
00062 
00063 
00064 
00065     if options.list_config:
00066         print json.dumps(OFFICIAL_MBED_LIBRARY_BUILD, indent=4)
00067         sys.exit()
00068 
00069     start = time()
00070     build_report = {}
00071     build_properties = {}
00072 
00073     platforms = None
00074     if options.platforms != "":
00075         platforms = set(options.platforms.split(","))
00076 
00077     if options.build_tests:
00078         # Get all paths
00079         directories = options.build_tests.split(',')
00080         for i in range(len(directories)):
00081             directories[i] = normpath(join(TEST_DIR, directories[i]))
00082 
00083         test_names = []
00084 
00085         for test_id in TEST_MAP.keys():
00086             # Prevents tests with multiple source dirs from being checked
00087             if isinstance( TEST_MAP[test_id].source_dir, basestring):
00088                 test_path = normpath(TEST_MAP[test_id].source_dir)
00089                 for directory in directories:
00090                     if directory in test_path:
00091                         test_names.append(test_id)
00092 
00093         mut_counter = 1
00094         mut = {}
00095         test_spec = {
00096             "targets": {}
00097         }
00098 
00099         if options.toolchains:
00100             print "Only building using the following toolchains: %s" % (options.toolchains)
00101 
00102         for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD:
00103             toolchains = None
00104             if platforms is not None and not target_name in platforms:
00105                 print("Excluding %s from release" % target_name)
00106                 continue
00107 
00108             if target_name not in TARGET_NAMES:
00109                 print "Target '%s' is not a valid target. Excluding from release"
00110                 continue
00111 
00112             if options.official_only:
00113                 toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),)
00114             else:
00115                 toolchains = toolchain_list
00116 
00117             if options.toolchains:
00118                 toolchainSet = set(toolchains)
00119                 toolchains = toolchainSet.intersection(set((options.toolchains).split(',')))
00120 
00121             mut[str(mut_counter)] = {
00122                 "mcu": target_name
00123             }
00124 
00125             mut_counter += 1
00126 
00127             test_spec["targets"][target_name] = toolchains
00128 
00129         single_test = SingleTestRunner(_muts=mut,
00130                                        _opts_report_build_file_name=options.report_build_file_name,
00131                                        _test_spec=test_spec,
00132                                        _opts_test_by_names=",".join(test_names),
00133                                        _opts_verbose=options.verbose,
00134                                        _opts_only_build_tests=True,
00135                                        _opts_suppress_summary=True,
00136                                        _opts_jobs=options.jobs,
00137                                        _opts_include_non_automated=True,
00138                                        _opts_build_report=build_report,
00139                                        _opts_build_properties=build_properties)
00140         # Runs test suite in CLI mode
00141         test_summary, shuffle_seed, test_summary_ext, test_suite_properties_ext, new_build_report, new_build_properties = single_test.execute()
00142     else:
00143         for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD:
00144             if platforms is not None and not target_name in platforms:
00145                 print("Excluding %s from release" % target_name)
00146                 continue
00147 
00148             if target_name not in TARGET_NAMES:
00149                 print "Target '%s' is not a valid target. Excluding from release"
00150                 continue
00151 
00152             if options.official_only:
00153                 toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),)
00154             else:
00155                 toolchains = toolchain_list
00156 
00157             if options.toolchains:
00158                 print "Only building using the following toolchains: %s" % (options.toolchains)
00159                 toolchainSet = set(toolchains)
00160                 toolchains = toolchainSet.intersection(set((options.toolchains).split(',')))
00161 
00162             for toolchain in toolchains:
00163                 id = "%s::%s" % (target_name, toolchain)
00164 
00165                 try:
00166                     built_mbed_lib = build_mbed_libs(TARGET_MAP[target_name], toolchain, verbose=options.verbose, jobs=options.jobs, report=build_report, properties=build_properties)
00167 
00168                 except Exception, e:
00169                     print str(e)
00170 
00171     # copy targets.json file as part of the release
00172     copy(join(dirname(abspath(__file__)), '..', 'hal', 'targets.json'), MBED_LIBRARIES)
00173 
00174     # Write summary of the builds
00175     if options.report_build_file_name:
00176         file_report_exporter = ReportExporter(ResultExporterType.JUNIT, package="build")
00177         file_report_exporter.report_to_file(build_report, options.report_build_file_name, test_suite_properties=build_properties)
00178 
00179     print "\n\nCompleted in: (%.2f)s" % (time() - start)
00180 
00181     print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")
00182     status = print_report_exporter.report(build_report)
00183 
00184     if not status:
00185         sys.exit(1)