Script to check a new SDK release by using the online compiler API to compile a simple program against various targets.
check_release.py
00001 # Script to check a new SKD release 00002 # Compiles a simple 'blinky' example for as many platforms as possible 00003 # Reports errors or success 00004 # Uses the online compiler API at https://mbed.org/handbook/Compile-API 00005 # Based on the example from https://mbed.org/teams/mbed/code/mbed-API-helper/ 00006 00007 ################################################################################ 00008 # Configuration section 00009 00010 # mbed_repo_path (optional): path to a github clone of the mbed repo. If found, 00011 # build_release.py in that repo will be used for the list of targets to build. 00012 # If not specified, target_mapping (below) will be used instead. 00013 # mbed_test_project_repo: repository of the program used for testing compilation 00014 # mbed_org_user: username for mbed.org 00015 # mbed_org_password (optional): password for 'mbed_org_user' 00016 00017 mbed_repo_path = "c:/work/mbed/github" 00018 mbed_org_user = "bogdanm" 00019 mbed_test_project_repo = "https://mbed.org/users/bogdanm/code/test_new_lib_mylib" 00020 ################################################################################ 00021 00022 from os.path import abspath, join, dirname 00023 import os, getpass, sys, json, time, requests, logging 00024 00025 # Mapping between target name in offline build system and target name in online 00026 # build system. This really shouldn't be needed. 00027 target_mapping = { 00028 'LPC11U24': 'mbed-LPC11U24', 00029 'LPC1768': 'mbed-LPC1768', 00030 'UBLOX_C027': 'u-blox-C027', 00031 'ARCH_PRO': 'Seeeduino-Arch-Pro', 00032 'LPC2368': 'mbed-LPC2368', 00033 'LPC812': 'NXP-LPC800-MAX', 00034 'LPC1347': 'DipCortex-M3', 00035 'LPC4088': 'EA-LPC4088', 00036 'LPC1114': 'LPC1114FN28', 00037 'LPC11U35_401': 'EA-LPC11U35', 00038 'LPC11U35_501': 'TG-LPC11U35-501', 00039 'LPC1549': 'LPCXpresso1549', 00040 'XADOW_M0': 'Seeed-Xadow-M0', 00041 'ARCH_GPRS': 'Seeed-Arch-GPRS', 00042 'KL05Z': 'FRDM-KL05Z', 00043 'KL25Z': 'KL25Z', 00044 'KL46Z': 'FRDM-KL46Z', 00045 'K64F': 'FRDM-K64F', 00046 'K20D50M': 'FRDM-K20D50M', 00047 'NUCLEO_F030R8': 'ST-Nucleo-F030R8', 00048 'NUCLEO_F072RB': 'ST-Nucleo-F072RB', 00049 'NUCLEO_F103RB': 'ST-Nucleo-F103RB', 00050 'NUCLEO_F302R8': 'ST-Nucleo-F302R8', 00051 'NUCLEO_F334R8': 'ST-Nucleo-F334R8', 00052 'NUCLEO_F401RE': 'ST-Nucleo-F401RE', 00053 'NUCLEO_F411RE': 'ST-Nucleo-F411RE', 00054 'NUCLEO_L053R8': 'ST-Nucleo-L053R8', 00055 'NUCLEO_L152RE': 'ST-Nucleo-L152RE', 00056 'NRF51822': 'Nordic-nRF51822', 00057 'HRM1017': 'mbed-HRM1017', 00058 'ARCH_BLE': 'Seeed-Arch-BLE', 00059 'RBLAB_NRF51822': 'RedBearLab-nRF51822', 00060 'LPC11U68': 'LPCXpresso11U68', 00061 'GHI_MBUINO': 'Outrageous-Circuits-mBuino', 00062 } 00063 00064 reverse_target_mapping = dict([(target_mapping[k], k) for k in target_mapping.keys()]) 00065 00066 # Get list of targets to build from build_release.py 00067 # And map the target names to the ones used in the online build system 00068 def get_target_list(): 00069 offline_list, online_list, skipped = [e[0] for e in OFFICIAL_MBED_LIBRARY_BUILD], [], [] 00070 for t in offline_list: 00071 if target_mapping.has_key(t): 00072 online_list.append(target_mapping[t]) 00073 else: 00074 skipped.append(t) 00075 logging.warn("Target '%s' not found" % t) 00076 return online_list, skipped 00077 00078 # Compile the test project for the given target 00079 def compile_for_target(target): 00080 payload = {'clean': False, 'platform': target, 'repo': mbed_test_project_repo} 00081 auth = (mbed_org_user, mbed_org_password) 00082 r = requests.post("https://mbed.org/api/v2/tasks/compiler/start/", data = payload, auth = auth) 00083 logging.debug("%s" % r.content) 00084 if r.status_code != 200: 00085 if r.content == "Authorization Required": 00086 return False, "invalid username/password" 00087 else: 00088 return False, "Error while talking to the mbed API" 00089 uuid = json.loads(r.content)['result']['data']['task_id'] 00090 logging.debug("Task accepted and given ID: %s" % uuid) 00091 success, errors = False, [] 00092 # Poll for output 00093 for check in range(0, 40): 00094 logging.debug("Checking for output: cycle %s" % check) 00095 time.sleep(2) 00096 r = requests.get("https://mbed.org/api/v2/tasks/compiler/output/%s" % uuid, auth = auth) 00097 logging.debug(r.content) 00098 response = json.loads(r.content) 00099 messages = response['result']['data']['new_messages'] 00100 for message in messages: 00101 if message.get('severity', False) == 'error': 00102 errors.append({"file": message["file"], "error": message["message"]}) 00103 elif message.get('type', False) == 'tool_error': 00104 errors.append({"file": "", "error": message["message"]}) 00105 if response['result']['data']['task_complete']: 00106 logging.info("Task completed.") 00107 success = response['result']['data']['compilation_success'] 00108 logging.info("Compile success: %s" % success) 00109 break 00110 else: 00111 errors = "Timeout" 00112 return success, errors 00113 00114 00115 if '-d' in sys.argv: 00116 logging.basicConfig(level = logging.DEBUG) 00117 sys.argv.remove('-d') 00118 else: 00119 logging.basicConfig(level = logging.WARN) 00120 00121 # Try to get list of targets to build for from build_release.py 00122 if len(sys.argv) > 1: 00123 targets, skipped = sys.argv[1:], [] 00124 else: 00125 try: 00126 import sys 00127 sys.path.insert(0, mbed_repo_path) 00128 from workspace_tools.build_release import OFFICIAL_MBED_LIBRARY_BUILD 00129 logging.info("Got target list from build_release.py") 00130 targets, skipped = get_target_list() 00131 except: 00132 logging.info("build_release.py not found, will try to build all known targets") 00133 targets, skipped = target_mapping.values(), [] 00134 00135 # Get password once 00136 try: 00137 mbed_org_password 00138 except: 00139 mbed_org_password = getpass.getpass("Password for '%s': " % mbed_org_user) 00140 00141 if not mbed_test_project_repo.endswith('/'): 00142 mbed_test_project_repo = mbed_test_project_repo + '/' 00143 ok, failed = [], [] 00144 00145 for t in targets: 00146 sys.stdout.write("Compiling for target '%s' (%s) ... " % (t, reverse_target_mapping[t])) 00147 sys.stdout.flush() 00148 res, errors = compile_for_target(t) 00149 if res: 00150 print "OK" 00151 ok.append(t) 00152 else: 00153 if type(errors) == type([]) and errors: 00154 print "BUILD ERROR!" 00155 for e in errors: 00156 print " '%s': %s" % (e["file"], e["error"]) 00157 else: 00158 print "ERROR: '%s'" % errors 00159 failed.append(t) 00160 00161 print "Compiled OK : " + (", ".join(ok) if ok else "none") 00162 print "Compilation errors: " + (", ".join(failed) if failed else "none") 00163 print "Skipped : " + (", ".join(skipped) if skipped else "none")
Generated on Wed Jul 13 2022 02:15:18 by 1.7.2