Skip to content

Commit d2a8b8b

Browse files
author
Qinghao Shi
committed
update example script for cmake
1 parent 9cc2a07 commit d2a8b8b

File tree

2 files changed

+57
-35
lines changed

2 files changed

+57
-35
lines changed

tools/test/examples/examples.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ def parse_args():
8080
official_target_names, "MCU")),
8181
default=official_target_names)
8282

83-
compile_cmd.add_argument(
84-
"--profiles",
85-
nargs='+',
86-
metavar="profile",
87-
help="build profile(s)")
83+
compile_cmd.add_argument("--profiles",
84+
nargs='+',
85+
metavar="profile",
86+
help="build profile(s)")
8887

8988
compile_cmd.add_argument("-j", "--jobs",
9089
dest='jobs',
@@ -93,6 +92,12 @@ def parse_args():
9392
default=0,
9493
help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
9594

95+
compile_cmd.add_argument("--cmake",
96+
action="store_true",
97+
dest="cmake",
98+
default=True,
99+
help="Use Cmake to build job")
100+
96101
compile_cmd.add_argument("-v", "--verbose",
97102
action="store_true",
98103
dest="verbose",
@@ -159,13 +164,13 @@ def do_deploy(_, config, examples):
159164

160165
def do_compile(args, config, examples):
161166
"""Do the compile step"""
162-
results = lib.compile_repos(config, args.toolchains, args.mcu, args.profiles, args.verbose, examples, args.jobs)
167+
results = lib.compile_repos(config, args.toolchains, args.mcu, args.profiles, args.verbose, examples, args.cmake, args.jobs)
163168
failures = lib.get_build_summary(results)
164169
return failures
165170

166171
def do_update(args, config, examples):
167172
""" Test update the mbed-os to the version specified by the tag """
168-
return lib.update_mbedos_version(config, args.TAG, examples)
173+
return lib.update_example_version(config, args.TAG, examples)
169174

170175
def do_list(_, config, examples):
171176
"""List the examples in the config file"""

tools/test/examples/examples_lib.py

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def export_repos(config, ides, targets, exp_filter):
329329
return results
330330

331331

332-
def compile_repos(config, toolchains, targets, profiles, verbose, exp_filter, jobs=0):
332+
def compile_repos(config, toolchains, targets, profiles, verbose, exp_filter, cmake=False ,jobs=0):
333333
"""Compiles combinations of example programs, targets and compile chains.
334334
335335
The results are returned in a [key: value] dictionary format:
@@ -382,27 +382,36 @@ def compile_repos(config, toolchains, targets, profiles, verbose, exp_filter, jo
382382
summary_string = "%s %s %s" % (name, target, toolchain)
383383
logging.info("Compiling %s" % summary_string)
384384

385-
build_command = ["mbed-cli", "compile", "-t", toolchain, "-m", target, "-j", str(jobs)] + (['-vv'] if verbose else [])
386-
if profiles:
387-
for profile in profiles:
388-
build_command.extend(["--profile", profile])
389-
390-
logging.info("Executing command '%s'..." % " ".join(build_command))
391-
proc = subprocess.Popen(build_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
392-
393-
std_out, std_err = proc.communicate()
394-
std_out = std_out.decode()
395-
std_err = std_err.decode()
396-
print ("\n#### STDOUT ####\n%s\n#### STDERR ####\n%s\n#### End of STDOUT/STDERR ####\n" % (std_out,std_err))
397-
398-
if proc.returncode:
399-
failures.append(example_summary)
385+
if cmake:
386+
build_command_seq = ["mbed-tools configure -t {} -m {}".format(toolchain,target), "rm -fr cmake_build","cmake -S . -B cmake_build -GNinja", "cmake --build cmake_build"]
400387
else:
388+
build_command_seq = ["mbed-cli compile -t {} -m {} -j {} {}".format(toolchain, target, str(jobs), '-vv' if verbose else '') ]
389+
if profiles:
390+
for profile in profiles:
391+
build_command_seq[0] += " --profile {}".format(profile)
392+
393+
failed_flag = False
394+
for build_command in build_command_seq:
395+
logging.info("Executing command '%s'..." % build_command)
396+
proc = subprocess.Popen(build_command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
397+
398+
std_out, std_err = proc.communicate()
399+
std_out = std_out.decode()
400+
std_err = std_err.decode()
401+
print ("\n#### STDOUT ####\n%s\n#### STDERR ####\n%s\n#### End of STDOUT/STDERR ####\n" % (std_out,std_err))
402+
403+
if proc.returncode:
404+
failures.append(example_summary)
405+
failed_flag = True
406+
break
407+
408+
409+
if not failed_flag:
401410
if example['test']:
402411
log = example['compare_log'].pop(0)
403412
# example['compare_log'] is a list of log file/files, which matches each examples/sub-examples from same repo.
404413
# pop the log file out of list regardless the compilation for each example pass of fail
405-
image = fetch_output_image(std_out)
414+
image = fetch_output_image(std_out,cmake)
406415
if image:
407416
image_info = [{"binary_type": "bootable","path": normpath(join(name,image)),"compare_log":log}]
408417
test_group = "{}-{}-{}".format(target, toolchain, example['baud_rate'])
@@ -438,7 +447,7 @@ def compile_repos(config, toolchains, targets, profiles, verbose, exp_filter, jo
438447
return results
439448

440449

441-
def update_mbedos_version(config, tag, exp_filter):
450+
def update_example_version(config, tag, exp_filter):
442451
""" For each example repo identified in the config json object, update the version of
443452
mbed-os to that specified by the supplied GitHub tag. This function assumes that each
444453
example repo has already been cloned.
@@ -448,15 +457,15 @@ def update_mbedos_version(config, tag, exp_filter):
448457
tag - GitHub tag corresponding to a version of mbed-os to upgrade to.
449458
450459
"""
451-
print("\nUpdating mbed-os in examples to version '%s'\n" % tag)
460+
print("\nUpdating examples to version(branch) '%s'\n" % tag)
452461
for example in config['examples']:
453462
if example['name'] not in exp_filter:
454463
continue
455464
for name in get_sub_examples_list(example):
456465
update_dir = name + "/mbed-os"
457-
os.chdir(update_dir)
466+
os.chdir(name)
458467
logging.info("In folder '%s'" % name)
459-
cmd = "mbed-cli update %s --clean" %tag
468+
cmd = "git checkout -B %s origin/%s" %(tag, tag)
460469
logging.info("Executing command '%s'..." % cmd)
461470
result = subprocess.call(cmd, shell=True)
462471
os.chdir(CWD)
@@ -476,26 +485,34 @@ def symlink_mbedos(config, path, exp_filter):
476485
os.chdir(name)
477486
logging.info("In folder '%s'" % name)
478487
if os.path.exists("mbed-os.lib"):
479-
logging.info("Removing 'mbed-os.lib' in '%s'" % name)
480-
os.remove("mbed-os.lib")
488+
logging.info("Replacing 'mbed-os.lib' in '%s'" % name)
489+
open("mbed-os.lib", 'w').close()
481490
else:
482491
logging.warning("No 'mbed-os.lib' found in '%s'" % name)
483492
if os.path.exists("mbed-os"):
484493
logging.warning("'mbed-os' already existed in '%s'" % name)
485494
else:
486495
logging.info("Creating Symbolic link '%s'->'mbed-os'" % path)
487496
os.symlink(path, "mbed-os")
497+
open('mbed-os.lib', 'a').close()
488498
os.chdir(CWD)
489499
return 0
490500

491-
def fetch_output_image(output):
501+
def fetch_output_image(output,cmake):
492502
"""Find the build image from the last 30 lines of a given log"""
493503
lines = output.splitlines()
494504
last_index = -31 if len(lines)>29 else (-1 - len(lines))
495505
for index in range(-1,last_index,-1):
496-
if lines[index].startswith("Image:"):
497-
image = lines[index][7:]
498-
if os.path.isfile(image):
499-
return image
506+
if cmake:
507+
if lines[index].startswith("-- built:") and lines[index].endswith(".bin"):
508+
image = lines[index][10:]
509+
print("IMAGE is " + image)
510+
if os.path.isfile(image):
511+
return image
512+
else:
513+
if lines[index].startswith("Image:"):
514+
image = lines[index][7:]
515+
if os.path.isfile(image):
516+
return image
500517
return False
501518

0 commit comments

Comments
 (0)