nkjnm

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
nitsshukla
Date:
Fri Nov 04 12:06:04 2016 +0000
Revision:
7:3a65ef12ba31
Parent:
1:55a6170b404f
kghj;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 1:55a6170b404f 1 """ import and bulid a bunch of example programs """
nexpaq 1:55a6170b404f 2
nexpaq 1:55a6170b404f 3 from argparse import ArgumentParser
nexpaq 1:55a6170b404f 4 import os
nexpaq 1:55a6170b404f 5 from os.path import dirname, abspath, basename
nexpaq 1:55a6170b404f 6 import os.path
nexpaq 1:55a6170b404f 7 import sys
nexpaq 1:55a6170b404f 8 import subprocess
nexpaq 1:55a6170b404f 9 import json
nexpaq 1:55a6170b404f 10
nexpaq 1:55a6170b404f 11 ROOT = abspath(dirname(dirname(dirname(dirname(__file__)))))
nexpaq 1:55a6170b404f 12 sys.path.insert(0, ROOT)
nexpaq 1:55a6170b404f 13
nexpaq 1:55a6170b404f 14 from tools.build_api import get_mbed_official_release
nexpaq 1:55a6170b404f 15 from tools.targets import TARGET_MAP
nexpaq 1:55a6170b404f 16 from tools.utils import argparse_force_uppercase_type
nexpaq 1:55a6170b404f 17
nexpaq 1:55a6170b404f 18
nexpaq 1:55a6170b404f 19 EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__),
nexpaq 1:55a6170b404f 20 "examples.json")))
nexpaq 1:55a6170b404f 21
nexpaq 1:55a6170b404f 22 def print_stuff(name, lst):
nexpaq 1:55a6170b404f 23 if lst:
nexpaq 1:55a6170b404f 24 print("#"*80)
nexpaq 1:55a6170b404f 25 print("# {} example combinations".format(name))
nexpaq 1:55a6170b404f 26 print("#")
nexpaq 1:55a6170b404f 27 for thing in lst:
nexpaq 1:55a6170b404f 28 print(thing)
nexpaq 1:55a6170b404f 29
nexpaq 1:55a6170b404f 30
nexpaq 1:55a6170b404f 31 SUPPORTED_TOOLCHAINS = ["ARM", "IAR", "GCC_ARM"]
nexpaq 1:55a6170b404f 32
nexpaq 1:55a6170b404f 33
nexpaq 1:55a6170b404f 34 def target_cross_toolchain(allowed_toolchains,
nexpaq 1:55a6170b404f 35 features=[], targets=TARGET_MAP.keys()):
nexpaq 1:55a6170b404f 36 """Generate pairs of target and toolchains
nexpaq 1:55a6170b404f 37
nexpaq 1:55a6170b404f 38 Args:
nexpaq 1:55a6170b404f 39 allowed_toolchains - a list of all possible toolchains
nexpaq 1:55a6170b404f 40
nexpaq 1:55a6170b404f 41 Kwargs:
nexpaq 1:55a6170b404f 42 features - the features that must be in the features array of a
nexpaq 1:55a6170b404f 43 target
nexpaq 1:55a6170b404f 44 targets - a list of available targets
nexpaq 1:55a6170b404f 45 """
nexpaq 1:55a6170b404f 46 for target, toolchains in get_mbed_official_release("5"):
nexpaq 1:55a6170b404f 47 for toolchain in toolchains:
nexpaq 1:55a6170b404f 48 if (toolchain in allowed_toolchains and
nexpaq 1:55a6170b404f 49 target in targets and
nexpaq 1:55a6170b404f 50 all(feature in TARGET_MAP[target].features
nexpaq 1:55a6170b404f 51 for feature in features)):
nexpaq 1:55a6170b404f 52 yield target, toolchain
nexpaq 1:55a6170b404f 53
nexpaq 1:55a6170b404f 54
nexpaq 1:55a6170b404f 55 def main():
nexpaq 1:55a6170b404f 56 """Entry point"""
nexpaq 1:55a6170b404f 57 parser = ArgumentParser()
nexpaq 1:55a6170b404f 58 subparsers = parser.add_subparsers()
nexpaq 1:55a6170b404f 59 import_cmd = subparsers.add_parser("import")
nexpaq 1:55a6170b404f 60 import_cmd.set_defaults(fn=do_import)
nexpaq 1:55a6170b404f 61 compile_cmd = subparsers.add_parser("compile")
nexpaq 1:55a6170b404f 62 compile_cmd.set_defaults(fn=do_compile)
nexpaq 1:55a6170b404f 63 compile_cmd.add_argument(
nexpaq 1:55a6170b404f 64 "toolchains", nargs="*", default=SUPPORTED_TOOLCHAINS,
nexpaq 1:55a6170b404f 65 type=argparse_force_uppercase_type(SUPPORTED_TOOLCHAINS,
nexpaq 1:55a6170b404f 66 "toolchain"))
nexpaq 1:55a6170b404f 67 args = parser.parse_args()
nexpaq 1:55a6170b404f 68 return args.fn(args)
nexpaq 1:55a6170b404f 69
nexpaq 1:55a6170b404f 70
nexpaq 1:55a6170b404f 71 def do_import(_):
nexpaq 1:55a6170b404f 72 """Do the import step of this process"""
nexpaq 1:55a6170b404f 73 for example, _ in EXAMPLES.iteritems():
nexpaq 1:55a6170b404f 74 subprocess.call(["mbed-cli", "import", example])
nexpaq 1:55a6170b404f 75 return 0
nexpaq 1:55a6170b404f 76
nexpaq 1:55a6170b404f 77
nexpaq 1:55a6170b404f 78 def do_compile(args):
nexpaq 1:55a6170b404f 79 """Do the compile step"""
nexpaq 1:55a6170b404f 80 failures = []
nexpaq 1:55a6170b404f 81 sucesses = []
nexpaq 1:55a6170b404f 82 for example, requirements in EXAMPLES.iteritems():
nexpaq 1:55a6170b404f 83 os.chdir(basename(example))
nexpaq 1:55a6170b404f 84 for target, toolchain in target_cross_toolchain(args.toolchains,
nexpaq 1:55a6170b404f 85 **requirements):
nexpaq 1:55a6170b404f 86 proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain,
nexpaq 1:55a6170b404f 87 "-m", target, "--silent"])
nexpaq 1:55a6170b404f 88 proc.wait()
nexpaq 1:55a6170b404f 89 example_name = "{} {} {}".format(basename(example), target,
nexpaq 1:55a6170b404f 90 toolchain)
nexpaq 1:55a6170b404f 91 if proc.returncode:
nexpaq 1:55a6170b404f 92 failures.append(example_name)
nexpaq 1:55a6170b404f 93 else:
nexpaq 1:55a6170b404f 94 sucesses.append(example_name)
nexpaq 1:55a6170b404f 95 os.chdir("..")
nexpaq 1:55a6170b404f 96
nexpaq 1:55a6170b404f 97 print_stuff("Passed", sucesses)
nexpaq 1:55a6170b404f 98 print_stuff("Failed", failures)
nexpaq 1:55a6170b404f 99 return len(failures)
nexpaq 1:55a6170b404f 100
nexpaq 1:55a6170b404f 101 if __name__ == "__main__":
nexpaq 1:55a6170b404f 102 sys.exit(main())