2016-08-29 16:26:37 +00:00
|
|
|
""" import and bulid a bunch of example programs """
|
|
|
|
|
2016-08-31 18:24:59 +00:00
|
|
|
from argparse import ArgumentParser
|
2016-08-29 16:26:37 +00:00
|
|
|
import os
|
2016-08-29 19:38:16 +00:00
|
|
|
from os.path import dirname, abspath, basename
|
2016-08-29 16:26:37 +00:00
|
|
|
import os.path
|
2016-08-29 18:46:39 +00:00
|
|
|
import sys
|
2016-08-29 16:26:37 +00:00
|
|
|
import subprocess
|
2016-08-29 18:46:39 +00:00
|
|
|
import json
|
2016-08-29 16:26:37 +00:00
|
|
|
|
2016-08-29 19:38:16 +00:00
|
|
|
ROOT = abspath(dirname(dirname(dirname(dirname(__file__)))))
|
|
|
|
sys.path.insert(0, ROOT)
|
|
|
|
|
|
|
|
from tools.build_api import get_mbed_official_release
|
|
|
|
from tools.targets import TARGET_MAP
|
2016-08-31 18:24:59 +00:00
|
|
|
from tools.utils import argparse_force_uppercase_type
|
2016-08-29 19:38:16 +00:00
|
|
|
|
2016-08-29 16:26:37 +00:00
|
|
|
|
2016-08-29 18:46:39 +00:00
|
|
|
EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__),
|
|
|
|
"examples.json")))
|
2016-08-29 16:26:37 +00:00
|
|
|
|
2016-08-29 19:38:16 +00:00
|
|
|
def print_stuff(name, lst):
|
2016-08-31 18:24:59 +00:00
|
|
|
if lst:
|
2016-08-29 19:38:16 +00:00
|
|
|
print("#"*80)
|
|
|
|
print("# {} example combinations".format(name))
|
|
|
|
print("#")
|
|
|
|
for thing in lst:
|
|
|
|
print(thing)
|
|
|
|
|
2016-08-29 16:26:37 +00:00
|
|
|
|
2016-08-31 18:24:59 +00:00
|
|
|
SUPPORTED_TOOLCHAINS = ["ARM", "IAR", "GCC_ARM"]
|
|
|
|
|
|
|
|
|
|
|
|
def target_cross_toolchain(required_features, allowed_toolchains):
|
|
|
|
"""Generate pairs of target and toolchains
|
|
|
|
|
|
|
|
Args:
|
|
|
|
required_features - the features that must be in the features array of a
|
|
|
|
target
|
|
|
|
allowed_toolchains - a list of all possible toolchains
|
|
|
|
"""
|
|
|
|
for target, toolchains in get_mbed_official_release("5"):
|
|
|
|
for toolchain in toolchains:
|
|
|
|
if (toolchain in allowed_toolchains and
|
|
|
|
all(feature in TARGET_MAP[target].features
|
|
|
|
for feature in required_features)):
|
|
|
|
yield target, toolchain
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-29 16:26:37 +00:00
|
|
|
def main():
|
|
|
|
"""Entry point"""
|
2016-08-31 18:24:59 +00:00
|
|
|
parser = ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
"toolchains", nargs="*", default=SUPPORTED_TOOLCHAINS,
|
|
|
|
type=argparse_force_uppercase_type(SUPPORTED_TOOLCHAINS,
|
|
|
|
"toolchain"))
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2016-08-29 18:46:39 +00:00
|
|
|
failures = []
|
2016-08-29 19:38:16 +00:00
|
|
|
sucesses = []
|
|
|
|
for example, build_features in EXAMPLES.iteritems():
|
2016-08-29 16:26:37 +00:00
|
|
|
subprocess.call(["mbed-cli", "import", example])
|
2016-08-29 19:38:16 +00:00
|
|
|
os.chdir(basename(example))
|
2016-08-31 18:24:59 +00:00
|
|
|
for target, toolchain in target_cross_toolchain(build_features,
|
|
|
|
args.toolchains):
|
|
|
|
proc = subprocess.Popen(["mbed-cli", "compile", "-t",
|
|
|
|
toolchain, "-m", target])
|
|
|
|
proc.wait()
|
|
|
|
example_name = "{} {} {}".format(basename(example), target,
|
|
|
|
toolchain)
|
|
|
|
if proc.returncode:
|
|
|
|
failures.append(example_name)
|
|
|
|
else:
|
|
|
|
sucesses.append(example_name)
|
2016-08-29 16:26:37 +00:00
|
|
|
os.chdir("..")
|
2016-08-31 18:24:59 +00:00
|
|
|
|
2016-08-29 19:38:16 +00:00
|
|
|
print_stuff("Passed", sucesses)
|
|
|
|
print_stuff("Failed", failures)
|
2016-08-29 18:46:39 +00:00
|
|
|
return len(failures)
|
2016-08-29 16:26:37 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2016-08-29 18:46:39 +00:00
|
|
|
sys.exit(main())
|