Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
build_test.py
00001 #!/usr/bin/env python 00002 """ 00003 mbed SDK 00004 Copyright (c) 2011-2016 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 00019 import sys 00020 from os import path, remove, rename 00021 import shutil 00022 ROOT = path.abspath(path.join(path.dirname(__file__), "..", "..", "..")) 00023 sys.path.insert(0, ROOT) 00024 import argparse 00025 00026 from tools.export import EXPORTERS 00027 from tools.targets import TARGET_NAMES 00028 from tools.tests import TESTS 00029 from tools.project import setup_project 00030 from tools.project_api import print_results, export_project 00031 from tools.tests import test_name_known, Test 00032 from tools.export.exporters import FailedBuildException, \ 00033 TargetNotSupportedException 00034 from tools.utils import argparse_force_lowercase_type, \ 00035 argparse_force_uppercase_type, argparse_many 00036 00037 00038 class ProgenBuildTest (object): 00039 """Object to encapsulate logic for progen build testing""" 00040 def __init__ (self, desired_ides, mcus, tests): 00041 """ 00042 Initialize an instance of class ProgenBuildTest 00043 Args: 00044 desired_ides: the IDEs you wish to make/build project files for 00045 mcus: the mcus to specify in project files 00046 tests: the test projects to make/build project files from 00047 """ 00048 self.ides = desired_ides 00049 self.mcus = mcus 00050 self.tests = tests 00051 00052 @property 00053 def mcu_ide_pairs (self): 00054 """Yields tuples of valid mcu, ide combinations""" 00055 for mcu in self.mcus : 00056 for ide in self.ides : 00057 if mcu in EXPORTERS[ide].TARGETS: 00058 yield mcu, ide 00059 00060 @staticmethod 00061 def handle_log_files (project_dir, tool, name): 00062 """ 00063 Renames/moves log files 00064 Args: 00065 project_dir: the directory that contains project files 00066 tool: the ide that created the project files 00067 name: the name of the project 00068 clean: a boolean value determining whether to remove the 00069 created project files 00070 """ 00071 log = '' 00072 if tool == 'uvision' or tool == 'uvision5': 00073 log = path.join(project_dir, "build", "build_log.txt") 00074 elif tool == 'iar': 00075 log = path.join(project_dir, 'build_log.txt') 00076 try: 00077 with open(log, 'r') as in_log: 00078 print in_log.read() 00079 log_name = path.join(path.dirname(project_dir), name + "_log.txt") 00080 00081 # check if a log already exists for this platform+test+ide 00082 if path.exists(log_name): 00083 # delete it if so 00084 remove(log_name) 00085 rename(log, log_name) 00086 except IOError: 00087 pass 00088 00089 def generate_and_build (self, clean=False): 00090 """ 00091 Generate the project file and build the project 00092 Args: 00093 clean: a boolean value determining whether to remove the 00094 created project files 00095 00096 Returns: 00097 successes: a list of strings that contain the mcu, ide, test 00098 properties of a successful build test 00099 skips: a list of strings that contain the mcu, ide, test properties 00100 of a skipped test (if the ide does not support mcu) 00101 failures: a list of strings that contain the mcu, ide, test 00102 properties of a failed build test 00103 00104 """ 00105 successes = [] 00106 failures = [] 00107 skips = [] 00108 for mcu, ide in self.mcu_ide_pairs : 00109 for test in self.tests : 00110 export_location, name, src, lib = setup_project(ide, mcu, 00111 program=test) 00112 test_name = Test(test).id 00113 try: 00114 exporter = export_project(src, export_location, mcu, ide, 00115 clean=clean, name=name, 00116 libraries_paths=lib) 00117 exporter.progen_build() 00118 successes.append("%s::%s\t%s" % (mcu, ide, test_name)) 00119 except FailedBuildException: 00120 failures.append("%s::%s\t%s" % (mcu, ide, test_name)) 00121 except TargetNotSupportedException: 00122 skips.append("%s::%s\t%s" % (mcu, ide, test_name)) 00123 00124 ProgenBuildTest.handle_log_files(export_location, ide, name) 00125 if clean: 00126 shutil.rmtree(export_location, ignore_errors=True) 00127 return successes, failures, skips 00128 00129 00130 def main(): 00131 """Entry point""" 00132 toolchainlist = ["iar", "uvision", "uvision5"] 00133 default_tests = [test_name_known("MBED_BLINKY")] 00134 targetnames = TARGET_NAMES 00135 targetnames.sort() 00136 00137 parser = argparse.ArgumentParser(description= 00138 "Test progen builders. Leave any flag off" 00139 " to run with all possible options.") 00140 parser.add_argument("-i", 00141 dest="ides", 00142 default=toolchainlist, 00143 type=argparse_many(argparse_force_lowercase_type( 00144 toolchainlist, "toolchain")), 00145 help="The target IDE: %s"% str(toolchainlist)) 00146 00147 parser.add_argument( 00148 "-p", 00149 type=argparse_many(test_name_known), 00150 dest="programs", 00151 help="The index of the desired test program: [0-%d]" % (len(TESTS) - 1), 00152 default=default_tests) 00153 00154 parser.add_argument("-n", 00155 type=argparse_many(test_name_known), 00156 dest="programs", 00157 help="The name of the desired test program", 00158 default=default_tests) 00159 00160 parser.add_argument( 00161 "-m", "--mcu", 00162 metavar="MCU", 00163 default='LPC1768', 00164 nargs="+", 00165 type=argparse_force_uppercase_type(targetnames, "MCU"), 00166 help="generate project for the given MCU (%s)" % ', '.join(targetnames)) 00167 00168 parser.add_argument("-c", "--clean", 00169 dest="clean", 00170 action="store_true", 00171 help="clean up the exported project files", 00172 default=False) 00173 00174 options = parser.parse_args() 00175 test = ProgenBuildTest(options.ides, options.mcu, options.programs) 00176 successes, failures, skips = test.generate_and_build(clean=options.clean) 00177 print_results(successes, failures, skips) 00178 sys.exit(len(failures)) 00179 00180 if __name__ == "__main__": 00181 main()
Generated on Tue Jul 12 2022 12:28:26 by
1.7.2
