Marco Zecchini
/
Example_RTOS
Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
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 00058 compile_cmd.add_argument("--profile", 00059 help=("build profile file"), 00060 metavar="profile") 00061 00062 export_cmd = subparsers.add_parser("export") 00063 export_cmd.set_defaults(fn=do_export), 00064 export_cmd.add_argument( 00065 "ide", nargs="*", default=SUPPORTED_IDES, 00066 type=argparse_force_uppercase_type(SUPPORTED_IDES, 00067 "ide")) 00068 export_cmd.add_argument("-m", "--mcu", 00069 help=("build for the given MCU (%s)" % 00070 ', '.join(official_target_names)), 00071 metavar="MCU", 00072 type=argparse_many( 00073 argparse_force_uppercase_type( 00074 official_target_names, "MCU")), 00075 default=official_target_names) 00076 args = parser.parse_args() 00077 config = json.load(open(os.path.join(os.path.dirname(__file__), 00078 args.config))) 00079 00080 all_examples = [] 00081 for example in config['examples']: 00082 all_examples = all_examples + [basename(x['repo']) for x in lib.get_repo_list(example)] 00083 examples = [x for x in all_examples if x in args.example] if args.example else all_examples 00084 return args.fn(args, config, examples) 00085 00086 00087 def do_export (args, config, examples): 00088 """Do export and build step""" 00089 results = {} 00090 results = lib.export_repos(config, args.ide, args.mcu, examples) 00091 00092 lib.print_summary(results, export=True) 00093 failures = lib.get_num_failures(results, export=True) 00094 print("Number of failures = %d" % failures) 00095 return failures 00096 00097 00098 def do_import (_, config, examples): 00099 """Do the import step of this process""" 00100 lib.source_repos(config, examples) 00101 return 0 00102 00103 00104 def do_clone (_, config, examples): 00105 """Do the clone step of this process""" 00106 lib.clone_repos(config, examples) 00107 return 0 00108 00109 00110 def do_deploy (_, config, examples): 00111 """Do the deploy step of this process""" 00112 lib.deploy_repos(config, examples) 00113 return 0 00114 00115 00116 def do_compile (args, config, examples): 00117 """Do the compile step""" 00118 results = {} 00119 results = lib.compile_repos(config, args.toolchains, args.mcu, args.profile, examples) 00120 00121 lib.print_summary(results) 00122 failures = lib.get_num_failures(results) 00123 print("Number of failures = %d" % failures) 00124 return failures 00125 00126 def do_versionning (args, config, examples): 00127 """ Test update the mbed-os to the version specified by the tag """ 00128 lib.update_mbedos_version(config, args.tag, examples) 00129 return 0 00130 00131 00132 if __name__ == "__main__": 00133 sys.exit(main())
Generated on Sun Jul 17 2022 08:25:22 by 1.7.2