Skip to content

Commit b739413

Browse files
committed
Correcting example, toolchain, and ide filters
1 parent 4bfd73a commit b739413

File tree

2 files changed

+63
-72
lines changed

2 files changed

+63
-72
lines changed

tools/test/examples/examples.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
import examples_lib as lib
1818
from examples_lib import SUPPORTED_TOOLCHAINS, SUPPORTED_IDES
1919

20-
EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__),
21-
"examples.json")))
22-
23-
2420
def main():
2521
"""Entry point"""
2622

@@ -33,7 +29,7 @@ def main():
3329
parser.add_argument("-e", "--example",
3430
help=("filter the examples used in the script"),
3531
type=argparse_many(lambda x: x),
36-
default = EXAMPLES.keys())
32+
default=[])
3733
subparsers = parser.add_subparsers()
3834
import_cmd = subparsers.add_parser("import")
3935
import_cmd.set_defaults(fn=do_import)
@@ -75,51 +71,56 @@ def main():
7571
args = parser.parse_args()
7672
config = json.load(open(os.path.join(os.path.dirname(__file__),
7773
args.config)))
78-
return args.fn(args, config)
74+
75+
all_examples = []
76+
for example in config['examples']:
77+
all_examples = all_examples + [basename(x['repo']) for x in lib.get_repo_list(example)]
78+
examples = [x for x in all_examples if x in args.example] if args.example else all_examples
79+
return args.fn(args, config, examples)
7980

8081

81-
def do_export(args, config):
82+
def do_export(args, config, examples):
8283
"""Do export and build step"""
8384
results = {}
84-
results = lib.export_repos(config, args.ide, args.mcu, args.example)
85+
results = lib.export_repos(config, args.ide, args.mcu, examples)
8586

8687
lib.print_summary(results, export=True)
8788
failures = lib.get_num_failures(results, export=True)
8889
print("Number of failures = %d" % failures)
8990
return failures
9091

9192

92-
def do_import(_, config):
93+
def do_import(args, config, examples):
9394
"""Do the import step of this process"""
94-
lib.source_repos(config)
95+
lib.source_repos(config, examples)
9596
return 0
9697

9798

98-
def do_clone(_, config):
99+
def do_clone(args, config, examples):
99100
"""Do the clone step of this process"""
100-
lib.clone_repos(config)
101+
lib.clone_repos(config, examples)
101102
return 0
102103

103104

104-
def do_deploy(_, config):
105+
def do_deploy(args, config, examples):
105106
"""Do the deploy step of this process"""
106-
lib.deploy_repos(config)
107+
lib.deploy_repos(config, examples)
107108
return 0
108109

109110

110-
def do_compile(args, config):
111+
def do_compile(args, config, examples):
111112
"""Do the compile step"""
112113
results = {}
113-
results = lib.compile_repos(config, args.toolchains, args.mcu, args.example)
114+
results = lib.compile_repos(config, args.toolchains, args.mcu, examples)
114115

115116
lib.print_summary(results)
116117
failures = lib.get_num_failures(results)
117118
print("Number of failures = %d" % failures)
118119
return failures
119120

120-
def do_versionning(args, config):
121+
def do_versionning(args, config, examples):
121122
""" Test update the mbed-os to the version specified by the tag """
122-
lib.update_mbedos_version(config, args.tag, args.example)
123+
lib.update_mbedos_version(config, args.tag, examples)
123124
return 0
124125

125126

tools/test/examples/examples_lib.py

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -76,57 +76,48 @@ def print_summary(results, export=False):
7676
print("#")
7777
print("#"*80)
7878

79-
def valid_targets(allowed_targets, targets):
80-
if len(allowed_targets) > 0:
81-
return [t for t in targets if t in allowed_targets]
79+
def valid_choices(allowed_choices, all_choices):
80+
if len(allowed_choices) > 0:
81+
return [t for t in all_choices if t in allowed_choices]
8282
else:
83-
return targets
83+
return all_choices
8484

8585

86-
def target_cross_toolchain(allowed_toolchains,
87-
features=[], targets=[]):
86+
def target_cross_toolchain(allowed_targets, allowed_toolchains, features=[]):
8887
"""Generate pairs of target and toolchains
8988
9089
Args:
90+
allowed_targets - a list of all possible targets
9191
allowed_toolchains - a list of all possible toolchains
9292
9393
Kwargs:
9494
features - the features that must be in the features array of a
9595
target
96-
targets - a list of available targets
9796
"""
98-
if len(targets) == 0:
99-
targets=TARGET_MAP.keys()
100-
101-
for target, toolchains in get_mbed_official_release("5"):
102-
for toolchain in toolchains:
103-
if (toolchain in allowed_toolchains and
104-
target in targets and
105-
all(feature in TARGET_MAP[target].features
106-
for feature in features)):
97+
for target in allowed_targets:
98+
for toolchain in allowed_toolchains:
99+
if all(feature in TARGET_MAP[target].features
100+
for feature in features):
107101
yield target, toolchain
108102

109103

110-
def target_cross_ide(allowed_ides,
111-
features=[], targets=[]):
104+
def target_cross_ide(allowed_targets, allowed_ides, features=[]):
112105
"""Generate pairs of target and ides
113106
114107
Args:
108+
allowed_targets - a list of all possible targets
115109
allowed_ides - a list of all possible IDEs
116110
117111
Kwargs:
118112
features - the features that must be in the features array of a
119113
target
120-
targets - a list of available targets
121114
"""
122-
if len(targets) == 0:
123-
targets=TARGET_MAP.keys()
124-
125-
for target, toolchains in get_mbed_official_release("5"):
115+
for target in allowed_targets:
126116
for ide in allowed_ides:
127-
if (EXPORTERS[ide].TOOLCHAIN in toolchains and
128-
target in EXPORTERS[ide].TARGETS and
129-
target in targets and
117+
if all(feature in TARGET_MAP[target].features
118+
for feature in features):
119+
yield target, toolchain
120+
if (target in EXPORTERS[ide].TARGETS and
130121
all(feature in TARGET_MAP[target].features
131122
for feature in features)):
132123
yield target, ide
@@ -160,7 +151,7 @@ def get_repo_list(example):
160151
return repos
161152

162153

163-
def source_repos(config):
154+
def source_repos(config, examples):
164155
""" Imports each of the repos and its dependencies (.lib files) associated
165156
with the specific examples name from the json config file. Note if
166157
there is already a clone of the repo then it will first be removed to
@@ -173,13 +164,14 @@ def source_repos(config):
173164
for example in config['examples']:
174165
for repo_info in get_repo_list(example):
175166
name = basename(repo_info['repo'])
176-
if os.path.exists(name):
177-
print("'%s' example directory already exists. Deleting..." % name)
178-
rmtree(name)
179-
180-
subprocess.call(["mbed-cli", "import", repo_info['repo']])
167+
if name in examples:
168+
if os.path.exists(name):
169+
print("'%s' example directory already exists. Deleting..." % name)
170+
rmtree(name)
181171

182-
def clone_repos(config):
172+
subprocess.call(["mbed-cli", "import", repo_info['repo']])
173+
174+
def clone_repos(config, examples):
183175
""" Clones each of the repos associated with the specific examples name from the
184176
json config file. Note if there is already a clone of the repo then it will first
185177
be removed to ensure a clean, up to date cloning.
@@ -191,13 +183,14 @@ def clone_repos(config):
191183
for example in config['examples']:
192184
for repo_info in get_repo_list(example):
193185
name = basename(repo_info['repo'])
194-
if os.path.exists(name):
195-
print("'%s' example directory already exists. Deleting..." % name)
196-
rmtree(name)
186+
if name in examples:
187+
if os.path.exists(name):
188+
print("'%s' example directory already exists. Deleting..." % name)
189+
rmtree(name)
197190

198-
subprocess.call([repo_info['type'], "clone", repo_info['repo']])
191+
subprocess.call([repo_info['type'], "clone", repo_info['repo']])
199192

200-
def deploy_repos(config):
193+
def deploy_repos(config, examples):
201194
""" If the example directory exists as provided by the json config file,
202195
pull in the examples dependencies by using `mbed-cli deploy`.
203196
Args:
@@ -208,13 +201,13 @@ def deploy_repos(config):
208201
for example in config['examples']:
209202
for repo_info in get_repo_list(example):
210203
name = basename(repo_info['repo'])
211-
212-
if os.path.exists(name):
213-
os.chdir(name)
214-
subprocess.call(["mbed-cli", "deploy"])
215-
os.chdir("..")
216-
else:
217-
print("'%s' example directory doesn't exist. Skipping..." % name)
204+
if name in examples:
205+
if os.path.exists(name):
206+
os.chdir(name)
207+
subprocess.call(["mbed-cli", "deploy"])
208+
os.chdir("..")
209+
else:
210+
print("'%s' example directory doesn't exist. Skipping..." % name)
218211

219212

220213
def get_num_failures(results, export=False):
@@ -276,9 +269,9 @@ def export_repos(config, ides, targets, examples):
276269
os.chdir(example_project_name)
277270
# Check that the target, IDE, and features combinations are valid and return a
278271
# list of valid combinations to work through
279-
for target, ide in target_cross_ide(ides,
280-
example['features'],
281-
valid_targets(example['targets'],targets)):
272+
for target, ide in target_cross_ide(valid_choices(example['targets'], targets),
273+
valid_choices(example['exporters'], ides),
274+
example['features']):
282275
example_name = "{} {} {}".format(example_project_name, target,
283276
ide)
284277
def status(message):
@@ -349,18 +342,15 @@ def compile_repos(config, toolchains, targets, examples):
349342
compiled = True
350343
pass_status = True
351344
if example['compile']:
352-
if len(example['toolchains']) > 0:
353-
toolchains = example['toolchains']
354-
355345
for repo_info in get_repo_list(example):
356346
name = basename(repo_info['repo'])
357347
os.chdir(name)
358348

359349
# Check that the target, toolchain and features combinations are valid and return a
360350
# list of valid combinations to work through
361-
for target, toolchain in target_cross_toolchain(toolchains,
362-
example['features'],
363-
valid_targets(example['targets'],targets)):
351+
for target, toolchain in target_cross_toolchain(valid_choices(example['targets'], targets),
352+
valid_choices(example['toolchains'], toolchains),
353+
example['features']):
364354
proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain,
365355
"-m", target, "--silent"])
366356
proc.wait()

0 commit comments

Comments
 (0)