Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-sdk-tools by
test/examples/examples.py@31:182518299918, 2017-01-04 (annotated)
- Committer:
- The Other Jimmy
- Date:
- Wed Jan 04 11:58:24 2017 -0600
- Revision:
- 31:182518299918
Update tools to follow mbed-os tools release 5.3.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
The Other Jimmy |
31:182518299918 | 1 | """ import and bulid a bunch of example programs """ |
The Other Jimmy |
31:182518299918 | 2 | |
The Other Jimmy |
31:182518299918 | 3 | from argparse import ArgumentParser |
The Other Jimmy |
31:182518299918 | 4 | import os |
The Other Jimmy |
31:182518299918 | 5 | from os.path import dirname, abspath, basename |
The Other Jimmy |
31:182518299918 | 6 | import os.path |
The Other Jimmy |
31:182518299918 | 7 | import sys |
The Other Jimmy |
31:182518299918 | 8 | import subprocess |
The Other Jimmy |
31:182518299918 | 9 | import json |
The Other Jimmy |
31:182518299918 | 10 | |
The Other Jimmy |
31:182518299918 | 11 | ROOT = abspath(dirname(dirname(dirname(dirname(__file__))))) |
The Other Jimmy |
31:182518299918 | 12 | sys.path.insert(0, ROOT) |
The Other Jimmy |
31:182518299918 | 13 | |
The Other Jimmy |
31:182518299918 | 14 | from tools.utils import argparse_force_uppercase_type |
The Other Jimmy |
31:182518299918 | 15 | from tools.utils import argparse_many |
The Other Jimmy |
31:182518299918 | 16 | from tools.build_api import get_mbed_official_release |
The Other Jimmy |
31:182518299918 | 17 | import examples_lib as lib |
The Other Jimmy |
31:182518299918 | 18 | from examples_lib import SUPPORTED_TOOLCHAINS, SUPPORTED_IDES |
The Other Jimmy |
31:182518299918 | 19 | |
The Other Jimmy |
31:182518299918 | 20 | def main(): |
The Other Jimmy |
31:182518299918 | 21 | """Entry point""" |
The Other Jimmy |
31:182518299918 | 22 | |
The Other Jimmy |
31:182518299918 | 23 | official_targets = get_mbed_official_release("5") |
The Other Jimmy |
31:182518299918 | 24 | official_target_names = [x[0] for x in official_targets] |
The Other Jimmy |
31:182518299918 | 25 | |
The Other Jimmy |
31:182518299918 | 26 | |
The Other Jimmy |
31:182518299918 | 27 | parser = ArgumentParser() |
The Other Jimmy |
31:182518299918 | 28 | parser.add_argument("-c", dest="config", default="examples.json") |
The Other Jimmy |
31:182518299918 | 29 | parser.add_argument("-e", "--example", |
The Other Jimmy |
31:182518299918 | 30 | help=("filter the examples used in the script"), |
The Other Jimmy |
31:182518299918 | 31 | type=argparse_many(lambda x: x), |
The Other Jimmy |
31:182518299918 | 32 | default=[]) |
The Other Jimmy |
31:182518299918 | 33 | subparsers = parser.add_subparsers() |
The Other Jimmy |
31:182518299918 | 34 | import_cmd = subparsers.add_parser("import") |
The Other Jimmy |
31:182518299918 | 35 | import_cmd.set_defaults(fn=do_import) |
The Other Jimmy |
31:182518299918 | 36 | clone_cmd = subparsers.add_parser("clone") |
The Other Jimmy |
31:182518299918 | 37 | clone_cmd.set_defaults(fn=do_clone) |
The Other Jimmy |
31:182518299918 | 38 | deploy_cmd = subparsers.add_parser("deploy") |
The Other Jimmy |
31:182518299918 | 39 | deploy_cmd.set_defaults(fn=do_deploy) |
The Other Jimmy |
31:182518299918 | 40 | version_cmd = subparsers.add_parser("tag") |
The Other Jimmy |
31:182518299918 | 41 | version_cmd.add_argument("tag") |
The Other Jimmy |
31:182518299918 | 42 | version_cmd.set_defaults(fn=do_versionning) |
The Other Jimmy |
31:182518299918 | 43 | compile_cmd = subparsers.add_parser("compile") |
The Other Jimmy |
31:182518299918 | 44 | compile_cmd.set_defaults(fn=do_compile), |
The Other Jimmy |
31:182518299918 | 45 | compile_cmd.add_argument( |
The Other Jimmy |
31:182518299918 | 46 | "toolchains", nargs="*", default=SUPPORTED_TOOLCHAINS, |
The Other Jimmy |
31:182518299918 | 47 | type=argparse_force_uppercase_type(SUPPORTED_TOOLCHAINS, |
The Other Jimmy |
31:182518299918 | 48 | "toolchain")), |
The Other Jimmy |
31:182518299918 | 49 | compile_cmd.add_argument("-m", "--mcu", |
The Other Jimmy |
31:182518299918 | 50 | help=("build for the given MCU (%s)" % |
The Other Jimmy |
31:182518299918 | 51 | ', '.join(official_target_names)), |
The Other Jimmy |
31:182518299918 | 52 | metavar="MCU", |
The Other Jimmy |
31:182518299918 | 53 | type=argparse_many( |
The Other Jimmy |
31:182518299918 | 54 | argparse_force_uppercase_type( |
The Other Jimmy |
31:182518299918 | 55 | official_target_names, "MCU")), |
The Other Jimmy |
31:182518299918 | 56 | default=official_target_names) |
The Other Jimmy |
31:182518299918 | 57 | export_cmd = subparsers.add_parser("export") |
The Other Jimmy |
31:182518299918 | 58 | export_cmd.set_defaults(fn=do_export), |
The Other Jimmy |
31:182518299918 | 59 | export_cmd.add_argument( |
The Other Jimmy |
31:182518299918 | 60 | "ide", nargs="*", default=SUPPORTED_IDES, |
The Other Jimmy |
31:182518299918 | 61 | type=argparse_force_uppercase_type(SUPPORTED_IDES, |
The Other Jimmy |
31:182518299918 | 62 | "ide")) |
The Other Jimmy |
31:182518299918 | 63 | export_cmd.add_argument("-m", "--mcu", |
The Other Jimmy |
31:182518299918 | 64 | help=("build for the given MCU (%s)" % |
The Other Jimmy |
31:182518299918 | 65 | ', '.join(official_target_names)), |
The Other Jimmy |
31:182518299918 | 66 | metavar="MCU", |
The Other Jimmy |
31:182518299918 | 67 | type=argparse_many( |
The Other Jimmy |
31:182518299918 | 68 | argparse_force_uppercase_type( |
The Other Jimmy |
31:182518299918 | 69 | official_target_names, "MCU")), |
The Other Jimmy |
31:182518299918 | 70 | default=official_target_names) |
The Other Jimmy |
31:182518299918 | 71 | args = parser.parse_args() |
The Other Jimmy |
31:182518299918 | 72 | config = json.load(open(os.path.join(os.path.dirname(__file__), |
The Other Jimmy |
31:182518299918 | 73 | args.config))) |
The Other Jimmy |
31:182518299918 | 74 | |
The Other Jimmy |
31:182518299918 | 75 | all_examples = [] |
The Other Jimmy |
31:182518299918 | 76 | for example in config['examples']: |
The Other Jimmy |
31:182518299918 | 77 | all_examples = all_examples + [basename(x['repo']) for x in lib.get_repo_list(example)] |
The Other Jimmy |
31:182518299918 | 78 | examples = [x for x in all_examples if x in args.example] if args.example else all_examples |
The Other Jimmy |
31:182518299918 | 79 | return args.fn(args, config, examples) |
The Other Jimmy |
31:182518299918 | 80 | |
The Other Jimmy |
31:182518299918 | 81 | |
The Other Jimmy |
31:182518299918 | 82 | def do_export(args, config, examples): |
The Other Jimmy |
31:182518299918 | 83 | """Do export and build step""" |
The Other Jimmy |
31:182518299918 | 84 | results = {} |
The Other Jimmy |
31:182518299918 | 85 | results = lib.export_repos(config, args.ide, args.mcu, examples) |
The Other Jimmy |
31:182518299918 | 86 | |
The Other Jimmy |
31:182518299918 | 87 | lib.print_summary(results, export=True) |
The Other Jimmy |
31:182518299918 | 88 | failures = lib.get_num_failures(results, export=True) |
The Other Jimmy |
31:182518299918 | 89 | print("Number of failures = %d" % failures) |
The Other Jimmy |
31:182518299918 | 90 | return failures |
The Other Jimmy |
31:182518299918 | 91 | |
The Other Jimmy |
31:182518299918 | 92 | |
The Other Jimmy |
31:182518299918 | 93 | def do_import(_, config, examples): |
The Other Jimmy |
31:182518299918 | 94 | """Do the import step of this process""" |
The Other Jimmy |
31:182518299918 | 95 | lib.source_repos(config, examples) |
The Other Jimmy |
31:182518299918 | 96 | return 0 |
The Other Jimmy |
31:182518299918 | 97 | |
The Other Jimmy |
31:182518299918 | 98 | |
The Other Jimmy |
31:182518299918 | 99 | def do_clone(_, config, examples): |
The Other Jimmy |
31:182518299918 | 100 | """Do the clone step of this process""" |
The Other Jimmy |
31:182518299918 | 101 | lib.clone_repos(config, examples) |
The Other Jimmy |
31:182518299918 | 102 | return 0 |
The Other Jimmy |
31:182518299918 | 103 | |
The Other Jimmy |
31:182518299918 | 104 | |
The Other Jimmy |
31:182518299918 | 105 | def do_deploy(_, config, examples): |
The Other Jimmy |
31:182518299918 | 106 | """Do the deploy step of this process""" |
The Other Jimmy |
31:182518299918 | 107 | lib.deploy_repos(config, examples) |
The Other Jimmy |
31:182518299918 | 108 | return 0 |
The Other Jimmy |
31:182518299918 | 109 | |
The Other Jimmy |
31:182518299918 | 110 | |
The Other Jimmy |
31:182518299918 | 111 | def do_compile(args, config, examples): |
The Other Jimmy |
31:182518299918 | 112 | """Do the compile step""" |
The Other Jimmy |
31:182518299918 | 113 | results = {} |
The Other Jimmy |
31:182518299918 | 114 | results = lib.compile_repos(config, args.toolchains, args.mcu, examples) |
The Other Jimmy |
31:182518299918 | 115 | |
The Other Jimmy |
31:182518299918 | 116 | lib.print_summary(results) |
The Other Jimmy |
31:182518299918 | 117 | failures = lib.get_num_failures(results) |
The Other Jimmy |
31:182518299918 | 118 | print("Number of failures = %d" % failures) |
The Other Jimmy |
31:182518299918 | 119 | return failures |
The Other Jimmy |
31:182518299918 | 120 | |
The Other Jimmy |
31:182518299918 | 121 | def do_versionning(args, config, examples): |
The Other Jimmy |
31:182518299918 | 122 | """ Test update the mbed-os to the version specified by the tag """ |
The Other Jimmy |
31:182518299918 | 123 | lib.update_mbedos_version(config, args.tag, examples) |
The Other Jimmy |
31:182518299918 | 124 | return 0 |
The Other Jimmy |
31:182518299918 | 125 | |
The Other Jimmy |
31:182518299918 | 126 | |
The Other Jimmy |
31:182518299918 | 127 | if __name__ == "__main__": |
The Other Jimmy |
31:182518299918 | 128 | sys.exit(main()) |