Skip to content

Commit 1f0afeb

Browse files
committed
Allow command-line filtering of toolchains
1 parent f7a1d1f commit 1f0afeb

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

tools/test/examples/examples.py

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" import and bulid a bunch of example programs """
22

3+
from argparse import ArgumentParser
34
import os
45
from os.path import dirname, abspath, basename
56
import os.path
@@ -12,42 +13,68 @@
1213

1314
from tools.build_api import get_mbed_official_release
1415
from tools.targets import TARGET_MAP
16+
from tools.utils import argparse_force_uppercase_type
1517

1618

1719
EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__),
1820
"examples.json")))
1921

2022
def print_stuff(name, lst):
21-
if list:
23+
if lst:
2224
print("#"*80)
2325
print("# {} example combinations".format(name))
2426
print("#")
2527
for thing in lst:
2628
print(thing)
2729

2830

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+
2951
def main():
3052
"""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+
3160
failures = []
3261
sucesses = []
3362
for example, build_features in EXAMPLES.iteritems():
3463
subprocess.call(["mbed-cli", "import", example])
3564
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)
5076
os.chdir("..")
77+
5178
print_stuff("Passed", sucesses)
5279
print_stuff("Failed", failures)
5380
return len(failures)

0 commit comments

Comments
 (0)