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