Skip to content

Commit b0d556b

Browse files
committed
Adding a clone and a deploy step to allow optimizations in CI.
This adds an example clone and deploy step that allows you to modify each top level repository before pulling in the rest of the example's dependencies. This allows us to not pull in a copy of mbed-os for each example in CI and instead symbolic link the already cloned copy, saving valuable time and disk space
1 parent f044786 commit b0d556b

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
@@ -130,34 +130,78 @@ def get_repo_list(example):
130130
131131
Args:
132132
example - Example for which the repo list is requested
133-
repos - The list of repos contained within that example in the json file
133+
repos - The list of repos and types contained within that example in the json file
134134
135135
"""
136136
repos = []
137137
if len(example['mbed']) > 0:
138138
for repo in example['mbed']:
139-
repos.append(repo)
139+
repos.append({
140+
'repo': repo,
141+
'type': 'hg'
142+
})
140143
else:
141-
repos.append(example['github'])
144+
repos.append({
145+
'repo': example['github'],
146+
'type': 'git'
147+
})
142148
return repos
143149

144150
def source_repos(config):
145-
""" Clones each of the repos associated with the specific examples name from the
146-
json config file. Note if there is already a clone of the repo then it will first
147-
be removed to ensure a clean, up to date cloning.
151+
""" Imports each of the repos and its dependencies (.lib files) associated
152+
with the specific examples name from the json config file. Note if
153+
there is already a clone of the repo then it will first be removed to
154+
ensure a clean, up to date cloning.
148155
Args:
149156
config - the json object imported from the file.
150157
151158
"""
152159
print("\nImporting example repos....\n")
153160
for example in config['examples']:
154-
for repo in get_repo_list(example):
155-
name = basename(repo)
161+
for repo_info in get_repo_list(example):
162+
name = basename(repo_info['repo'])
156163
if os.path.exists(name):
157164
print("'%s' example directory already exists. Deleting..." % name)
158165
rmtree(name)
159166

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

162206
def get_num_failures(results, export=False):
163207
""" Returns the number of failed compilations from the results summary
@@ -191,8 +235,8 @@ def print_message(message, name):
191235
exported = True
192236
pass_status = True
193237
if example['export']:
194-
for repo in get_repo_list(example):
195-
example_project_name = basename(repo)
238+
for repo_info in get_repo_list(example):
239+
example_project_name = basename(repo_info['repo'])
196240
os.chdir(example_project_name)
197241
# Check that the target, IDE, and features combinations are valid and return a
198242
# list of valid combinations to work through
@@ -265,8 +309,9 @@ def compile_repos(config, toolchains):
265309
if len(example['toolchains']) > 0:
266310
toolchains = example['toolchains']
267311

268-
for repo in get_repo_list(example):
269-
os.chdir(basename(repo))
312+
for repo_info in get_repo_list(example):
313+
name = basename(repo_info['repo'])
314+
os.chdir(name)
270315

271316
# Check that the target, toolchain and features combinations are valid and return a
272317
# list of valid combinations to work through
@@ -275,7 +320,7 @@ def compile_repos(config, toolchains):
275320
proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain,
276321
"-m", target, "--silent"])
277322
proc.wait()
278-
example_summary = "{} {} {}".format(basename(repo), target, toolchain)
323+
example_summary = "{} {} {}".format(name, target, toolchain)
279324
if proc.returncode:
280325
failures.append(example_summary)
281326
else:
@@ -305,8 +350,8 @@ def update_mbedos_version(config, tag):
305350
"""
306351
print("Updating mbed-os in examples to version %s\n" % tag)
307352
for example in config['examples']:
308-
for repo in get_repo_list(example):
309-
update_dir = basename(repo) + "/mbed-os"
353+
for repo_info in get_repo_list(example):
354+
update_dir = basename(repo_info['repo']) + "/mbed-os"
310355
print("\nChanging dir to %s\n" % update_dir)
311356
os.chdir(update_dir)
312357
subprocess.call(["mbed-cli", "update", tag, "--clean"])

0 commit comments

Comments
 (0)