Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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