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