the other jimmy / mbed-sdk-tools

Fork of mbed-sdk-tools by mbed official

Committer:
The Other Jimmy
Date:
Wed Jan 04 11:58:24 2017 -0600
Revision:
32:8ea194f6145b
Update tools to follow mbed-os tools release 5.3.1

Who changed what in which revision?

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