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