Skip to content

Commit 9624ccf

Browse files
committed
Add boolean 'export' to examples.json.
This will determine whether the example should be exported. Additionally, relocated export logic to examples_lib.py.
1 parent cc154a4 commit 9624ccf

File tree

3 files changed

+123
-110
lines changed

3 files changed

+123
-110
lines changed

tools/test/examples/examples.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"features" : [],
1010
"targets" : [],
1111
"toolchains" : [],
12+
"exporters": [],
1213
"compile" : true,
14+
"export": true,
1315
"auto-update" : true
1416
},
1517
{
@@ -24,7 +26,9 @@
2426
"features" : [],
2527
"targets" : ["K64F", "NUCLEO_F429ZI"],
2628
"toolchains" : ["GCC_ARM", "ARM"],
29+
"exporters": [],
2730
"compile" : true,
31+
"export": false,
2832
"auto-update" : true
2933
},
3034
{
@@ -36,7 +40,9 @@
3640
"features" : ["IPV6"],
3741
"targets" : [],
3842
"toolchains" : [],
43+
"exporters": [],
3944
"compile" : true,
45+
"export": false,
4046
"auto-update" : true
4147
},
4248
{
@@ -57,7 +63,9 @@
5763
"features" : ["BLE"],
5864
"targets" : ["NRF51_DK", "NRF52_DK", "K64F", "NUCLEO_F401RE"],
5965
"toolchains" : [],
66+
"exporters": [],
6067
"compile" : true,
68+
"export": false,
6169
"auto-update" : true
6270
},
6371
{
@@ -69,7 +77,9 @@
6977
"features" : ["IPV6"],
7078
"targets" : [],
7179
"toolchains" : [],
80+
"exporters": [],
7281
"compile" : true,
82+
"export": false,
7383
"auto-update" : true
7484
},
7585
{
@@ -80,7 +90,9 @@
8090
"features" : ["IPV6"],
8191
"targets" : [],
8292
"toolchains" : [],
93+
"exporters": [],
8394
"compile" : true,
95+
"export": false,
8496
"auto-update" : true
8597
},
8698
{
@@ -91,7 +103,9 @@
91103
"features" : [],
92104
"targets" : [],
93105
"toolchains" : [],
106+
"exporters": [],
94107
"compile" : false,
108+
"export": false,
95109
"auto-update" : true
96110
},
97111
{
@@ -102,7 +116,9 @@
102116
"features" : [],
103117
"targets" : ["K64F"],
104118
"toolchains" : ["GCC_ARM"],
119+
"exporters": [],
105120
"compile" : true,
121+
"export": false,
106122
"auto-update" : false
107123
}
108124
]

tools/test/examples/examples.py

Lines changed: 11 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -13,70 +13,11 @@
1313

1414
from tools.utils import argparse_force_uppercase_type
1515
import examples_lib as lib
16-
from examples_lib import SUPPORTED_TOOLCHAINS
17-
from tools.export import EXPORTERS
18-
from tools.build_api import get_mbed_official_release
19-
from tools.targets import TARGET_MAP
16+
from examples_lib import SUPPORTED_TOOLCHAINS, SUPPORTED_IDES
2017

2118
EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__),
2219
"examples.json")))
2320

24-
def print_stuff(name, lst):
25-
if lst:
26-
print("#"*80)
27-
print("# {} example combinations".format(name))
28-
print("#")
29-
for thing in lst:
30-
print(thing)
31-
32-
33-
SUPPORTED_TOOLCHAINS = ["ARM", "IAR", "GCC_ARM"]
34-
SUPPORTED_IDES = ["iar", "uvision", "make_gcc_arm", "make_iar", "make_armc5"]
35-
36-
37-
def target_cross_toolchain(allowed_toolchains,
38-
features=[], targets=TARGET_MAP.keys(),
39-
toolchains=SUPPORTED_TOOLCHAINS):
40-
"""Generate pairs of target and toolchains
41-
42-
Args:
43-
allowed_toolchains - a list of all possible toolchains
44-
45-
Kwargs:
46-
features - the features that must be in the features array of a
47-
target
48-
targets - a list of available targets
49-
toolchains - a list of available toolchains
50-
"""
51-
for release_target, release_toolchains in get_mbed_official_release("5"):
52-
for toolchain in release_toolchains:
53-
if (toolchain in allowed_toolchains and
54-
toolchain in toolchains and
55-
release_target in targets and
56-
all(feature in TARGET_MAP[release_target].features
57-
for feature in features)):
58-
yield release_target, toolchain
59-
60-
61-
def target_cross_ide(allowed_ides,
62-
features=[],
63-
ides=SUPPORTED_IDES,
64-
toolchains=SUPPORTED_TOOLCHAINS):
65-
"""Generate pairs of target and ides
66-
67-
Args:
68-
allowed_ides - a list of all possible IDEs
69-
70-
"""
71-
for release_target, release_toolchains in get_mbed_official_release("5"):
72-
for ide in allowed_ides:
73-
if (release_target in EXPORTERS[ide].TARGETS and
74-
EXPORTERS[ide].TOOLCHAIN in toolchains and
75-
ide in ides and
76-
all(feature in TARGET_MAP[release_target].features
77-
for feature in features)):
78-
yield release_target, ide
79-
8021

8122
def main():
8223
"""Entry point"""
@@ -106,57 +47,29 @@ def main():
10647
return args.fn(args, config)
10748

10849

109-
def do_export(args):
50+
def do_export(args, config):
11051
"""Do export and build step"""
111-
def print_message(message, name):
112-
print(message+ " %s"%name)
113-
sys.stdout.flush()
52+
results = {}
53+
results = lib.export_repos(config, args.ide)
54+
55+
lib.print_summary(results, export=True)
56+
failures = lib.get_num_failures(results, export=True)
57+
print("Number of failures = %d" % failures)
58+
return failures
11459

115-
export_failures = []
116-
build_failures = []
117-
sucesses = []
118-
for example, requirements in EXAMPLES.iteritems():
119-
ex_name = basename(example)
120-
if ex_name != "mbed-os-example-blinky":
121-
continue
122-
os.chdir(ex_name)
123-
for target, ide in target_cross_ide(args.ide,
124-
**requirements):
125-
example_name = "{} {} {}".format(ex_name, target,
126-
ide)
127-
print_message("Export:",example_name)
128-
proc = subprocess.Popen(["mbed-cli", "export", "-i", ide,
129-
"-m", target])
130-
proc.wait()
131-
if proc.returncode:
132-
export_failures.append(example_name)
133-
print_message("FAILURE Export:", example_name)
134-
else:
135-
print_message("SUCCESS Export:", example_name)
136-
print_message("Build:", example_name)
137-
if EXPORTERS[ide].build(ex_name):
138-
print_message("FAILURE Build:", example_name)
139-
build_failures.append(example_name)
140-
else:
141-
print_message("SUCCESS Build:", example_name)
142-
sucesses.append(example_name)
143-
print_stuff("Passed", sucesses)
144-
print_stuff("Failed Export", export_failures)
145-
print_stuff("Failed Building", build_failures)
146-
return len(export_failures+build_failures)
14760

148-
14961
def do_import(_, config):
15062
"""Do the import step of this process"""
15163
lib.source_repos(config)
15264
return 0
15365

66+
15467
def do_compile(args, config):
15568
"""Do the compile step"""
15669
results = {}
15770
results = lib.compile_repos(config, args.toolchains)
15871

159-
lib.print_compilation_summary(results)
72+
lib.print_summary(results)
16073
failures = lib.get_num_failures(results)
16174
print("Number of failures = %d" % failures)
16275
return failures

tools/test/examples/examples_lib.py

Lines changed: 96 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
from tools.build_api import get_mbed_official_release
1818
from tools.targets import TARGET_MAP
19+
from tools.export import EXPORTERS
1920

2021
SUPPORTED_TOOLCHAINS = ["ARM", "IAR", "GCC_ARM"]
22+
SUPPORTED_IDES = ["iar", "uvision", "make_gcc_arm", "make_iar", "make_armc5"]
2123

2224
def print_list(lst):
2325
"""Prints to screen the contents of a list
@@ -30,13 +32,13 @@ def print_list(lst):
3032
for thing in lst:
3133
print("# %s" % thing)
3234

33-
def print_compilation_summary(results):
34-
"""Prints to screen the results of compiling combinations of example programs,
35-
targets and compile chains.
35+
def print_summary(results, export=False):
36+
"""Prints to screen the results of compiling/exporting combinations of example programs,
37+
targets and compile toolchains/IDEs.
3638
3739
Args:
38-
results - results of the compilation stage. See compile_repos() for
39-
details of the format.
40+
results - results of the compilation stage. See compile_repos() and export_repos()
41+
for details of the format.
4042
4143
"""
4244

@@ -48,12 +50,23 @@ def print_compilation_summary(results):
4850
print("#")
4951
for key, val in results.iteritems():
5052
print_list(val[2])
53+
54+
second_result = "Failed example combinations" if not export else \
55+
"Failed export example combinations"
5156

5257
print("#")
53-
print("# Failed example combinations")
58+
print("# %s"%second_result)
5459
print("#")
5560
for key, val in results.iteritems():
5661
print_list(val[3])
62+
63+
if export:
64+
print("#")
65+
print("# Failed build example combinations")
66+
print("#")
67+
for key, val in results.iteritems():
68+
print_list(val[4])
69+
5770
print("#")
5871
print("#"*80)
5972

@@ -81,18 +94,30 @@ def target_cross_toolchain(allowed_toolchains,
8194
for feature in features)):
8295
yield target, toolchain
8396

97+
8498
def target_cross_ide(allowed_ides,
85-
targets=TARGET_MAP.keys()):
99+
features=[], targets=[]):
86100
"""Generate pairs of target and ides
87101
88102
Args:
89103
allowed_ides - a list of all possible IDEs
90104
105+
Kwargs:
106+
features - the features that must be in the features array of a
107+
target
108+
targets - a list of available targets
91109
"""
92-
for release_target, release_toolchains in get_mbed_official_release("5"):
110+
if len(targets) == 0:
111+
targets=TARGET_MAP.keys()
112+
113+
for target, toolchains in get_mbed_official_release("5"):
93114
for ide in allowed_ides:
94-
if release_target in EXPORTERS[ide].TARGETS:
95-
yield release_target, ide
115+
if (EXPORTERS[ide].TOOLCHAIN in toolchains and
116+
target in EXPORTERS[ide].TARGETS and
117+
target in targets and
118+
all(feature in TARGET_MAP[target].features
119+
for feature in features)):
120+
yield target, ide
96121

97122

98123
def get_repo_list(example):
@@ -134,7 +159,7 @@ def source_repos(config):
134159

135160
subprocess.call(["mbed-cli", "import", repo])
136161

137-
def get_num_failures(results):
162+
def get_num_failures(results, export=False):
138163
""" Returns the number of failed compilations from the results summary
139164
Args:
140165
results - results summary of the compilation stage. See compile_repos() for
@@ -146,9 +171,68 @@ def get_num_failures(results):
146171

147172
for key, val in results.iteritems():
148173
num_failures = num_failures + len(val[3])
174+
if export:
175+
num_failures += len(val[4])
149176

150177
return num_failures
151-
178+
179+
180+
def export_repos(config, ides):
181+
def print_message(message, name):
182+
print(message+ " %s"%name)
183+
sys.stdout.flush()
184+
185+
results = {}
186+
print("\nExporting example repos....\n")
187+
for example in config['examples']:
188+
export_failures = []
189+
build_failures = []
190+
successes = []
191+
exported = True
192+
pass_status = True
193+
if example['export']:
194+
for repo in get_repo_list(example):
195+
example_project_name = basename(repo)
196+
os.chdir(example_project_name)
197+
# Check that the target, IDE, and features combinations are valid and return a
198+
# list of valid combinations to work through
199+
for target, ide in target_cross_ide(ides,
200+
example['features'],
201+
example['targets']):
202+
example_name = "{} {} {}".format(example_project_name, target,
203+
ide)
204+
def status(message):
205+
print(message + " %s" % example_name)
206+
sys.stdout.flush()
207+
208+
status("Exporting")
209+
proc = subprocess.Popen(["mbed-cli", "export", "-i", ide,
210+
"-m", target])
211+
proc.wait()
212+
if proc.returncode:
213+
export_failures.append(example_name)
214+
status("FAILURE exporting")
215+
else:
216+
status("SUCCESS exporting")
217+
status("Building")
218+
if EXPORTERS[ide].build(example_project_name):
219+
status("FAILURE building")
220+
build_failures.append(example_name)
221+
else:
222+
status("SUCCESS building")
223+
successes.append(example_name)
224+
os.chdir("..")
225+
226+
if len(build_failures+export_failures) > 0:
227+
pass_status= False
228+
else:
229+
exported = False
230+
231+
results[example['name']] = [exported, pass_status, successes, export_failures, build_failures]
232+
233+
return results
234+
235+
152236
def compile_repos(config, toolchains):
153237
"""Compiles combinations of example programs, targets and compile chains.
154238

0 commit comments

Comments
 (0)