Skip to content

Commit 045b7d4

Browse files
committed
Minor review comments plus add new 'compile' option to examples json file.
Adding the new compile option allows the marking of a set of examples to indicate whether they should be compiled or not. For the update process examples that are not compiled will not be auto updated irrespective of that setting. Other changes to make return logic from some functions in update.py more efficient and some typos in the lib file.
1 parent 3696456 commit 045b7d4

File tree

3 files changed

+65
-48
lines changed

3 files changed

+65
-48
lines changed

tools/test/examples/examples.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"features" : [],
1010
"targets" : [],
1111
"toolchains" : [],
12+
"compile" : true,
1213
"auto-update" : true
1314
},
1415
{
@@ -23,6 +24,7 @@
2324
"features" : [],
2425
"targets" : ["K64F", "NUCLEO_F429ZI"],
2526
"toolchains" : ["GCC_ARM", "ARM"],
27+
"compile" : true,
2628
"auto-update" : true
2729
},
2830
{
@@ -34,6 +36,7 @@
3436
"features" : ["IPV6"],
3537
"targets" : [],
3638
"toolchains" : [],
39+
"compile" : true,
3740
"auto-update" : true
3841
},
3942
{
@@ -55,6 +58,7 @@
5558
"features" : ["BLE"],
5659
"targets" : [],
5760
"toolchains" : [],
61+
"compile" : true,
5862
"auto-update" : true
5963
},
6064
{
@@ -66,6 +70,7 @@
6670
"features" : ["IPV6"],
6771
"targets" : [],
6872
"toolchains" : [],
73+
"compile" : true,
6974
"auto-update" : true
7075
},
7176
{
@@ -76,6 +81,7 @@
7681
"features" : ["IPV6"],
7782
"targets" : [],
7883
"toolchains" : [],
84+
"compile" : true,
7985
"auto-update" : true
8086
},
8187
{
@@ -86,6 +92,7 @@
8692
"features" : [],
8793
"targets" : [],
8894
"toolchains" : [],
95+
"compile" : true,
8996
"auto-update" : true
9097
},
9198
{
@@ -96,6 +103,7 @@
96103
"features" : [],
97104
"targets" : ["K64F"],
98105
"toolchains" : ["GCC_ARM"],
106+
"compile" : true,
99107
"auto-update" : false
100108
}
101109
]

tools/test/examples/examples_lib.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ def print_compilation_summary(results):
4747
print("# Passed example combinations")
4848
print("#")
4949
for key, val in results.iteritems():
50-
print_list(val[1])
50+
print_list(val[2])
5151

5252
print("#")
5353
print("# Failed example combinations")
5454
print("#")
5555
for key, val in results.iteritems():
56-
print_list(val[2])
56+
print_list(val[3])
5757
print("#")
5858
print("#"*80)
5959

@@ -132,7 +132,7 @@ def get_num_failures(results):
132132
num_failures = 0
133133

134134
for key, val in results.iteritems():
135-
num_failures = num_failures + len(val[2])
135+
num_failures = num_failures + len(val[3])
136136

137137
return num_failures
138138

@@ -141,7 +141,7 @@ def compile_repos(config, toolchains):
141141
142142
The results are returned in a [key: value] dictionary format:
143143
Where key = The example name from the json config file
144-
value = a list containing: pass_status, successes, and failures failures
144+
value = a list containing: pass_status, successes, and failures
145145
146146
where pass_status = The overall pass status for the compilation of the full
147147
set of example programs comprising the example suite.
@@ -162,31 +162,37 @@ def compile_repos(config, toolchains):
162162
for example in config['examples']:
163163
failures = []
164164
successes = []
165-
if len(example['toolchains']) > 0:
166-
toolchains = example['toolchains']
167-
168-
for repo in get_repo_list(example):
169-
os.chdir(basename(repo))
170-
171-
# Check that the target, toolchain and features combinations are valid and return a
172-
# list of valid combinations to work through
173-
for target, toolchain in target_cross_toolchain(toolchains,
174-
example['features'], example['targets']):
175-
proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain,
176-
"-m", target, "--silent"])
177-
proc.wait()
178-
example_summary = "{} {} {}".format(basename(repo), target, toolchain)
179-
if proc.returncode:
180-
failures.append(example_summary)
181-
else:
182-
successes.append(example_summary)
183-
os.chdir("..")
165+
compiled = True
184166
pass_status = True
185-
186-
# If there are any compilation failures for the example 'set' then the overall status is fail.
187-
if len(failures) > 0:
188-
pass_status = False
189-
results[example['name']] = [pass_status, successes, failures]
167+
if example['compile']:
168+
if len(example['toolchains']) > 0:
169+
toolchains = example['toolchains']
170+
171+
for repo in get_repo_list(example):
172+
os.chdir(basename(repo))
173+
174+
# Check that the target, toolchain and features combinations are valid and return a
175+
# list of valid combinations to work through
176+
for target, toolchain in target_cross_toolchain(toolchains,
177+
example['features'], example['targets']):
178+
proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain,
179+
"-m", target, "--silent"])
180+
proc.wait()
181+
example_summary = "{} {} {}".format(basename(repo), target, toolchain)
182+
if proc.returncode:
183+
failures.append(example_summary)
184+
else:
185+
successes.append(example_summary)
186+
os.chdir("..")
187+
188+
# If there are any compilation failures for the example 'set' then the overall status is fail.
189+
if len(failures) > 0:
190+
pass_status = False
191+
else:
192+
compiled = False
193+
194+
results[example['name']] = [compiled, pass_status, successes, failures]
195+
190196
return results
191197

192198

tools/test/examples/update.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ def find_all_examples(path):
5858
"""
5959
examples = []
6060
for root, dirs, files in os.walk(path):
61-
for file in files:
62-
if file == 'mbed-os.lib':
63-
examples += [root]
61+
if 'mbed-os.lib' in files:
62+
examples += [root]
6463

6564
return examples
6665

@@ -105,12 +104,8 @@ def upgrade_single_example(example, tag, directory):
105104
add_cmd = ['git', 'add', 'mbed-os.lib']
106105
return_code = run_cmd(add_cmd)
107106

108-
if return_code:
109-
os.chdir(cwd)
110-
return False
111-
112107
os.chdir(cwd)
113-
return True
108+
return not return_code
114109

115110
def upgrade_example(example, tag):
116111
""" Clones the example specified from GitHub and updates the associated mbed-os.lib file
@@ -182,12 +177,8 @@ def upgrade_example(example, tag):
182177
push_cmd = ['git', 'push', 'origin', tag]
183178
return_code = run_cmd(push_cmd)
184179

185-
if return_code:
186-
os.chdir(cwd)
187-
return False
188-
189180
os.chdir(cwd)
190-
return True
181+
return not return_code
191182

192183
def create_work_directory(path):
193184
""" Create a new directory specified in 'path', overwrite if the directory already
@@ -254,6 +245,7 @@ def main(arguments):
254245
# Loop through the examples
255246
failures = []
256247
successes = []
248+
not_compiled = []
257249
results = {}
258250
os.chdir('examples')
259251

@@ -266,13 +258,18 @@ def main(arguments):
266258
# Attempt to update if:
267259
# group of examples passed compilation and
268260
# auto update is set to True
269-
if results[example['name']][0] and example['auto-update']:
270-
if upgrade_example(example, args.tag):
271-
successes += [example['name']]
272-
else:
261+
# Note: results fields are [compiled flag, pass flag, successes list, failures list]
262+
if not results[example['name']][0]:
263+
# Example was not compiled
264+
not_compiled += [example['name']]
265+
else:
266+
if results[example['name']][1] and example['auto-update']:
267+
if upgrade_example(example, args.tag):
268+
successes += [example['name']]
269+
else:
270+
failures += [example['name']]
271+
else:
273272
failures += [example['name']]
274-
else:
275-
failures += [example['name']]
276273

277274
os.chdir('../')
278275

@@ -285,9 +282,15 @@ def main(arguments):
285282
print(' - %s' % success)
286283

287284
if failures:
288-
print('\nThe following were not updated:')
285+
print('\nThe following examples were not updated:')
289286
for fail in failures:
290287
print(' - %s' % fail)
291288

289+
if not_compiled:
290+
print('The following examples were skipped:')
291+
for example in not_compiled:
292+
print(' - %s' % example)
293+
294+
292295
if __name__ == '__main__':
293296
sys.exit(main(sys.argv[1:]))

0 commit comments

Comments
 (0)