Clone of official tools

Committer:
The Other Jimmy
Date:
Wed Feb 15 13:53:18 2017 -0600
Revision:
35:da9c89f8be7d
Parent:
31:8ea194f6145b
Update tools to mbed-os 5.3.5

Who changed what in which revision?

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