|
1 | 1 | """ import and bulid a bunch of example programs """
|
2 | 2 |
|
| 3 | +from argparse import ArgumentParser |
3 | 4 | import os
|
4 | 5 | from os.path import dirname, abspath, basename
|
5 | 6 | import os.path
|
|
12 | 13 |
|
13 | 14 | from tools.build_api import get_mbed_official_release
|
14 | 15 | from tools.targets import TARGET_MAP
|
| 16 | +from tools.utils import argparse_force_uppercase_type |
15 | 17 |
|
16 | 18 |
|
17 | 19 | EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__),
|
18 | 20 | "examples.json")))
|
19 | 21 |
|
20 | 22 | def print_stuff(name, lst):
|
21 |
| - if list: |
| 23 | + if lst: |
22 | 24 | print("#"*80)
|
23 | 25 | print("# {} example combinations".format(name))
|
24 | 26 | print("#")
|
25 | 27 | for thing in lst:
|
26 | 28 | print(thing)
|
27 | 29 |
|
28 | 30 |
|
| 31 | +SUPPORTED_TOOLCHAINS = ["ARM", "IAR", "GCC_ARM"] |
| 32 | + |
| 33 | + |
| 34 | +def target_cross_toolchain(required_features, allowed_toolchains): |
| 35 | + """Generate pairs of target and toolchains |
| 36 | +
|
| 37 | + Args: |
| 38 | + required_features - the features that must be in the features array of a |
| 39 | + target |
| 40 | + allowed_toolchains - a list of all possible toolchains |
| 41 | + """ |
| 42 | + for target, toolchains in get_mbed_official_release("5"): |
| 43 | + for toolchain in toolchains: |
| 44 | + if (toolchain in allowed_toolchains and |
| 45 | + all(feature in TARGET_MAP[target].features |
| 46 | + for feature in required_features)): |
| 47 | + yield target, toolchain |
| 48 | + |
| 49 | + |
| 50 | + |
29 | 51 | def main():
|
30 | 52 | """Entry point"""
|
| 53 | + parser = ArgumentParser() |
| 54 | + parser.add_argument( |
| 55 | + "toolchains", nargs="*", default=SUPPORTED_TOOLCHAINS, |
| 56 | + type=argparse_force_uppercase_type(SUPPORTED_TOOLCHAINS, |
| 57 | + "toolchain")) |
| 58 | + args = parser.parse_args() |
| 59 | + |
31 | 60 | failures = []
|
32 | 61 | sucesses = []
|
33 | 62 | for example, build_features in EXAMPLES.iteritems():
|
34 | 63 | subprocess.call(["mbed-cli", "import", example])
|
35 | 64 | os.chdir(basename(example))
|
36 |
| - for target, toolchains in [(target, toolchains) for target, toolchains |
37 |
| - in get_mbed_official_release("5") if |
38 |
| - all(feature in TARGET_MAP[target].features |
39 |
| - for feature in build_features)]: |
40 |
| - for toolchain in toolchains: |
41 |
| - proc = subprocess.Popen(["mbed-cli", "compile", "-t", |
42 |
| - toolchain, "-m", target]) |
43 |
| - proc.wait() |
44 |
| - example_name = "{} {} {}".format(basename(example), target, |
45 |
| - toolchain) |
46 |
| - if proc.returncode: |
47 |
| - failures.append(example_name) |
48 |
| - else: |
49 |
| - sucesses.append(example_name) |
| 65 | + for target, toolchain in target_cross_toolchain(build_features, |
| 66 | + args.toolchains): |
| 67 | + proc = subprocess.Popen(["mbed-cli", "compile", "-t", |
| 68 | + toolchain, "-m", target]) |
| 69 | + proc.wait() |
| 70 | + example_name = "{} {} {}".format(basename(example), target, |
| 71 | + toolchain) |
| 72 | + if proc.returncode: |
| 73 | + failures.append(example_name) |
| 74 | + else: |
| 75 | + sucesses.append(example_name) |
50 | 76 | os.chdir("..")
|
| 77 | + |
51 | 78 | print_stuff("Passed", sucesses)
|
52 | 79 | print_stuff("Failed", failures)
|
53 | 80 | return len(failures)
|
|
0 commit comments