mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:f782d9c66c49 1 """ Import and bulid a bunch of example programs
dkato 0:f782d9c66c49 2
dkato 0:f782d9c66c49 3 This library includes functions that are shared between the examples.py and
dkato 0:f782d9c66c49 4 the update.py modules.
dkato 0:f782d9c66c49 5
dkato 0:f782d9c66c49 6 """
dkato 0:f782d9c66c49 7 import os
dkato 0:f782d9c66c49 8 from os.path import dirname, abspath, basename
dkato 0:f782d9c66c49 9 import os.path
dkato 0:f782d9c66c49 10 import sys
dkato 0:f782d9c66c49 11 import subprocess
dkato 0:f782d9c66c49 12 from shutil import rmtree
dkato 0:f782d9c66c49 13 from sets import Set
dkato 0:f782d9c66c49 14
dkato 0:f782d9c66c49 15 ROOT = abspath(dirname(dirname(dirname(dirname(__file__)))))
dkato 0:f782d9c66c49 16 sys.path.insert(0, ROOT)
dkato 0:f782d9c66c49 17
dkato 0:f782d9c66c49 18 from tools.build_api import get_mbed_official_release
dkato 0:f782d9c66c49 19 from tools.targets import TARGET_MAP
dkato 0:f782d9c66c49 20 from tools.export import EXPORTERS
dkato 0:f782d9c66c49 21
dkato 0:f782d9c66c49 22 SUPPORTED_TOOLCHAINS = ["ARM", "IAR", "GCC_ARM"]
dkato 0:f782d9c66c49 23 SUPPORTED_IDES = [exp for exp in EXPORTERS.keys() if exp != "cmsis" and exp != "zip"]
dkato 0:f782d9c66c49 24
dkato 0:f782d9c66c49 25
dkato 0:f782d9c66c49 26 def print_list(lst):
dkato 0:f782d9c66c49 27 """Prints to screen the contents of a list
dkato 0:f782d9c66c49 28
dkato 0:f782d9c66c49 29 Args:
dkato 0:f782d9c66c49 30 lst - a list of any type, to be displayed
dkato 0:f782d9c66c49 31
dkato 0:f782d9c66c49 32 """
dkato 0:f782d9c66c49 33 if lst:
dkato 0:f782d9c66c49 34 for thing in lst:
dkato 0:f782d9c66c49 35 print("# %s" % thing)
dkato 0:f782d9c66c49 36
dkato 0:f782d9c66c49 37
dkato 0:f782d9c66c49 38 def print_category(results, index, message):
dkato 0:f782d9c66c49 39 summary = [example for key, summ in results.iteritems()
dkato 0:f782d9c66c49 40 for example in summ[index]]
dkato 0:f782d9c66c49 41 if all(len(s) == 0 for s in summary):
dkato 0:f782d9c66c49 42 return
dkato 0:f782d9c66c49 43 print("#")
dkato 0:f782d9c66c49 44 print("#" * 80)
dkato 0:f782d9c66c49 45 print("# %s" % message)
dkato 0:f782d9c66c49 46 print("#" * 80)
dkato 0:f782d9c66c49 47 split_summ = [s.rsplit(" ", 1) for s in summary]
dkato 0:f782d9c66c49 48
dkato 0:f782d9c66c49 49 print_list(summary)
dkato 0:f782d9c66c49 50
dkato 0:f782d9c66c49 51
dkato 0:f782d9c66c49 52 def print_summary(results, export=False):
dkato 0:f782d9c66c49 53 """Prints to screen the results of compiling/exporting combinations of example programs,
dkato 0:f782d9c66c49 54 targets and compile toolchains/IDEs.
dkato 0:f782d9c66c49 55
dkato 0:f782d9c66c49 56 Args:
dkato 0:f782d9c66c49 57 results - results of the compilation stage. See compile_repos() and export_repos()
dkato 0:f782d9c66c49 58 for details of the format.
dkato 0:f782d9c66c49 59
dkato 0:f782d9c66c49 60 """
dkato 0:f782d9c66c49 61
dkato 0:f782d9c66c49 62 print("#"*80)
dkato 0:f782d9c66c49 63 print("# Examples compilation summary")
dkato 0:f782d9c66c49 64 print("#"*80)
dkato 0:f782d9c66c49 65
dkato 0:f782d9c66c49 66 print_category(results, 2, "Passed example combinations")
dkato 0:f782d9c66c49 67
dkato 0:f782d9c66c49 68 second_result = "Failed example combinations" if not export else \
dkato 0:f782d9c66c49 69 "Failed export example combinations"
dkato 0:f782d9c66c49 70
dkato 0:f782d9c66c49 71 print_category(results, 3, second_result)
dkato 0:f782d9c66c49 72
dkato 0:f782d9c66c49 73 if export:
dkato 0:f782d9c66c49 74 print_category(results, 4, "Failed build combinations")
dkato 0:f782d9c66c49 75 print_category(results, 5, "Skipped build combinations")
dkato 0:f782d9c66c49 76
dkato 0:f782d9c66c49 77 print("#")
dkato 0:f782d9c66c49 78 print("#"*80)
dkato 0:f782d9c66c49 79
dkato 0:f782d9c66c49 80 def valid_choices(allowed_choices, all_choices):
dkato 0:f782d9c66c49 81 if len(allowed_choices) > 0:
dkato 0:f782d9c66c49 82 return [t for t in all_choices if t in allowed_choices]
dkato 0:f782d9c66c49 83 else:
dkato 0:f782d9c66c49 84 return all_choices
dkato 0:f782d9c66c49 85
dkato 0:f782d9c66c49 86
dkato 0:f782d9c66c49 87 def target_cross_toolchain(allowed_targets, allowed_toolchains, features=[]):
dkato 0:f782d9c66c49 88 """Generate pairs of target and toolchains
dkato 0:f782d9c66c49 89
dkato 0:f782d9c66c49 90 Args:
dkato 0:f782d9c66c49 91 allowed_targets - a list of all possible targets
dkato 0:f782d9c66c49 92 allowed_toolchains - a list of all possible toolchains
dkato 0:f782d9c66c49 93
dkato 0:f782d9c66c49 94 Kwargs:
dkato 0:f782d9c66c49 95 features - the features that must be in the features array of a
dkato 0:f782d9c66c49 96 target
dkato 0:f782d9c66c49 97 """
dkato 0:f782d9c66c49 98 for target in allowed_targets:
dkato 0:f782d9c66c49 99 for toolchain in allowed_toolchains:
dkato 0:f782d9c66c49 100 if all(feature in TARGET_MAP[target].features
dkato 0:f782d9c66c49 101 for feature in features):
dkato 0:f782d9c66c49 102 yield target, toolchain
dkato 0:f782d9c66c49 103
dkato 0:f782d9c66c49 104
dkato 0:f782d9c66c49 105 def target_cross_ide(allowed_targets, allowed_ides, features=[], toolchains=[]):
dkato 0:f782d9c66c49 106 """Generate pairs of target and ides
dkato 0:f782d9c66c49 107
dkato 0:f782d9c66c49 108 Args:
dkato 0:f782d9c66c49 109 allowed_targets - a list of all possible targets
dkato 0:f782d9c66c49 110 allowed_ides - a list of all possible IDEs
dkato 0:f782d9c66c49 111
dkato 0:f782d9c66c49 112 Kwargs:
dkato 0:f782d9c66c49 113 features - the features that must be in the features array of a
dkato 0:f782d9c66c49 114 target
dkato 0:f782d9c66c49 115 """
dkato 0:f782d9c66c49 116 for target in allowed_targets:
dkato 0:f782d9c66c49 117 for ide in allowed_ides:
dkato 0:f782d9c66c49 118 if (target in EXPORTERS[ide].TARGETS and
dkato 0:f782d9c66c49 119 (not toolchains or EXPORTERS[ide].TOOLCHAIN in toolchains) and
dkato 0:f782d9c66c49 120 all(feature in TARGET_MAP[target].features
dkato 0:f782d9c66c49 121 for feature in features)):
dkato 0:f782d9c66c49 122 yield target, ide
dkato 0:f782d9c66c49 123
dkato 0:f782d9c66c49 124
dkato 0:f782d9c66c49 125 def get_repo_list(example):
dkato 0:f782d9c66c49 126 """ Returns a list of all the repos associated with the specific example in the json
dkato 0:f782d9c66c49 127 config file.
dkato 0:f782d9c66c49 128 If there are repos listed under the mbed section then these will be returned as a
dkato 0:f782d9c66c49 129 list. If not then the github single repo with be returned.
dkato 0:f782d9c66c49 130 NOTE: This does not currently deal with multiple examples underneath a github
dkato 0:f782d9c66c49 131 sourced exampe repo.
dkato 0:f782d9c66c49 132
dkato 0:f782d9c66c49 133 Args:
dkato 0:f782d9c66c49 134 example - Example for which the repo list is requested
dkato 0:f782d9c66c49 135 repos - The list of repos and types contained within that example in the json file
dkato 0:f782d9c66c49 136
dkato 0:f782d9c66c49 137 """
dkato 0:f782d9c66c49 138 repos = []
dkato 0:f782d9c66c49 139 if len(example['mbed']) > 0:
dkato 0:f782d9c66c49 140 for repo in example['mbed']:
dkato 0:f782d9c66c49 141 repos.append({
dkato 0:f782d9c66c49 142 'repo': repo,
dkato 0:f782d9c66c49 143 'type': 'hg'
dkato 0:f782d9c66c49 144 })
dkato 0:f782d9c66c49 145 else:
dkato 0:f782d9c66c49 146 repos.append({
dkato 0:f782d9c66c49 147 'repo': example['github'],
dkato 0:f782d9c66c49 148 'type': 'git'
dkato 0:f782d9c66c49 149 })
dkato 0:f782d9c66c49 150 return repos
dkato 0:f782d9c66c49 151
dkato 0:f782d9c66c49 152
dkato 0:f782d9c66c49 153 def source_repos(config, examples):
dkato 0:f782d9c66c49 154 """ Imports each of the repos and its dependencies (.lib files) associated
dkato 0:f782d9c66c49 155 with the specific examples name from the json config file. Note if
dkato 0:f782d9c66c49 156 there is already a clone of the repo then it will first be removed to
dkato 0:f782d9c66c49 157 ensure a clean, up to date cloning.
dkato 0:f782d9c66c49 158 Args:
dkato 0:f782d9c66c49 159 config - the json object imported from the file.
dkato 0:f782d9c66c49 160
dkato 0:f782d9c66c49 161 """
dkato 0:f782d9c66c49 162 print("\nImporting example repos....\n")
dkato 0:f782d9c66c49 163 for example in config['examples']:
dkato 0:f782d9c66c49 164 for repo_info in get_repo_list(example):
dkato 0:f782d9c66c49 165 name = basename(repo_info['repo'])
dkato 0:f782d9c66c49 166 if name in examples:
dkato 0:f782d9c66c49 167 if os.path.exists(name):
dkato 0:f782d9c66c49 168 print("'%s' example directory already exists. Deleting..." % name)
dkato 0:f782d9c66c49 169 rmtree(name)
dkato 0:f782d9c66c49 170
dkato 0:f782d9c66c49 171 subprocess.call(["mbed-cli", "import", repo_info['repo']])
dkato 0:f782d9c66c49 172
dkato 0:f782d9c66c49 173 def clone_repos(config, examples):
dkato 0:f782d9c66c49 174 """ Clones each of the repos associated with the specific examples name from the
dkato 0:f782d9c66c49 175 json config file. Note if there is already a clone of the repo then it will first
dkato 0:f782d9c66c49 176 be removed to ensure a clean, up to date cloning.
dkato 0:f782d9c66c49 177 Args:
dkato 0:f782d9c66c49 178 config - the json object imported from the file.
dkato 0:f782d9c66c49 179
dkato 0:f782d9c66c49 180 """
dkato 0:f782d9c66c49 181 print("\nCloning example repos....\n")
dkato 0:f782d9c66c49 182 for example in config['examples']:
dkato 0:f782d9c66c49 183 for repo_info in get_repo_list(example):
dkato 0:f782d9c66c49 184 name = basename(repo_info['repo'])
dkato 0:f782d9c66c49 185 if name in examples:
dkato 0:f782d9c66c49 186 if os.path.exists(name):
dkato 0:f782d9c66c49 187 print("'%s' example directory already exists. Deleting..." % name)
dkato 0:f782d9c66c49 188 rmtree(name)
dkato 0:f782d9c66c49 189
dkato 0:f782d9c66c49 190 subprocess.call([repo_info['type'], "clone", repo_info['repo']])
dkato 0:f782d9c66c49 191
dkato 0:f782d9c66c49 192 def deploy_repos(config, examples):
dkato 0:f782d9c66c49 193 """ If the example directory exists as provided by the json config file,
dkato 0:f782d9c66c49 194 pull in the examples dependencies by using `mbed-cli deploy`.
dkato 0:f782d9c66c49 195 Args:
dkato 0:f782d9c66c49 196 config - the json object imported from the file.
dkato 0:f782d9c66c49 197
dkato 0:f782d9c66c49 198 """
dkato 0:f782d9c66c49 199 print("\nDeploying example repos....\n")
dkato 0:f782d9c66c49 200 for example in config['examples']:
dkato 0:f782d9c66c49 201 for repo_info in get_repo_list(example):
dkato 0:f782d9c66c49 202 name = basename(repo_info['repo'])
dkato 0:f782d9c66c49 203 if name in examples:
dkato 0:f782d9c66c49 204 if os.path.exists(name):
dkato 0:f782d9c66c49 205 os.chdir(name)
dkato 0:f782d9c66c49 206 subprocess.call(["mbed-cli", "deploy"])
dkato 0:f782d9c66c49 207 os.chdir("..")
dkato 0:f782d9c66c49 208 else:
dkato 0:f782d9c66c49 209 print("'%s' example directory doesn't exist. Skipping..." % name)
dkato 0:f782d9c66c49 210
dkato 0:f782d9c66c49 211
dkato 0:f782d9c66c49 212 def get_num_failures(results, export=False):
dkato 0:f782d9c66c49 213 """ Returns the number of failed compilations from the results summary
dkato 0:f782d9c66c49 214 Args:
dkato 0:f782d9c66c49 215 results - results summary of the compilation stage. See compile_repos() for
dkato 0:f782d9c66c49 216 details of the format.
dkato 0:f782d9c66c49 217 num_failures
dkato 0:f782d9c66c49 218
dkato 0:f782d9c66c49 219 """
dkato 0:f782d9c66c49 220 num_failures = 0
dkato 0:f782d9c66c49 221
dkato 0:f782d9c66c49 222 for key, val in results.iteritems():
dkato 0:f782d9c66c49 223 num_failures = num_failures + len(val[3])
dkato 0:f782d9c66c49 224 if export:
dkato 0:f782d9c66c49 225 num_failures += len(val[4])
dkato 0:f782d9c66c49 226
dkato 0:f782d9c66c49 227 return num_failures
dkato 0:f782d9c66c49 228
dkato 0:f782d9c66c49 229 def export_repos(config, ides, targets, examples):
dkato 0:f782d9c66c49 230 """Exports and builds combinations of example programs, targets and IDEs.
dkato 0:f782d9c66c49 231
dkato 0:f782d9c66c49 232 The results are returned in a [key: value] dictionary format:
dkato 0:f782d9c66c49 233 Where key = The example name from the json config file
dkato 0:f782d9c66c49 234 value = a list containing: pass_status, successes, export failures, build_failures,
dkato 0:f782d9c66c49 235 and build_skips
dkato 0:f782d9c66c49 236
dkato 0:f782d9c66c49 237 where pass_status = The overall pass status for the export of the full
dkato 0:f782d9c66c49 238 set of example programs comprising the example suite.
dkato 0:f782d9c66c49 239 IE they must build and export) True if all examples pass, false otherwise
dkato 0:f782d9c66c49 240 successes = list of examples that exported and built (if possible)
dkato 0:f782d9c66c49 241 If the exporter has no build functionality, then it is a pass
dkato 0:f782d9c66c49 242 if exported
dkato 0:f782d9c66c49 243 export_failures = list of examples that failed to export.
dkato 0:f782d9c66c49 244 build_failures = list of examples that failed to build
dkato 0:f782d9c66c49 245 build_skips = list of examples that cannot build
dkato 0:f782d9c66c49 246
dkato 0:f782d9c66c49 247 Both successes and failures contain the example name, target and IDE
dkato 0:f782d9c66c49 248
dkato 0:f782d9c66c49 249 Args:
dkato 0:f782d9c66c49 250 config - the json object imported from the file.
dkato 0:f782d9c66c49 251 ides - List of IDES to export to
dkato 0:f782d9c66c49 252 """
dkato 0:f782d9c66c49 253 results = {}
dkato 0:f782d9c66c49 254 valid_examples = Set(examples)
dkato 0:f782d9c66c49 255 print("\nExporting example repos....\n")
dkato 0:f782d9c66c49 256 for example in config['examples']:
dkato 0:f782d9c66c49 257 example_names = [basename(x['repo']) for x in get_repo_list(example)]
dkato 0:f782d9c66c49 258 common_examples = valid_examples.intersection(Set(example_names))
dkato 0:f782d9c66c49 259 if not common_examples:
dkato 0:f782d9c66c49 260 continue
dkato 0:f782d9c66c49 261 export_failures = []
dkato 0:f782d9c66c49 262 build_failures = []
dkato 0:f782d9c66c49 263 build_skips = []
dkato 0:f782d9c66c49 264 successes = []
dkato 0:f782d9c66c49 265 exported = True
dkato 0:f782d9c66c49 266 pass_status = True
dkato 0:f782d9c66c49 267 if example['export']:
dkato 0:f782d9c66c49 268 for repo_info in get_repo_list(example):
dkato 0:f782d9c66c49 269 example_project_name = basename(repo_info['repo'])
dkato 0:f782d9c66c49 270 os.chdir(example_project_name)
dkato 0:f782d9c66c49 271 # Check that the target, IDE, and features combinations are valid and return a
dkato 0:f782d9c66c49 272 # list of valid combinations to work through
dkato 0:f782d9c66c49 273 for target, ide in target_cross_ide(valid_choices(example['targets'], targets),
dkato 0:f782d9c66c49 274 valid_choices(example['exporters'], ides),
dkato 0:f782d9c66c49 275 example['features'], example['toolchains']):
dkato 0:f782d9c66c49 276 example_name = "{} {} {}".format(example_project_name, target,
dkato 0:f782d9c66c49 277 ide)
dkato 0:f782d9c66c49 278 def status(message):
dkato 0:f782d9c66c49 279 print(message + " %s" % example_name)
dkato 0:f782d9c66c49 280 sys.stdout.flush()
dkato 0:f782d9c66c49 281
dkato 0:f782d9c66c49 282 status("Exporting")
dkato 0:f782d9c66c49 283 proc = subprocess.Popen(["mbed-cli", "export", "-i", ide,
dkato 0:f782d9c66c49 284 "-m", target])
dkato 0:f782d9c66c49 285 proc.wait()
dkato 0:f782d9c66c49 286 if proc.returncode:
dkato 0:f782d9c66c49 287 export_failures.append(example_name)
dkato 0:f782d9c66c49 288 status("FAILURE exporting")
dkato 0:f782d9c66c49 289 else:
dkato 0:f782d9c66c49 290 status("SUCCESS exporting")
dkato 0:f782d9c66c49 291 status("Building")
dkato 0:f782d9c66c49 292 try:
dkato 0:f782d9c66c49 293 if EXPORTERS[ide].build(example_project_name):
dkato 0:f782d9c66c49 294 status("FAILURE building")
dkato 0:f782d9c66c49 295 build_failures.append(example_name)
dkato 0:f782d9c66c49 296 else:
dkato 0:f782d9c66c49 297 status("SUCCESS building")
dkato 0:f782d9c66c49 298 successes.append(example_name)
dkato 0:f782d9c66c49 299 except TypeError:
dkato 0:f782d9c66c49 300 successes.append(example_name)
dkato 0:f782d9c66c49 301 build_skips.append(example_name)
dkato 0:f782d9c66c49 302 os.chdir("..")
dkato 0:f782d9c66c49 303
dkato 0:f782d9c66c49 304 if len(build_failures+export_failures) > 0:
dkato 0:f782d9c66c49 305 pass_status= False
dkato 0:f782d9c66c49 306 else:
dkato 0:f782d9c66c49 307 exported = False
dkato 0:f782d9c66c49 308
dkato 0:f782d9c66c49 309 results[example['name']] = [exported, pass_status, successes,
dkato 0:f782d9c66c49 310 export_failures, build_failures, build_skips]
dkato 0:f782d9c66c49 311
dkato 0:f782d9c66c49 312 return results
dkato 0:f782d9c66c49 313
dkato 0:f782d9c66c49 314
dkato 0:f782d9c66c49 315 def compile_repos(config, toolchains, targets, examples):
dkato 0:f782d9c66c49 316 """Compiles combinations of example programs, targets and compile chains.
dkato 0:f782d9c66c49 317
dkato 0:f782d9c66c49 318 The results are returned in a [key: value] dictionary format:
dkato 0:f782d9c66c49 319 Where key = The example name from the json config file
dkato 0:f782d9c66c49 320 value = a list containing: pass_status, successes, and failures
dkato 0:f782d9c66c49 321
dkato 0:f782d9c66c49 322 where pass_status = The overall pass status for the compilation of the full
dkato 0:f782d9c66c49 323 set of example programs comprising the example suite.
dkato 0:f782d9c66c49 324 True if all examples pass, false otherwise
dkato 0:f782d9c66c49 325 successes = list of passing examples.
dkato 0:f782d9c66c49 326 failures = list of failing examples.
dkato 0:f782d9c66c49 327
dkato 0:f782d9c66c49 328 Both successes and failures contain the example name, target and compile chain
dkato 0:f782d9c66c49 329
dkato 0:f782d9c66c49 330 Args:
dkato 0:f782d9c66c49 331 config - the json object imported from the file.
dkato 0:f782d9c66c49 332 toolchains - List of toolchains to compile for.
dkato 0:f782d9c66c49 333 results - results of the compilation stage.
dkato 0:f782d9c66c49 334
dkato 0:f782d9c66c49 335 """
dkato 0:f782d9c66c49 336 results = {}
dkato 0:f782d9c66c49 337 valid_examples = Set(examples)
dkato 0:f782d9c66c49 338 print("\nCompiling example repos....\n")
dkato 0:f782d9c66c49 339 for example in config['examples']:
dkato 0:f782d9c66c49 340 example_names = [basename(x['repo']) for x in get_repo_list(example)]
dkato 0:f782d9c66c49 341 common_examples = valid_examples.intersection(Set(example_names))
dkato 0:f782d9c66c49 342 if not common_examples:
dkato 0:f782d9c66c49 343 continue
dkato 0:f782d9c66c49 344 failures = []
dkato 0:f782d9c66c49 345 successes = []
dkato 0:f782d9c66c49 346 compiled = True
dkato 0:f782d9c66c49 347 pass_status = True
dkato 0:f782d9c66c49 348 if example['compile']:
dkato 0:f782d9c66c49 349 for repo_info in get_repo_list(example):
dkato 0:f782d9c66c49 350 name = basename(repo_info['repo'])
dkato 0:f782d9c66c49 351 os.chdir(name)
dkato 0:f782d9c66c49 352
dkato 0:f782d9c66c49 353 # Check that the target, toolchain and features combinations are valid and return a
dkato 0:f782d9c66c49 354 # list of valid combinations to work through
dkato 0:f782d9c66c49 355 for target, toolchain in target_cross_toolchain(valid_choices(example['targets'], targets),
dkato 0:f782d9c66c49 356 valid_choices(example['toolchains'], toolchains),
dkato 0:f782d9c66c49 357 example['features']):
dkato 0:f782d9c66c49 358 print("Compiling %s for %s, %s" % (name, target, toolchain))
dkato 0:f782d9c66c49 359 proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain,
dkato 0:f782d9c66c49 360 "-m", target, "--silent"])
dkato 0:f782d9c66c49 361 proc.wait()
dkato 0:f782d9c66c49 362 example_summary = "{} {} {}".format(name, target, toolchain)
dkato 0:f782d9c66c49 363 if proc.returncode:
dkato 0:f782d9c66c49 364 failures.append(example_summary)
dkato 0:f782d9c66c49 365 else:
dkato 0:f782d9c66c49 366 successes.append(example_summary)
dkato 0:f782d9c66c49 367 os.chdir("..")
dkato 0:f782d9c66c49 368
dkato 0:f782d9c66c49 369 # If there are any compilation failures for the example 'set' then the overall status is fail.
dkato 0:f782d9c66c49 370 if len(failures) > 0:
dkato 0:f782d9c66c49 371 pass_status = False
dkato 0:f782d9c66c49 372 else:
dkato 0:f782d9c66c49 373 compiled = False
dkato 0:f782d9c66c49 374
dkato 0:f782d9c66c49 375 results[example['name']] = [compiled, pass_status, successes, failures]
dkato 0:f782d9c66c49 376
dkato 0:f782d9c66c49 377 return results
dkato 0:f782d9c66c49 378
dkato 0:f782d9c66c49 379
dkato 0:f782d9c66c49 380 def update_mbedos_version(config, tag, examples):
dkato 0:f782d9c66c49 381 """ For each example repo identified in the config json object, update the version of
dkato 0:f782d9c66c49 382 mbed-os to that specified by the supplied GitHub tag. This function assumes that each
dkato 0:f782d9c66c49 383 example repo has already been cloned.
dkato 0:f782d9c66c49 384
dkato 0:f782d9c66c49 385 Args:
dkato 0:f782d9c66c49 386 config - the json object imported from the file.
dkato 0:f782d9c66c49 387 tag - GitHub tag corresponding to a version of mbed-os to upgrade to.
dkato 0:f782d9c66c49 388
dkato 0:f782d9c66c49 389 """
dkato 0:f782d9c66c49 390 print("Updating mbed-os in examples to version %s\n" % tag)
dkato 0:f782d9c66c49 391 for example in config['examples']:
dkato 0:f782d9c66c49 392 if example['name'] not in examples:
dkato 0:f782d9c66c49 393 continue
dkato 0:f782d9c66c49 394 for repo_info in get_repo_list(example):
dkato 0:f782d9c66c49 395 update_dir = basename(repo_info['repo']) + "/mbed-os"
dkato 0:f782d9c66c49 396 print("\nChanging dir to %s\n" % update_dir)
dkato 0:f782d9c66c49 397 os.chdir(update_dir)
dkato 0:f782d9c66c49 398 subprocess.call(["mbed-cli", "update", tag, "--clean"])
dkato 0:f782d9c66c49 399 os.chdir("../..")
dkato 0:f782d9c66c49 400