Maxim mbed development library

Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:0e018d759a2a 1 """ import and bulid a bunch of example programs """
switches 0:0e018d759a2a 2
switches 0:0e018d759a2a 3 from argparse import ArgumentParser
switches 0:0e018d759a2a 4 import os
switches 0:0e018d759a2a 5 from os.path import dirname, abspath, basename
switches 0:0e018d759a2a 6 import os.path
switches 0:0e018d759a2a 7 import sys
switches 0:0e018d759a2a 8 import subprocess
switches 0:0e018d759a2a 9 import json
switches 0:0e018d759a2a 10
switches 0:0e018d759a2a 11 ROOT = abspath(dirname(dirname(dirname(dirname(__file__)))))
switches 0:0e018d759a2a 12 sys.path.insert(0, ROOT)
switches 0:0e018d759a2a 13
switches 0:0e018d759a2a 14 from tools.utils import argparse_force_uppercase_type
switches 0:0e018d759a2a 15 import examples_lib as lib
switches 0:0e018d759a2a 16 from examples_lib import SUPPORTED_TOOLCHAINS, SUPPORTED_IDES
switches 0:0e018d759a2a 17
switches 0:0e018d759a2a 18 EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__),
switches 0:0e018d759a2a 19 "examples.json")))
switches 0:0e018d759a2a 20
switches 0:0e018d759a2a 21
switches 0:0e018d759a2a 22 def main():
switches 0:0e018d759a2a 23 """Entry point"""
switches 0:0e018d759a2a 24 parser = ArgumentParser()
switches 0:0e018d759a2a 25 parser.add_argument("-c", dest="config", default="examples.json")
switches 0:0e018d759a2a 26 subparsers = parser.add_subparsers()
switches 0:0e018d759a2a 27 import_cmd = subparsers.add_parser("import")
switches 0:0e018d759a2a 28 import_cmd.set_defaults(fn=do_import)
switches 0:0e018d759a2a 29 version_cmd = subparsers.add_parser("tag")
switches 0:0e018d759a2a 30 version_cmd.add_argument("tag")
switches 0:0e018d759a2a 31 version_cmd.set_defaults(fn=do_versionning)
switches 0:0e018d759a2a 32 compile_cmd = subparsers.add_parser("compile")
switches 0:0e018d759a2a 33 compile_cmd.set_defaults(fn=do_compile),
switches 0:0e018d759a2a 34 compile_cmd.add_argument(
switches 0:0e018d759a2a 35 "toolchains", nargs="*", default=SUPPORTED_TOOLCHAINS,
switches 0:0e018d759a2a 36 type=argparse_force_uppercase_type(SUPPORTED_TOOLCHAINS,
switches 0:0e018d759a2a 37 "toolchain")),
switches 0:0e018d759a2a 38 export_cmd = subparsers.add_parser("export")
switches 0:0e018d759a2a 39 export_cmd.set_defaults(fn=do_export),
switches 0:0e018d759a2a 40 export_cmd.add_argument(
switches 0:0e018d759a2a 41 "ide", nargs="*", default=SUPPORTED_IDES,
switches 0:0e018d759a2a 42 type=argparse_force_uppercase_type(SUPPORTED_IDES,
switches 0:0e018d759a2a 43 "ide"))
switches 0:0e018d759a2a 44 args = parser.parse_args()
switches 0:0e018d759a2a 45 config = json.load(open(os.path.join(os.path.dirname(__file__),
switches 0:0e018d759a2a 46 args.config)))
switches 0:0e018d759a2a 47 return args.fn(args, config)
switches 0:0e018d759a2a 48
switches 0:0e018d759a2a 49
switches 0:0e018d759a2a 50 def do_export(args, config):
switches 0:0e018d759a2a 51 """Do export and build step"""
switches 0:0e018d759a2a 52 results = {}
switches 0:0e018d759a2a 53 results = lib.export_repos(config, args.ide)
switches 0:0e018d759a2a 54
switches 0:0e018d759a2a 55 lib.print_summary(results, export=True)
switches 0:0e018d759a2a 56 failures = lib.get_num_failures(results, export=True)
switches 0:0e018d759a2a 57 print("Number of failures = %d" % failures)
switches 0:0e018d759a2a 58 return failures
switches 0:0e018d759a2a 59
switches 0:0e018d759a2a 60
switches 0:0e018d759a2a 61 def do_import(_, config):
switches 0:0e018d759a2a 62 """Do the import step of this process"""
switches 0:0e018d759a2a 63 lib.source_repos(config)
switches 0:0e018d759a2a 64 return 0
switches 0:0e018d759a2a 65
switches 0:0e018d759a2a 66
switches 0:0e018d759a2a 67 def do_compile(args, config):
switches 0:0e018d759a2a 68 """Do the compile step"""
switches 0:0e018d759a2a 69 results = {}
switches 0:0e018d759a2a 70 results = lib.compile_repos(config, args.toolchains)
switches 0:0e018d759a2a 71
switches 0:0e018d759a2a 72 lib.print_summary(results)
switches 0:0e018d759a2a 73 failures = lib.get_num_failures(results)
switches 0:0e018d759a2a 74 print("Number of failures = %d" % failures)
switches 0:0e018d759a2a 75 return failures
switches 0:0e018d759a2a 76
switches 0:0e018d759a2a 77 def do_versionning(args, config):
switches 0:0e018d759a2a 78 """ Test update the mbed-os to the version specified by the tag """
switches 0:0e018d759a2a 79 lib.update_mbedos_version(config, args.tag)
switches 0:0e018d759a2a 80 return 0
switches 0:0e018d759a2a 81
switches 0:0e018d759a2a 82
switches 0:0e018d759a2a 83 if __name__ == "__main__":
switches 0:0e018d759a2a 84 sys.exit(main())