BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:fbdae7e6d805 1 # Script to check a new mbed 2 release by compiling a set of specified test apps
borlanic 0:fbdae7e6d805 2 # for all currently supported platforms. Each test app must include an mbed library.
borlanic 0:fbdae7e6d805 3 # This can either be the pre-compiled version 'mbed' or the source version 'mbed-dev'.
borlanic 0:fbdae7e6d805 4 #
borlanic 0:fbdae7e6d805 5 # Setup:
borlanic 0:fbdae7e6d805 6 # 1. Set up your global .hgrc file
borlanic 0:fbdae7e6d805 7 #
borlanic 0:fbdae7e6d805 8 # If you don't already have a .hgrc file in your $HOME directory, create one there.
borlanic 0:fbdae7e6d805 9 # Then add the following section:
borlanic 0:fbdae7e6d805 10 #
borlanic 0:fbdae7e6d805 11 # [auth]
borlanic 0:fbdae7e6d805 12 # x.prefix = *
borlanic 0:fbdae7e6d805 13 # x.username = <put your mbed org username here>
borlanic 0:fbdae7e6d805 14 # x.password = <put your mbed org password here>
borlanic 0:fbdae7e6d805 15 #
borlanic 0:fbdae7e6d805 16 # This has 2 purposes, the first means you don't get prompted for your password
borlanic 0:fbdae7e6d805 17 # whenever you run hg commands on the commandline. The second is that this script
borlanic 0:fbdae7e6d805 18 # reads these details in order to fully automate the Mercurial commands.
borlanic 0:fbdae7e6d805 19 #
borlanic 0:fbdae7e6d805 20 # Edit "check_release.json". This has the following structure:
borlanic 0:fbdae7e6d805 21 #{
borlanic 0:fbdae7e6d805 22 # "config" : {
borlanic 0:fbdae7e6d805 23 # "mbed_repo_path" : "C:/Users/annbri01/Work/Mercurial"
borlanic 0:fbdae7e6d805 24 # },
borlanic 0:fbdae7e6d805 25 # "test_list" : [
borlanic 0:fbdae7e6d805 26 # {
borlanic 0:fbdae7e6d805 27 # "name" : "test_compile_mbed_lib",
borlanic 0:fbdae7e6d805 28 # "lib" : "mbed"
borlanic 0:fbdae7e6d805 29 # },
borlanic 0:fbdae7e6d805 30 # {
borlanic 0:fbdae7e6d805 31 # "name" : "test_compile_mbed_dev",
borlanic 0:fbdae7e6d805 32 # "lib" : "mbed-dev"
borlanic 0:fbdae7e6d805 33 # }
borlanic 0:fbdae7e6d805 34 # ],
borlanic 0:fbdae7e6d805 35 # "target_list" : []
borlanic 0:fbdae7e6d805 36 #}
borlanic 0:fbdae7e6d805 37 #
borlanic 0:fbdae7e6d805 38 # The mbed_repo_path field should be changed to point to where your local
borlanic 0:fbdae7e6d805 39 # working directory is for Mercurial repositories.
borlanic 0:fbdae7e6d805 40 # For each test app you wish to run, add an entry to the test list. The example
borlanic 0:fbdae7e6d805 41 # above has 2 test apps
borlanic 0:fbdae7e6d805 42 # "test_compile_mbed_lib" and "test_compile_mbed_dev"
borlanic 0:fbdae7e6d805 43 # The lib field in each says which type of mbed 2 library the app contains.
borlanic 0:fbdae7e6d805 44 # These test apps MUST be available as repos in the user's online Mercurial area.
borlanic 0:fbdae7e6d805 45 # The target_list allows the user to override the set of targets/platforms used
borlanic 0:fbdae7e6d805 46 # for the compilation.
borlanic 0:fbdae7e6d805 47 # E.g to just compile for 2 targets, K64F and K22F :
borlanic 0:fbdae7e6d805 48 # "target_list" : ["K64F", "K22F"]
borlanic 0:fbdae7e6d805 49 #
borlanic 0:fbdae7e6d805 50 # Run the script from the mbed-os directory as follows:
borlanic 0:fbdae7e6d805 51 # > python tools/check_release.py
borlanic 0:fbdae7e6d805 52 #
borlanic 0:fbdae7e6d805 53 # It will look for local clones of the test app repos. If they don't exist
borlanic 0:fbdae7e6d805 54 # it will clone them. It will then read the latest versions of mbed and mbed-dev
borlanic 0:fbdae7e6d805 55 # (an assumption is made that both of these are already cloned in your Mercurial area).
borlanic 0:fbdae7e6d805 56 # The lib files within the test apps are then updated to the corresponding version in
borlanic 0:fbdae7e6d805 57 # the associated lib itself. The test apps are then committed and pushed back to the users
borlanic 0:fbdae7e6d805 58 # fork.
borlanic 0:fbdae7e6d805 59 # The test apps will then be compiled for all supported targets and a % result output at
borlanic 0:fbdae7e6d805 60 # the end.
borlanic 0:fbdae7e6d805 61 #
borlanic 0:fbdae7e6d805 62 # Uses the online compiler API at https://mbed.org/handbook/Compile-API
borlanic 0:fbdae7e6d805 63 # Based on the example from https://mbed.org/teams/mbed/code/mbed-API-helper/
borlanic 0:fbdae7e6d805 64
borlanic 0:fbdae7e6d805 65
borlanic 0:fbdae7e6d805 66 import os, getpass, sys, json, time, requests, logging
borlanic 0:fbdae7e6d805 67 from os.path import dirname, abspath, basename, join
borlanic 0:fbdae7e6d805 68 import argparse
borlanic 0:fbdae7e6d805 69 import subprocess
borlanic 0:fbdae7e6d805 70 import re
borlanic 0:fbdae7e6d805 71 import hglib
borlanic 0:fbdae7e6d805 72 import argparse
borlanic 0:fbdae7e6d805 73
borlanic 0:fbdae7e6d805 74 # Be sure that the tools directory is in the search path
borlanic 0:fbdae7e6d805 75 ROOT = abspath(join(dirname(__file__), ".."))
borlanic 0:fbdae7e6d805 76 sys.path.insert(0, ROOT)
borlanic 0:fbdae7e6d805 77
borlanic 0:fbdae7e6d805 78 from tools.build_api import get_mbed_official_release
borlanic 0:fbdae7e6d805 79
borlanic 0:fbdae7e6d805 80 OFFICIAL_MBED_LIBRARY_BUILD = get_mbed_official_release('2')
borlanic 0:fbdae7e6d805 81
borlanic 0:fbdae7e6d805 82 def get_compilation_failure(messages):
borlanic 0:fbdae7e6d805 83 """ Reads the json formatted 'messages' and checks for compilation errors.
borlanic 0:fbdae7e6d805 84 If there is a genuine compilation error then there should be a new
borlanic 0:fbdae7e6d805 85 message containing a severity field = Error and an accompanying message
borlanic 0:fbdae7e6d805 86 with the compile error text. Any other combination is considered an
borlanic 0:fbdae7e6d805 87 internal compile engine failure
borlanic 0:fbdae7e6d805 88 Args:
borlanic 0:fbdae7e6d805 89 messages - json formatted text returned by the online compiler API.
borlanic 0:fbdae7e6d805 90
borlanic 0:fbdae7e6d805 91 Returns:
borlanic 0:fbdae7e6d805 92 Either "Error" or "Internal" to indicate an actual compilation error or an
borlanic 0:fbdae7e6d805 93 internal IDE API fault.
borlanic 0:fbdae7e6d805 94
borlanic 0:fbdae7e6d805 95 """
borlanic 0:fbdae7e6d805 96 for m in messages:
borlanic 0:fbdae7e6d805 97 # Get message text if it exists
borlanic 0:fbdae7e6d805 98 try:
borlanic 0:fbdae7e6d805 99 message = m['message']
borlanic 0:fbdae7e6d805 100 message = message + "\n"
borlanic 0:fbdae7e6d805 101 except KeyError:
borlanic 0:fbdae7e6d805 102 # Skip this message as it has no 'message' field
borlanic 0:fbdae7e6d805 103 continue
borlanic 0:fbdae7e6d805 104
borlanic 0:fbdae7e6d805 105 # Get type of message text
borlanic 0:fbdae7e6d805 106 try:
borlanic 0:fbdae7e6d805 107 msg_type = m['type']
borlanic 0:fbdae7e6d805 108 except KeyError:
borlanic 0:fbdae7e6d805 109 # Skip this message as it has no 'type' field
borlanic 0:fbdae7e6d805 110 continue
borlanic 0:fbdae7e6d805 111
borlanic 0:fbdae7e6d805 112 if msg_type == 'error' or msg_type == 'tool_error':
borlanic 0:fbdae7e6d805 113 rel_log.error(message)
borlanic 0:fbdae7e6d805 114 return "Error"
borlanic 0:fbdae7e6d805 115 else:
borlanic 0:fbdae7e6d805 116 rel_log.debug(message)
borlanic 0:fbdae7e6d805 117
borlanic 0:fbdae7e6d805 118 return "Internal"
borlanic 0:fbdae7e6d805 119
borlanic 0:fbdae7e6d805 120 def invoke_api(payload, url, auth, polls, begin="start/"):
borlanic 0:fbdae7e6d805 121 """ Sends an API command request to the online IDE. Waits for a task completed
borlanic 0:fbdae7e6d805 122 response before returning the results.
borlanic 0:fbdae7e6d805 123
borlanic 0:fbdae7e6d805 124 Args:
borlanic 0:fbdae7e6d805 125 payload - Configuration parameters to be passed to the API
borlanic 0:fbdae7e6d805 126 url - THe URL for the online compiler API
borlanic 0:fbdae7e6d805 127 auth - Tuple containing authentication credentials
borlanic 0:fbdae7e6d805 128 polls - Number of times to poll for results
borlanic 0:fbdae7e6d805 129 begin - Default value = "start/", start command to be appended to URL
borlanic 0:fbdae7e6d805 130
borlanic 0:fbdae7e6d805 131 Returns:
borlanic 0:fbdae7e6d805 132 result - True/False indicating the success/failure of the compilation
borlanic 0:fbdae7e6d805 133 fail_type - the failure text if the compilation failed, else None
borlanic 0:fbdae7e6d805 134 """
borlanic 0:fbdae7e6d805 135
borlanic 0:fbdae7e6d805 136 # send task to api
borlanic 0:fbdae7e6d805 137 rel_log.debug(url + begin + "| data: " + str(payload))
borlanic 0:fbdae7e6d805 138 r = requests.post(url + begin, data=payload, auth=auth)
borlanic 0:fbdae7e6d805 139 rel_log.debug(r.request.body)
borlanic 0:fbdae7e6d805 140
borlanic 0:fbdae7e6d805 141 if r.status_code != 200:
borlanic 0:fbdae7e6d805 142 rel_log.error("HTTP code %d reported.", r.status_code)
borlanic 0:fbdae7e6d805 143 return False, "Internal"
borlanic 0:fbdae7e6d805 144
borlanic 0:fbdae7e6d805 145 response = r.json()
borlanic 0:fbdae7e6d805 146 rel_log.debug(response)
borlanic 0:fbdae7e6d805 147 uuid = response['result']['data']['task_id']
borlanic 0:fbdae7e6d805 148 rel_log.debug("Task accepted and given ID: %s", uuid)
borlanic 0:fbdae7e6d805 149 result = False
borlanic 0:fbdae7e6d805 150 fail_type = None
borlanic 0:fbdae7e6d805 151
borlanic 0:fbdae7e6d805 152 # It currently seems to take the onlide IDE API ~30s to process the compile
borlanic 0:fbdae7e6d805 153 # request and provide a response. Set the poll time to half that in case it
borlanic 0:fbdae7e6d805 154 # does manage to compile quicker.
borlanic 0:fbdae7e6d805 155 poll_delay = 15
borlanic 0:fbdae7e6d805 156 rel_log.debug("Running with a poll for response delay of: %ss", poll_delay)
borlanic 0:fbdae7e6d805 157
borlanic 0:fbdae7e6d805 158 # poll for output
borlanic 0:fbdae7e6d805 159 for check in range(polls):
borlanic 0:fbdae7e6d805 160 time.sleep(poll_delay)
borlanic 0:fbdae7e6d805 161
borlanic 0:fbdae7e6d805 162 try:
borlanic 0:fbdae7e6d805 163 r = requests.get(url + "output/%s" % uuid, auth=auth)
borlanic 0:fbdae7e6d805 164
borlanic 0:fbdae7e6d805 165 except ConnectionError:
borlanic 0:fbdae7e6d805 166 return "Internal"
borlanic 0:fbdae7e6d805 167
borlanic 0:fbdae7e6d805 168 response = r.json()
borlanic 0:fbdae7e6d805 169
borlanic 0:fbdae7e6d805 170 data = response['result']['data']
borlanic 0:fbdae7e6d805 171 if data['task_complete']:
borlanic 0:fbdae7e6d805 172 # Task completed. Now determine the result. Should be one of :
borlanic 0:fbdae7e6d805 173 # 1) Successful compilation
borlanic 0:fbdae7e6d805 174 # 2) Failed compilation with an error message
borlanic 0:fbdae7e6d805 175 # 3) Internal failure of the online compiler
borlanic 0:fbdae7e6d805 176 result = bool(data['compilation_success'])
borlanic 0:fbdae7e6d805 177 if result:
borlanic 0:fbdae7e6d805 178 rel_log.info("COMPILATION SUCCESSFUL\n")
borlanic 0:fbdae7e6d805 179 else:
borlanic 0:fbdae7e6d805 180 # Did this fail due to a genuine compilation error or a failue of
borlanic 0:fbdae7e6d805 181 # the api itself ?
borlanic 0:fbdae7e6d805 182 rel_log.info("COMPILATION FAILURE\n")
borlanic 0:fbdae7e6d805 183 fail_type = get_compilation_failure(data['new_messages'])
borlanic 0:fbdae7e6d805 184 break
borlanic 0:fbdae7e6d805 185 else:
borlanic 0:fbdae7e6d805 186 rel_log.info("COMPILATION FAILURE\n")
borlanic 0:fbdae7e6d805 187
borlanic 0:fbdae7e6d805 188 if not result and fail_type == None:
borlanic 0:fbdae7e6d805 189 fail_type = "Internal"
borlanic 0:fbdae7e6d805 190
borlanic 0:fbdae7e6d805 191 return result, fail_type
borlanic 0:fbdae7e6d805 192
borlanic 0:fbdae7e6d805 193
borlanic 0:fbdae7e6d805 194 def build_repo(target, program, user, pw, polls=25,
borlanic 0:fbdae7e6d805 195 url="https://developer.mbed.org/api/v2/tasks/compiler/"):
borlanic 0:fbdae7e6d805 196 """ Wrapper for sending an API command request to the online IDE. Sends a
borlanic 0:fbdae7e6d805 197 build request.
borlanic 0:fbdae7e6d805 198
borlanic 0:fbdae7e6d805 199 Args:
borlanic 0:fbdae7e6d805 200 target - Target to be built
borlanic 0:fbdae7e6d805 201 program - Test program to build
borlanic 0:fbdae7e6d805 202 user - mbed username
borlanic 0:fbdae7e6d805 203 pw - mbed password
borlanic 0:fbdae7e6d805 204 polls - Number of times to poll for results
borlanic 0:fbdae7e6d805 205 url - THe URL for the online compiler API
borlanic 0:fbdae7e6d805 206
borlanic 0:fbdae7e6d805 207 Returns:
borlanic 0:fbdae7e6d805 208 result - True/False indicating the success/failure of the compilation
borlanic 0:fbdae7e6d805 209 fail_type - the failure text if the compilation failed, else None
borlanic 0:fbdae7e6d805 210 """
borlanic 0:fbdae7e6d805 211 payload = {'clean':True, 'target':target, 'program':program}
borlanic 0:fbdae7e6d805 212 auth = (user, pw)
borlanic 0:fbdae7e6d805 213 return invoke_api(payload, url, auth, polls)
borlanic 0:fbdae7e6d805 214
borlanic 0:fbdae7e6d805 215 def run_cmd(command, exit_on_failure=False):
borlanic 0:fbdae7e6d805 216 """ Passes a command to the system and returns a True/False result once the
borlanic 0:fbdae7e6d805 217 command has been executed, indicating success/failure. Commands are passed
borlanic 0:fbdae7e6d805 218 as a list of tokens.
borlanic 0:fbdae7e6d805 219 E.g. The command 'git remote -v' would be passed in as ['git', 'remote', '-v']
borlanic 0:fbdae7e6d805 220
borlanic 0:fbdae7e6d805 221 Args:
borlanic 0:fbdae7e6d805 222 command - system command as a list of tokens
borlanic 0:fbdae7e6d805 223 exit_on_failure - If True exit the program on failure (default = False)
borlanic 0:fbdae7e6d805 224
borlanic 0:fbdae7e6d805 225 Returns:
borlanic 0:fbdae7e6d805 226 result - True/False indicating the success/failure of the command
borlanic 0:fbdae7e6d805 227 """
borlanic 0:fbdae7e6d805 228 rel_log.debug('[Exec] %s', ' '.join(command))
borlanic 0:fbdae7e6d805 229 return_code = subprocess.call(command, shell=True)
borlanic 0:fbdae7e6d805 230
borlanic 0:fbdae7e6d805 231 if return_code:
borlanic 0:fbdae7e6d805 232 rel_log.warning("The command '%s' failed with return code: %s",
borlanic 0:fbdae7e6d805 233 (' '.join(command), return_code))
borlanic 0:fbdae7e6d805 234 if exit_on_failure:
borlanic 0:fbdae7e6d805 235 sys.exit(1)
borlanic 0:fbdae7e6d805 236
borlanic 0:fbdae7e6d805 237 return return_code
borlanic 0:fbdae7e6d805 238
borlanic 0:fbdae7e6d805 239 def run_cmd_with_output(command, exit_on_failure=False):
borlanic 0:fbdae7e6d805 240 """ Passes a command to the system and returns a True/False result once the
borlanic 0:fbdae7e6d805 241 command has been executed, indicating success/failure. If the command was
borlanic 0:fbdae7e6d805 242 successful then the output from the command is returned to the caller.
borlanic 0:fbdae7e6d805 243 Commands are passed as a list of tokens.
borlanic 0:fbdae7e6d805 244 E.g. The command 'git remote -v' would be passed in as ['git', 'remote', '-v']
borlanic 0:fbdae7e6d805 245
borlanic 0:fbdae7e6d805 246 Args:
borlanic 0:fbdae7e6d805 247 command - system command as a list of tokens
borlanic 0:fbdae7e6d805 248 exit_on_failure - If True exit the program on failure (default = False)
borlanic 0:fbdae7e6d805 249
borlanic 0:fbdae7e6d805 250 Returns:
borlanic 0:fbdae7e6d805 251 result - True/False indicating the success/failure of the command
borlanic 0:fbdae7e6d805 252 output - The output of the command if it was successful, else empty string
borlanic 0:fbdae7e6d805 253 """
borlanic 0:fbdae7e6d805 254 rel_log.debug('[Exec] %s', ' '.join(command))
borlanic 0:fbdae7e6d805 255 returncode = 0
borlanic 0:fbdae7e6d805 256 output = ""
borlanic 0:fbdae7e6d805 257 try:
borlanic 0:fbdae7e6d805 258 output = subprocess.check_output(command, shell=True)
borlanic 0:fbdae7e6d805 259 except subprocess.CalledProcessError as e:
borlanic 0:fbdae7e6d805 260 rel_log.warning("The command '%s' failed with return code: %s",
borlanic 0:fbdae7e6d805 261 (' '.join(command), e.returncode))
borlanic 0:fbdae7e6d805 262 returncode = e.returncode
borlanic 0:fbdae7e6d805 263 if exit_on_failure:
borlanic 0:fbdae7e6d805 264 sys.exit(1)
borlanic 0:fbdae7e6d805 265 return returncode, output
borlanic 0:fbdae7e6d805 266
borlanic 0:fbdae7e6d805 267 def upgrade_test_repo(test, user, library, ref, repo_path):
borlanic 0:fbdae7e6d805 268 """ Upgrades a local version of a test repo to the latest version of its
borlanic 0:fbdae7e6d805 269 embedded library.
borlanic 0:fbdae7e6d805 270 If the test repo is not present in the user area specified in the json
borlanic 0:fbdae7e6d805 271 config file, then it will first be cloned.
borlanic 0:fbdae7e6d805 272 Args:
borlanic 0:fbdae7e6d805 273 test - Mercurial test repo name
borlanic 0:fbdae7e6d805 274 user - Mercurial user name
borlanic 0:fbdae7e6d805 275 library - library name
borlanic 0:fbdae7e6d805 276 ref - SHA corresponding to the latest version of the library
borlanic 0:fbdae7e6d805 277 repo_path - path to the user's repo area
borlanic 0:fbdae7e6d805 278
borlanic 0:fbdae7e6d805 279 Returns:
borlanic 0:fbdae7e6d805 280 updated - True if library was updated, False otherwise
borlanic 0:fbdae7e6d805 281 """
borlanic 0:fbdae7e6d805 282 rel_log.info("Updating test repo: '%s' to SHA: %s", test, ref)
borlanic 0:fbdae7e6d805 283 cwd = os.getcwd()
borlanic 0:fbdae7e6d805 284
borlanic 0:fbdae7e6d805 285 repo = "https://" + user + '@developer.mbed.org/users/' + user + '/code/' + test
borlanic 0:fbdae7e6d805 286
borlanic 0:fbdae7e6d805 287 # Clone the repo if it doesn't already exist
borlanic 0:fbdae7e6d805 288 path = abspath(repo_path + '/' + test)
borlanic 0:fbdae7e6d805 289 if not os.path.exists(path):
borlanic 0:fbdae7e6d805 290 rel_log.info("Test repo doesn't exist, cloning...")
borlanic 0:fbdae7e6d805 291 os.chdir(abspath(repo_path))
borlanic 0:fbdae7e6d805 292 clone_cmd = ['hg', 'clone', repo]
borlanic 0:fbdae7e6d805 293 run_cmd(clone_cmd, exit_on_failure=True)
borlanic 0:fbdae7e6d805 294
borlanic 0:fbdae7e6d805 295 os.chdir(path)
borlanic 0:fbdae7e6d805 296
borlanic 0:fbdae7e6d805 297 client = hglib.open(path)
borlanic 0:fbdae7e6d805 298
borlanic 0:fbdae7e6d805 299 lib_file = library + '.lib'
borlanic 0:fbdae7e6d805 300 if os.path.isfile(lib_file):
borlanic 0:fbdae7e6d805 301 # Rename command will fail on some OS's if the target file already exist,
borlanic 0:fbdae7e6d805 302 # so ensure if it does, it is deleted first.
borlanic 0:fbdae7e6d805 303 bak_file = library + '_bak'
borlanic 0:fbdae7e6d805 304 if os.path.isfile(bak_file):
borlanic 0:fbdae7e6d805 305 os.remove(bak_file)
borlanic 0:fbdae7e6d805 306
borlanic 0:fbdae7e6d805 307 os.rename(lib_file, bak_file)
borlanic 0:fbdae7e6d805 308 else:
borlanic 0:fbdae7e6d805 309 rel_log.error("Failure to backup lib file prior to updating.")
borlanic 0:fbdae7e6d805 310 return False
borlanic 0:fbdae7e6d805 311
borlanic 0:fbdae7e6d805 312 # mbed 2 style lib file contains one line with the following format
borlanic 0:fbdae7e6d805 313 # e.g. https://developer.mbed.org/users/<user>/code/mbed-dev/#156823d33999
borlanic 0:fbdae7e6d805 314 exp = 'https://developer.mbed.org/users/' + user + '/code/' + library + '/#[A-Za-z0-9]+'
borlanic 0:fbdae7e6d805 315 lib_re = re.compile(exp)
borlanic 0:fbdae7e6d805 316 updated = False
borlanic 0:fbdae7e6d805 317
borlanic 0:fbdae7e6d805 318 # Scan through mbed-os.lib line by line, looking for lib version and update
borlanic 0:fbdae7e6d805 319 # it if found
borlanic 0:fbdae7e6d805 320 with open(bak_file, 'r') as ip, open(lib_file, 'w') as op:
borlanic 0:fbdae7e6d805 321 for line in ip:
borlanic 0:fbdae7e6d805 322
borlanic 0:fbdae7e6d805 323 opline = line
borlanic 0:fbdae7e6d805 324
borlanic 0:fbdae7e6d805 325 regexp = lib_re.match(line)
borlanic 0:fbdae7e6d805 326 if regexp:
borlanic 0:fbdae7e6d805 327 opline = 'https://developer.mbed.org/users/' + user + '/code/' + library + '/#' + ref
borlanic 0:fbdae7e6d805 328 updated = True
borlanic 0:fbdae7e6d805 329
borlanic 0:fbdae7e6d805 330 op.write(opline)
borlanic 0:fbdae7e6d805 331
borlanic 0:fbdae7e6d805 332 if updated:
borlanic 0:fbdae7e6d805 333
borlanic 0:fbdae7e6d805 334 # Setup the default commit message
borlanic 0:fbdae7e6d805 335 commit_message = '"Updating ' + library + ' to ' + ref + '"'
borlanic 0:fbdae7e6d805 336
borlanic 0:fbdae7e6d805 337 # Setup and run the commit command. Need to use the rawcommand in the hglib
borlanic 0:fbdae7e6d805 338 # for this in order to pass the string value to the -m option. run_cmd using
borlanic 0:fbdae7e6d805 339 # subprocess does not like this syntax.
borlanic 0:fbdae7e6d805 340 try:
borlanic 0:fbdae7e6d805 341 client.rawcommand(['commit','-m '+commit_message, lib_file])
borlanic 0:fbdae7e6d805 342
borlanic 0:fbdae7e6d805 343 cmd = ['hg', 'push', '-f', repo]
borlanic 0:fbdae7e6d805 344 run_cmd(cmd, exit_on_failure=True)
borlanic 0:fbdae7e6d805 345
borlanic 0:fbdae7e6d805 346 except:
borlanic 0:fbdae7e6d805 347 rel_log.info("Lib file already up to date and thus nothing to commit")
borlanic 0:fbdae7e6d805 348
borlanic 0:fbdae7e6d805 349 os.chdir(cwd)
borlanic 0:fbdae7e6d805 350 return updated
borlanic 0:fbdae7e6d805 351
borlanic 0:fbdae7e6d805 352 def get_sha(repo_path, library):
borlanic 0:fbdae7e6d805 353 """ Gets the latest SHA for the library specified. The library is assumed to be
borlanic 0:fbdae7e6d805 354 located at the repo_path. If a SHA cannot be obtained this script will exit.
borlanic 0:fbdae7e6d805 355
borlanic 0:fbdae7e6d805 356 Args:
borlanic 0:fbdae7e6d805 357 library - library name
borlanic 0:fbdae7e6d805 358 repo_path - path to the user's repo area
borlanic 0:fbdae7e6d805 359
borlanic 0:fbdae7e6d805 360 Returns:
borlanic 0:fbdae7e6d805 361 sha - last commit SHA
borlanic 0:fbdae7e6d805 362 """
borlanic 0:fbdae7e6d805 363 cwd = os.getcwd()
borlanic 0:fbdae7e6d805 364 sha = None
borlanic 0:fbdae7e6d805 365 os.chdir(abspath(repo_path + '/' + library))
borlanic 0:fbdae7e6d805 366
borlanic 0:fbdae7e6d805 367 cmd = ['hg', 'log', '-l', '1']
borlanic 0:fbdae7e6d805 368 ret, output = run_cmd_with_output(cmd, exit_on_failure=True)
borlanic 0:fbdae7e6d805 369
borlanic 0:fbdae7e6d805 370 # Output should contain a 4 line string of the form:
borlanic 0:fbdae7e6d805 371 # changeset: 135:176b8275d35d
borlanic 0:fbdae7e6d805 372 # tag: tip
borlanic 0:fbdae7e6d805 373 # user: <>
borlanic 0:fbdae7e6d805 374 # date: Thu Feb 02 16:02:30 2017 +0000
borlanic 0:fbdae7e6d805 375 # summary: Release 135 of the mbed library
borlanic 0:fbdae7e6d805 376 # All we want is the changeset string after version number
borlanic 0:fbdae7e6d805 377
borlanic 0:fbdae7e6d805 378 lines = output.split('\n')
borlanic 0:fbdae7e6d805 379 fields = lines[0].split(':')
borlanic 0:fbdae7e6d805 380 sha = fields[2]
borlanic 0:fbdae7e6d805 381
borlanic 0:fbdae7e6d805 382 os.chdir(cwd)
borlanic 0:fbdae7e6d805 383 return sha
borlanic 0:fbdae7e6d805 384
borlanic 0:fbdae7e6d805 385 def get_latest_library_versions(repo_path):
borlanic 0:fbdae7e6d805 386 """ Returns the latest library versions (SHAs) for 'mbed' and 'mbed-dev'.
borlanic 0:fbdae7e6d805 387 If the SHAs cannot be obtained this script will exit.
borlanic 0:fbdae7e6d805 388
borlanic 0:fbdae7e6d805 389 Args:
borlanic 0:fbdae7e6d805 390 repo_path - path to the user's repo area
borlanic 0:fbdae7e6d805 391
borlanic 0:fbdae7e6d805 392 Returns:
borlanic 0:fbdae7e6d805 393 mbed - last commit SHA for mbed library
borlanic 0:fbdae7e6d805 394 mbed_dev - last commit SHA for mbed_dev library
borlanic 0:fbdae7e6d805 395
borlanic 0:fbdae7e6d805 396 """
borlanic 0:fbdae7e6d805 397
borlanic 0:fbdae7e6d805 398 mbed = get_sha(repo_path, 'mbed')
borlanic 0:fbdae7e6d805 399 mbed_dev = get_sha(repo_path, 'mbed-dev')
borlanic 0:fbdae7e6d805 400
borlanic 0:fbdae7e6d805 401 return mbed, mbed_dev
borlanic 0:fbdae7e6d805 402
borlanic 0:fbdae7e6d805 403 def log_results(lst, title):
borlanic 0:fbdae7e6d805 404 if len(lst) == 0:
borlanic 0:fbdae7e6d805 405 rel_log.info("%s - None", title)
borlanic 0:fbdae7e6d805 406 else:
borlanic 0:fbdae7e6d805 407 for entry in lst:
borlanic 0:fbdae7e6d805 408 rel_log.info("%s - Test: %s, Target: %s", title, entry[0], entry[1])
borlanic 0:fbdae7e6d805 409
borlanic 0:fbdae7e6d805 410
borlanic 0:fbdae7e6d805 411 if __name__ == '__main__':
borlanic 0:fbdae7e6d805 412
borlanic 0:fbdae7e6d805 413 parser = argparse.ArgumentParser(description=__doc__,
borlanic 0:fbdae7e6d805 414 formatter_class=argparse.RawDescriptionHelpFormatter)
borlanic 0:fbdae7e6d805 415 parser.add_argument('-l', '--log-level',
borlanic 0:fbdae7e6d805 416 help="Level for providing logging output",
borlanic 0:fbdae7e6d805 417 default='INFO')
borlanic 0:fbdae7e6d805 418 args = parser.parse_args()
borlanic 0:fbdae7e6d805 419
borlanic 0:fbdae7e6d805 420 default = getattr(logging, 'INFO')
borlanic 0:fbdae7e6d805 421 level = getattr(logging, args.log_level.upper(), default)
borlanic 0:fbdae7e6d805 422
borlanic 0:fbdae7e6d805 423 # Set logging level
borlanic 0:fbdae7e6d805 424 logging.basicConfig(level=level)
borlanic 0:fbdae7e6d805 425 rel_log = logging.getLogger("check-release")
borlanic 0:fbdae7e6d805 426
borlanic 0:fbdae7e6d805 427 # Read configuration data
borlanic 0:fbdae7e6d805 428 with open(os.path.join(os.path.dirname(__file__), "check_release.json")) as config:
borlanic 0:fbdae7e6d805 429 json_data = json.load(config)
borlanic 0:fbdae7e6d805 430
borlanic 0:fbdae7e6d805 431 supported_targets = []
borlanic 0:fbdae7e6d805 432
borlanic 0:fbdae7e6d805 433 if len(json_data["target_list"]) > 0:
borlanic 0:fbdae7e6d805 434 # Compile user supplied subset of targets
borlanic 0:fbdae7e6d805 435 supported_targets = json_data["target_list"]
borlanic 0:fbdae7e6d805 436 else:
borlanic 0:fbdae7e6d805 437 # Get a list of the officially supported mbed-os 2 targets
borlanic 0:fbdae7e6d805 438 for tgt in OFFICIAL_MBED_LIBRARY_BUILD:
borlanic 0:fbdae7e6d805 439 supported_targets.append(tgt[0])
borlanic 0:fbdae7e6d805 440
borlanic 0:fbdae7e6d805 441 ignore_list = []
borlanic 0:fbdae7e6d805 442
borlanic 0:fbdae7e6d805 443 if len(json_data["ignore_list"]) > 0:
borlanic 0:fbdae7e6d805 444 # List of tuples of (test, target) to be ignored in this test
borlanic 0:fbdae7e6d805 445 ignore_list = json_data["ignore_list"]
borlanic 0:fbdae7e6d805 446
borlanic 0:fbdae7e6d805 447 config = json_data["config"]
borlanic 0:fbdae7e6d805 448 test_list = json_data["test_list"]
borlanic 0:fbdae7e6d805 449 repo_path = config["mbed_repo_path"]
borlanic 0:fbdae7e6d805 450 tests = []
borlanic 0:fbdae7e6d805 451
borlanic 0:fbdae7e6d805 452 # get username
borlanic 0:fbdae7e6d805 453 cmd = ['hg', 'config', 'auth.x.username']
borlanic 0:fbdae7e6d805 454 ret, output = run_cmd_with_output(cmd, exit_on_failure=True)
borlanic 0:fbdae7e6d805 455 output = output.split('\n')
borlanic 0:fbdae7e6d805 456 user = output[0]
borlanic 0:fbdae7e6d805 457
borlanic 0:fbdae7e6d805 458 # get password
borlanic 0:fbdae7e6d805 459 cmd = ['hg', 'config', 'auth.x.password']
borlanic 0:fbdae7e6d805 460 ret, output = run_cmd_with_output(cmd, exit_on_failure=True)
borlanic 0:fbdae7e6d805 461 output = output.split('\n')
borlanic 0:fbdae7e6d805 462 password = output[0]
borlanic 0:fbdae7e6d805 463
borlanic 0:fbdae7e6d805 464 mbed, mbed_dev = get_latest_library_versions(repo_path)
borlanic 0:fbdae7e6d805 465
borlanic 0:fbdae7e6d805 466 if not mbed or not mbed_dev:
borlanic 0:fbdae7e6d805 467 rel_log.error("Could not obtain latest versions of library files!!")
borlanic 0:fbdae7e6d805 468 exit(1)
borlanic 0:fbdae7e6d805 469
borlanic 0:fbdae7e6d805 470 rel_log.info("Latest mbed lib version = %s", mbed)
borlanic 0:fbdae7e6d805 471 rel_log.info("Latest mbed-dev lib version = %s", mbed_dev)
borlanic 0:fbdae7e6d805 472
borlanic 0:fbdae7e6d805 473 # First update test repos to latest versions of their embedded libraries
borlanic 0:fbdae7e6d805 474 for test in test_list:
borlanic 0:fbdae7e6d805 475 tests.append(test['name'])
borlanic 0:fbdae7e6d805 476 upgrade_test_repo(test['name'], user, test['lib'],
borlanic 0:fbdae7e6d805 477 mbed if test['lib'] == "mbed" else mbed_dev,
borlanic 0:fbdae7e6d805 478 repo_path)
borlanic 0:fbdae7e6d805 479
borlanic 0:fbdae7e6d805 480 total = len(supported_targets) * len(tests)
borlanic 0:fbdae7e6d805 481 current = 0
borlanic 0:fbdae7e6d805 482 retries = 10
borlanic 0:fbdae7e6d805 483 passes = 0
borlanic 0:fbdae7e6d805 484 failures = []
borlanic 0:fbdae7e6d805 485 skipped = []
borlanic 0:fbdae7e6d805 486
borlanic 0:fbdae7e6d805 487 # Compile each test for each supported target
borlanic 0:fbdae7e6d805 488 for test in tests:
borlanic 0:fbdae7e6d805 489 for target in supported_targets:
borlanic 0:fbdae7e6d805 490
borlanic 0:fbdae7e6d805 491 combo = [test, target]
borlanic 0:fbdae7e6d805 492
borlanic 0:fbdae7e6d805 493 if combo in ignore_list:
borlanic 0:fbdae7e6d805 494 rel_log.info("SKIPPING TEST: %s, TARGET: %s", test, target)
borlanic 0:fbdae7e6d805 495 total -= 1
borlanic 0:fbdae7e6d805 496 skipped.append(combo)
borlanic 0:fbdae7e6d805 497 continue
borlanic 0:fbdae7e6d805 498
borlanic 0:fbdae7e6d805 499 current += 1
borlanic 0:fbdae7e6d805 500 for retry in range(0, retries):
borlanic 0:fbdae7e6d805 501 rel_log.info("COMPILING (%d/%d): TEST %s, TARGET: %s , attempt %u\n", current, total, test, target, retry)
borlanic 0:fbdae7e6d805 502 result, mesg = build_repo(target, test, user, password)
borlanic 0:fbdae7e6d805 503 if not result:
borlanic 0:fbdae7e6d805 504 if mesg == 'Internal':
borlanic 0:fbdae7e6d805 505 # Internal compiler error thus retry
borlanic 0:fbdae7e6d805 506 continue
borlanic 0:fbdae7e6d805 507 else:
borlanic 0:fbdae7e6d805 508 # Actual error thus move on to next compilation
borlanic 0:fbdae7e6d805 509 failures.append(combo)
borlanic 0:fbdae7e6d805 510 break
borlanic 0:fbdae7e6d805 511
borlanic 0:fbdae7e6d805 512 passes += (int)(result)
borlanic 0:fbdae7e6d805 513 break
borlanic 0:fbdae7e6d805 514 else:
borlanic 0:fbdae7e6d805 515 rel_log.error("Compilation failed due to internal errors.")
borlanic 0:fbdae7e6d805 516 rel_log.error("Skipping test/target combination.")
borlanic 0:fbdae7e6d805 517 total -= 1
borlanic 0:fbdae7e6d805 518 skipped.append(combo)
borlanic 0:fbdae7e6d805 519
borlanic 0:fbdae7e6d805 520 rel_log.info(" SUMMARY OF COMPILATION RESULTS")
borlanic 0:fbdae7e6d805 521 rel_log.info(" ------------------------------")
borlanic 0:fbdae7e6d805 522 rel_log.info(" NUMBER OF TEST APPS: %d, NUMBER OF TARGETS: %d",
borlanic 0:fbdae7e6d805 523 len(tests), len(supported_targets))
borlanic 0:fbdae7e6d805 524 log_results(failures, " FAILED")
borlanic 0:fbdae7e6d805 525 log_results(skipped, " SKIPPED")
borlanic 0:fbdae7e6d805 526
borlanic 0:fbdae7e6d805 527 # Output a % pass rate, indicate a failure if not 100% successful
borlanic 0:fbdae7e6d805 528 pass_rate = (float(passes) / float(total)) * 100.0
borlanic 0:fbdae7e6d805 529 rel_log.info(" PASS RATE %.1f %%\n", pass_rate)
borlanic 0:fbdae7e6d805 530 sys.exit(not (pass_rate == 100))