ON Semiconductor / mbed-os

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers examples.py Source File

examples.py

00001 """ import and bulid a bunch of example programs """
00002 
00003 from argparse import ArgumentParser
00004 import os
00005 from os.path import dirname, abspath, basename
00006 import os.path
00007 import sys
00008 import subprocess
00009 import json
00010 
00011 ROOT = abspath(dirname(dirname(dirname(dirname(__file__)))))
00012 sys.path.insert(0, ROOT)
00013 
00014 from tools.utils import argparse_force_uppercase_type
00015 from tools.utils import argparse_many
00016 from tools.build_api import get_mbed_official_release
00017 import examples_lib as lib
00018 from examples_lib import SUPPORTED_TOOLCHAINS, SUPPORTED_IDES
00019 
00020 def main ():
00021     """Entry point"""
00022 
00023     official_targets = get_mbed_official_release("5")
00024     official_target_names = [x[0] for x in official_targets]
00025 
00026 
00027     parser = ArgumentParser()
00028     parser.add_argument("-c", dest="config", default="examples.json")
00029     parser.add_argument("-e", "--example",
00030                         help=("filter the examples used in the script"),
00031                         type=argparse_many(lambda x: x),
00032                         default=[])
00033     subparsers = parser.add_subparsers()
00034     import_cmd = subparsers.add_parser("import")
00035     import_cmd.set_defaults(fn=do_import)
00036     clone_cmd = subparsers.add_parser("clone")
00037     clone_cmd.set_defaults(fn=do_clone)
00038     deploy_cmd = subparsers.add_parser("deploy")
00039     deploy_cmd.set_defaults(fn=do_deploy)
00040     version_cmd = subparsers.add_parser("tag")
00041     version_cmd.add_argument("tag")
00042     version_cmd.set_defaults(fn=do_versionning)
00043     compile_cmd = subparsers.add_parser("compile")
00044     compile_cmd.set_defaults(fn=do_compile),
00045     compile_cmd.add_argument(
00046         "toolchains", nargs="*", default=SUPPORTED_TOOLCHAINS,
00047         type=argparse_force_uppercase_type(SUPPORTED_TOOLCHAINS,
00048                                            "toolchain")),
00049     compile_cmd.add_argument("-m", "--mcu",
00050                              help=("build for the given MCU (%s)" %
00051                                 ', '.join(official_target_names)),
00052                             metavar="MCU",
00053                             type=argparse_many(
00054                                 argparse_force_uppercase_type(
00055                                     official_target_names, "MCU")),
00056                             default=official_target_names)
00057     export_cmd = subparsers.add_parser("export")
00058     export_cmd.set_defaults(fn=do_export),
00059     export_cmd.add_argument(
00060         "ide", nargs="*", default=SUPPORTED_IDES,
00061         type=argparse_force_uppercase_type(SUPPORTED_IDES,
00062                                            "ide"))
00063     export_cmd.add_argument("-m", "--mcu",
00064                              help=("build for the given MCU (%s)" %
00065                                 ', '.join(official_target_names)),
00066                             metavar="MCU",
00067                             type=argparse_many(
00068                                 argparse_force_uppercase_type(
00069                                     official_target_names, "MCU")),
00070                             default=official_target_names)
00071     args = parser.parse_args()
00072     config = json.load(open(os.path.join(os.path.dirname(__file__),
00073                                args.config)))
00074 
00075     all_examples = []
00076     for example in config['examples']:
00077         all_examples = all_examples + [basename(x['repo']) for x in lib.get_repo_list(example)]
00078     examples = [x for x in all_examples if x in args.example] if args.example else all_examples
00079     return args.fn(args, config, examples)
00080 
00081 
00082 def do_export (args, config, examples):
00083     """Do export and build step"""
00084     results = {}
00085     results = lib.export_repos(config, args.ide, args.mcu, examples)
00086 
00087     lib.print_summary(results, export=True)
00088     failures = lib.get_num_failures(results, export=True)
00089     print("Number of failures = %d" % failures)
00090     return failures
00091 
00092 
00093 def do_import (_, config, examples):
00094     """Do the import step of this process"""
00095     lib.source_repos(config, examples)
00096     return 0
00097 
00098 
00099 def do_clone (_, config, examples):
00100     """Do the clone step of this process"""
00101     lib.clone_repos(config, examples)
00102     return 0
00103 
00104 
00105 def do_deploy (_, config, examples):
00106     """Do the deploy step of this process"""
00107     lib.deploy_repos(config, examples)
00108     return 0
00109 
00110 
00111 def do_compile (args, config, examples):
00112     """Do the compile step"""
00113     results = {}
00114     results = lib.compile_repos(config, args.toolchains, args.mcu, examples)
00115     
00116     lib.print_summary(results)
00117     failures = lib.get_num_failures(results)
00118     print("Number of failures = %d" % failures)
00119     return failures 
00120     
00121 def do_versionning (args, config, examples):
00122     """ Test update the mbed-os to the version specified by the tag """
00123     lib.update_mbedos_version(config, args.tag, examples)
00124     return 0
00125 
00126 
00127 if __name__ == "__main__":
00128     sys.exit(main())