mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

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