Skip to content

Commit 79abaab

Browse files
authored
Merge pull request #3208 from bridadan/examples-clone-deploy
[example tests] Adding a clone and a deploy step to allow optimizations in CI.
2 parents 73e1229 + b0d556b commit 79abaab

File tree

2 files changed

+77
-16
lines changed

2 files changed

+77
-16
lines changed

tools/test/examples/examples.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def main():
2626
subparsers = parser.add_subparsers()
2727
import_cmd = subparsers.add_parser("import")
2828
import_cmd.set_defaults(fn=do_import)
29+
clone_cmd = subparsers.add_parser("clone")
30+
clone_cmd.set_defaults(fn=do_clone)
31+
deploy_cmd = subparsers.add_parser("deploy")
32+
deploy_cmd.set_defaults(fn=do_deploy)
2933
version_cmd = subparsers.add_parser("tag")
3034
version_cmd.add_argument("tag")
3135
version_cmd.set_defaults(fn=do_versionning)
@@ -64,6 +68,18 @@ def do_import(_, config):
6468
return 0
6569

6670

71+
def do_clone(_, config):
72+
"""Do the clone step of this process"""
73+
lib.clone_repos(config)
74+
return 0
75+
76+
77+
def do_deploy(_, config):
78+
"""Do the deploy step of this process"""
79+
lib.deploy_repos(config)
80+
return 0
81+
82+
6783
def do_compile(args, config):
6884
"""Do the compile step"""
6985
results = {}

tools/test/examples/examples_lib.py

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,35 +136,79 @@ def get_repo_list(example):
136136
137137
Args:
138138
example - Example for which the repo list is requested
139-
repos - The list of repos contained within that example in the json file
139+
repos - The list of repos and types contained within that example in the json file
140140
141141
"""
142142
repos = []
143143
if len(example['mbed']) > 0:
144144
for repo in example['mbed']:
145-
repos.append(repo)
145+
repos.append({
146+
'repo': repo,
147+
'type': 'hg'
148+
})
146149
else:
147-
repos.append(example['github'])
150+
repos.append({
151+
'repo': example['github'],
152+
'type': 'git'
153+
})
148154
return repos
149155

150156

151157
def source_repos(config):
152-
""" Clones each of the repos associated with the specific examples name from the
153-
json config file. Note if there is already a clone of the repo then it will first
154-
be removed to ensure a clean, up to date cloning.
158+
""" Imports each of the repos and its dependencies (.lib files) associated
159+
with the specific examples name from the json config file. Note if
160+
there is already a clone of the repo then it will first be removed to
161+
ensure a clean, up to date cloning.
155162
Args:
156163
config - the json object imported from the file.
157164
158165
"""
159166
print("\nImporting example repos....\n")
160167
for example in config['examples']:
161-
for repo in get_repo_list(example):
162-
name = basename(repo)
168+
for repo_info in get_repo_list(example):
169+
name = basename(repo_info['repo'])
163170
if os.path.exists(name):
164171
print("'%s' example directory already exists. Deleting..." % name)
165172
rmtree(name)
166173

167-
subprocess.call(["mbed-cli", "import", repo])
174+
subprocess.call(["mbed-cli", "import", repo_info['repo']])
175+
176+
def clone_repos(config):
177+
""" Clones each of the repos associated with the specific examples name from the
178+
json config file. Note if there is already a clone of the repo then it will first
179+
be removed to ensure a clean, up to date cloning.
180+
Args:
181+
config - the json object imported from the file.
182+
183+
"""
184+
print("\nCloning example repos....\n")
185+
for example in config['examples']:
186+
for repo_info in get_repo_list(example):
187+
name = basename(repo_info['repo'])
188+
if os.path.exists(name):
189+
print("'%s' example directory already exists. Deleting..." % name)
190+
rmtree(name)
191+
192+
subprocess.call([repo_info['type'], "clone", repo_info['repo']])
193+
194+
def deploy_repos(config):
195+
""" If the example directory exists as provided by the json config file,
196+
pull in the examples dependencies by using `mbed-cli deploy`.
197+
Args:
198+
config - the json object imported from the file.
199+
200+
"""
201+
print("\nDeploying example repos....\n")
202+
for example in config['examples']:
203+
for repo_info in get_repo_list(example):
204+
name = basename(repo_info['repo'])
205+
206+
if os.path.exists(name):
207+
os.chdir(name)
208+
subprocess.call(["mbed-cli", "deploy"])
209+
os.chdir("..")
210+
else:
211+
print("'%s' example directory doesn't exist. Skipping..." % name)
168212

169213

170214
def get_num_failures(results, export=False):
@@ -220,8 +264,8 @@ def export_repos(config, ides):
220264
exported = True
221265
pass_status = True
222266
if example['export']:
223-
for repo in get_repo_list(example):
224-
example_project_name = basename(repo)
267+
for repo_info in get_repo_list(example):
268+
example_project_name = basename(repo_info['repo'])
225269
os.chdir(example_project_name)
226270
# Check that the target, IDE, and features combinations are valid and return a
227271
# list of valid combinations to work through
@@ -299,8 +343,9 @@ def compile_repos(config, toolchains):
299343
if len(example['toolchains']) > 0:
300344
toolchains = example['toolchains']
301345

302-
for repo in get_repo_list(example):
303-
os.chdir(basename(repo))
346+
for repo_info in get_repo_list(example):
347+
name = basename(repo_info['repo'])
348+
os.chdir(name)
304349

305350
# Check that the target, toolchain and features combinations are valid and return a
306351
# list of valid combinations to work through
@@ -309,7 +354,7 @@ def compile_repos(config, toolchains):
309354
proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain,
310355
"-m", target, "--silent"])
311356
proc.wait()
312-
example_summary = "{} {} {}".format(basename(repo), target, toolchain)
357+
example_summary = "{} {} {}".format(name, target, toolchain)
313358
if proc.returncode:
314359
failures.append(example_summary)
315360
else:
@@ -339,8 +384,8 @@ def update_mbedos_version(config, tag):
339384
"""
340385
print("Updating mbed-os in examples to version %s\n" % tag)
341386
for example in config['examples']:
342-
for repo in get_repo_list(example):
343-
update_dir = basename(repo) + "/mbed-os"
387+
for repo_info in get_repo_list(example):
388+
update_dir = basename(repo_info['repo']) + "/mbed-os"
344389
print("\nChanging dir to %s\n" % update_dir)
345390
os.chdir(update_dir)
346391
subprocess.call(["mbed-cli", "update", tag, "--clean"])

0 commit comments

Comments
 (0)