Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
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.build_api import get_mbed_official_release 00015 from tools.targets import TARGET_MAP 00016 from tools.utils import argparse_force_uppercase_type 00017 00018 00019 EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__), 00020 "examples.json"))) 00021 00022 def print_stuff(name, lst): 00023 if lst: 00024 print("#"*80) 00025 print("# {} example combinations".format(name)) 00026 print("#") 00027 for thing in lst: 00028 print(thing) 00029 00030 00031 SUPPORTED_TOOLCHAINS = ["ARM", "IAR", "GCC_ARM"] 00032 00033 00034 def target_cross_toolchain (allowed_toolchains, 00035 features=[], targets=TARGET_MAP.keys()): 00036 """Generate pairs of target and toolchains 00037 00038 Args: 00039 allowed_toolchains - a list of all possible toolchains 00040 00041 Kwargs: 00042 features - the features that must be in the features array of a 00043 target 00044 targets - a list of available targets 00045 """ 00046 for target, toolchains in get_mbed_official_release("5"): 00047 for toolchain in toolchains: 00048 if (toolchain in allowed_toolchains and 00049 target in targets and 00050 all(feature in TARGET_MAP[target].features 00051 for feature in features)): 00052 yield target, toolchain 00053 00054 00055 def main (): 00056 """Entry point""" 00057 parser = ArgumentParser() 00058 subparsers = parser.add_subparsers() 00059 import_cmd = subparsers.add_parser("import") 00060 import_cmd.set_defaults(fn=do_import) 00061 compile_cmd = subparsers.add_parser("compile") 00062 compile_cmd.set_defaults(fn=do_compile) 00063 compile_cmd.add_argument( 00064 "toolchains", nargs="*", default=SUPPORTED_TOOLCHAINS, 00065 type=argparse_force_uppercase_type(SUPPORTED_TOOLCHAINS, 00066 "toolchain")) 00067 args = parser.parse_args() 00068 return args.fn(args) 00069 00070 00071 def do_import (_): 00072 """Do the import step of this process""" 00073 for example, _ in EXAMPLES.iteritems(): 00074 subprocess.call(["mbed-cli", "import", example]) 00075 return 0 00076 00077 00078 def do_compile (args): 00079 """Do the compile step""" 00080 failures = [] 00081 sucesses = [] 00082 for example, requirements in EXAMPLES.iteritems(): 00083 os.chdir(basename(example)) 00084 for target, toolchain in target_cross_toolchain(args.toolchains, 00085 **requirements): 00086 proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain, 00087 "-m", target, "--silent"]) 00088 proc.wait() 00089 example_name = "{} {} {}".format(basename(example), target, 00090 toolchain) 00091 if proc.returncode: 00092 failures.append(example_name) 00093 else: 00094 sucesses.append(example_name) 00095 os.chdir("..") 00096 00097 print_stuff("Passed", sucesses) 00098 print_stuff("Failed", failures) 00099 return len(failures) 00100 00101 if __name__ == "__main__": 00102 sys.exit(main())
Generated on Tue Jul 12 2022 12:28:31 by
