Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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