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