Skip to content

Commit 88d5079

Browse files
Qinghao ShiQinghao Shi
authored andcommitted
EXAMPLES: update comments and fix bugs
1 parent cf02be6 commit 88d5079

File tree

2 files changed

+55
-34
lines changed

2 files changed

+55
-34
lines changed

tools/test/examples/examples.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
13
"""
24
Copyright (c) 2017-2019 ARM Limited. All rights reserved.
35
@@ -28,6 +30,10 @@
2830
""" import and bulid a bunch of example programs """
2931

3032
ROOT = abspath(dirname(dirname(dirname(dirname(__file__)))))
33+
DEFAULT_BUILD_PROFILES = [
34+
"develop",
35+
"mbed-os/tools/profiles/extensions/minimal-printf.json",
36+
]
3137
sys.path.insert(0, ROOT)
3238

3339
from tools.utils import argparse_force_uppercase_type
@@ -36,9 +42,8 @@
3642
import examples_lib as lib
3743
from examples_lib import SUPPORTED_TOOLCHAINS, SUPPORTED_IDES
3844

39-
def main():
40-
"""Entry point"""
41-
45+
def parse_args():
46+
"""Parse the arguments passed to the script."""
4247
official_targets = get_mbed_official_release("5")
4348
official_target_names = [x[0] for x in official_targets]
4449

@@ -79,10 +84,14 @@ def main():
7984
official_target_names, "MCU")),
8085
default=official_target_names)
8186

82-
compile_cmd.add_argument("--profile",
83-
help=("build profile file"),
84-
metavar="profile")
85-
87+
compile_cmd.add_argument(
88+
"--profiles",
89+
nargs='+',
90+
default=DEFAULT_BUILD_PROFILES,
91+
metavar="profile",
92+
help="build profile file(s). default = {}".format(DEFAULT_BUILD_PROFILES)
93+
)
94+
8695
compile_cmd.add_argument("-j", "--jobs",
8796
dest='jobs',
8897
metavar="NUMBER",
@@ -97,7 +106,7 @@ def main():
97106
help="Verbose diagnostic output")
98107

99108
export_cmd = subparsers.add_parser("export", help="export of examples")
100-
export_cmd.set_defaults(fn=do_export),
109+
export_cmd.set_defaults(fn=do_export)
101110
export_cmd.add_argument(
102111
"ide", nargs="*", default=SUPPORTED_IDES,
103112
type=argparse_force_uppercase_type(SUPPORTED_IDES,
@@ -110,7 +119,12 @@ def main():
110119
argparse_force_uppercase_type(
111120
official_target_names, "MCU")),
112121
default=official_target_names)
113-
args = parser.parse_args()
122+
return parser.parse_args()
123+
124+
125+
def main():
126+
"""Entry point"""
127+
args = parse_args()
114128
config = json.load(open(os.path.join(os.path.dirname(__file__),
115129
args.config)))
116130

@@ -151,7 +165,7 @@ def do_deploy(_, config, examples):
151165

152166
def do_compile(args, config, examples):
153167
"""Do the compile step"""
154-
results = lib.compile_repos(config, args.toolchains, args.mcu, args.profile, args.verbose, examples, args.jobs)
168+
results = lib.compile_repos(config, args.toolchains, args.mcu, args.profiles, args.verbose, examples, args.jobs)
155169
failures = lib.get_build_summary(results)
156170
return failures
157171

@@ -170,6 +184,7 @@ def do_list(_, config, examples):
170184
return 0
171185

172186
def do_symlink(args, config, examples):
187+
"""Create Symbolic link for given mbed-os PATH"""
173188
return lib.symlink_mbedos(config, args.PATH, examples)
174189

175190
if __name__ == "__main__":

tools/test/examples/examples_lib.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
13
"""
24
Copyright (c) 2017-2019 ARM Limited. All rights reserved.
35
@@ -53,13 +55,12 @@
5355

5456

5557
def get_build_summary(results):
56-
"""Prints to screen the results of compiling/exporting combinations of example programs,
57-
targets and compile toolchains/IDEs.
58+
"""Prints to screen the complication results of example programs.
5859
5960
Args:
60-
results - results of the compilation stage. See compile_repos() and export_repos()
61-
for details of the format.
62-
61+
results - results of the compilation stage. which is the output of compile_repos()
62+
63+
Returns: Numbers of failed results
6364
"""
6465
pass_table = PrettyTable()
6566
pass_table.field_names = ["EXAMPLE NAME", "TARGET", "TOOLCHAIN", "TEST GEN", "BUILD RESULT"]
@@ -82,13 +83,12 @@ def get_build_summary(results):
8283
return failure_counter
8384

8485
def get_export_summary(results):
85-
"""Prints to screen the results of compiling/exporting combinations of example programs,
86-
targets and compile toolchains/IDEs.
86+
"""Prints to screen the exporting results of example programs.
8787
8888
Args:
89-
results - results of the compilation stage. See compile_repos() and export_repos()
90-
for details of the format.
91-
89+
results - results of the compilation stage. which is the output of and export_repos()
90+
91+
Returns: Numbers of failed results
9292
"""
9393
pass_table = PrettyTable()
9494
pass_table.field_names = ["EXAMPLE NAME", "TARGET", "IDE", "EXPORT RESULT", "BUILD RESULT"]
@@ -162,8 +162,7 @@ def target_cross_ide(allowed_targets, allowed_ides, features=[], toolchains=[]):
162162

163163

164164
def get_sub_examples_list(example):
165-
"""
166-
"""
165+
""" Get the names of sub examples. if no sub examples, return the name of main example"""
167166
sub_examples = []
168167
if example['sub-repo-example']:
169168
for sub in example['subs']:
@@ -330,7 +329,7 @@ def export_repos(config, ides, targets, exp_filter):
330329
return results
331330

332331

333-
def compile_repos(config, toolchains, targets, profile, verbose, exp_filter, jobs=0):
332+
def compile_repos(config, toolchains, targets, profiles, verbose, exp_filter, jobs=0):
334333
"""Compiles combinations of example programs, targets and compile chains.
335334
336335
The results are returned in a [key: value] dictionary format:
@@ -382,19 +381,20 @@ def compile_repos(config, toolchains, targets, profile, verbose, exp_filter, job
382381
example_summary = {"name" : name, "target" : target, "toolchain" : toolchain, "test": "UNSET"}
383382
summary_string = "%s %s %s" % (name, target, toolchain)
384383
logging.info("Compiling %s" % summary_string)
385-
384+
386385
build_command = ["mbed-cli", "compile", "-t", toolchain, "-m", target, "-j", str(jobs)] + (['-vv'] if verbose else [])
387-
if profile:
388-
build_command.append("--profile")
389-
build_command.append(profile)
390-
386+
if profiles:
387+
for profile in profiles:
388+
build_command.extend(["--profile", profile])
389+
391390
logging.info("Executing command '%s'..." % " ".join(build_command))
392391
proc = subprocess.Popen(build_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
393392

394393
std_out, std_err = proc.communicate()
395-
std_out = std_out.decode('utf-8')
394+
std_out = std_out.decode()
395+
std_err = std_err.decode()
396396
print ("\n#### STDOUT ####\n%s\n#### STDERR ####\n%s\n#### End of STDOUT/STDERR ####\n" % (std_out,std_err))
397-
397+
398398
if proc.returncode:
399399
failures.append(example_summary)
400400
else:
@@ -465,7 +465,8 @@ def update_mbedos_version(config, tag, exp_filter):
465465
return 0
466466

467467
def symlink_mbedos(config, path, exp_filter):
468-
"""
468+
""" Create a symbolic link in each example folder to given path
469+
If a mbed-os.lib can be found in the folder, it will be removed
469470
"""
470471
print("\nCreating mbed-os Symbolic link to '%s'\n" % path)
471472
for example in config['examples']:
@@ -475,11 +476,15 @@ def symlink_mbedos(config, path, exp_filter):
475476
os.chdir(name)
476477
logging.info("In folder '%s'" % name)
477478
if os.path.exists("mbed-os.lib"):
479+
logging.info("Removing 'mbed-os.lib' in '%s'" % name)
478480
os.remove("mbed-os.lib")
479481
else:
480482
logging.warning("No 'mbed-os.lib' found in '%s'" % name)
481-
logging.info("Creating Symbolic link '%s'->'mbed-os'" % path)
482-
os.symlink(path, "mbed-os")
483+
if os.path.exists("mbed-os"):
484+
logging.warning("'mbed-os' already existed in '%s'" % name)
485+
else:
486+
logging.info("Creating Symbolic link '%s'->'mbed-os'" % path)
487+
os.symlink(path, "mbed-os")
483488
os.chdir(CWD)
484489
return 0
485490

@@ -492,4 +497,5 @@ def fetch_output_image(output):
492497
image = lines[index][7:]
493498
if os.path.isfile(image):
494499
return image
495-
return False
500+
return False
501+

0 commit comments

Comments
 (0)