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