Correcting example, toolchain, and ide filters

pull/3206/head
Brian Daniels 2016-11-07 16:26:27 -06:00
parent 4bfd73a661
commit b739413526
2 changed files with 63 additions and 72 deletions

View File

@ -17,10 +17,6 @@ from tools.build_api import get_mbed_official_release
import examples_lib as lib
from examples_lib import SUPPORTED_TOOLCHAINS, SUPPORTED_IDES
EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__),
"examples.json")))
def main():
"""Entry point"""
@ -33,7 +29,7 @@ def main():
parser.add_argument("-e", "--example",
help=("filter the examples used in the script"),
type=argparse_many(lambda x: x),
default = EXAMPLES.keys())
default=[])
subparsers = parser.add_subparsers()
import_cmd = subparsers.add_parser("import")
import_cmd.set_defaults(fn=do_import)
@ -75,13 +71,18 @@ def main():
args = parser.parse_args()
config = json.load(open(os.path.join(os.path.dirname(__file__),
args.config)))
return args.fn(args, config)
all_examples = []
for example in config['examples']:
all_examples = all_examples + [basename(x['repo']) for x in lib.get_repo_list(example)]
examples = [x for x in all_examples if x in args.example] if args.example else all_examples
return args.fn(args, config, examples)
def do_export(args, config):
def do_export(args, config, examples):
"""Do export and build step"""
results = {}
results = lib.export_repos(config, args.ide, args.mcu, args.example)
results = lib.export_repos(config, args.ide, args.mcu, examples)
lib.print_summary(results, export=True)
failures = lib.get_num_failures(results, export=True)
@ -89,37 +90,37 @@ def do_export(args, config):
return failures
def do_import(_, config):
def do_import(args, config, examples):
"""Do the import step of this process"""
lib.source_repos(config)
lib.source_repos(config, examples)
return 0
def do_clone(_, config):
def do_clone(args, config, examples):
"""Do the clone step of this process"""
lib.clone_repos(config)
lib.clone_repos(config, examples)
return 0
def do_deploy(_, config):
def do_deploy(args, config, examples):
"""Do the deploy step of this process"""
lib.deploy_repos(config)
lib.deploy_repos(config, examples)
return 0
def do_compile(args, config):
def do_compile(args, config, examples):
"""Do the compile step"""
results = {}
results = lib.compile_repos(config, args.toolchains, args.mcu, args.example)
results = lib.compile_repos(config, args.toolchains, args.mcu, examples)
lib.print_summary(results)
failures = lib.get_num_failures(results)
print("Number of failures = %d" % failures)
return failures
def do_versionning(args, config):
def do_versionning(args, config, examples):
""" Test update the mbed-os to the version specified by the tag """
lib.update_mbedos_version(config, args.tag, args.example)
lib.update_mbedos_version(config, args.tag, examples)
return 0

View File

@ -76,57 +76,48 @@ def print_summary(results, export=False):
print("#")
print("#"*80)
def valid_targets(allowed_targets, targets):
if len(allowed_targets) > 0:
return [t for t in targets if t in allowed_targets]
def valid_choices(allowed_choices, all_choices):
if len(allowed_choices) > 0:
return [t for t in all_choices if t in allowed_choices]
else:
return targets
return all_choices
def target_cross_toolchain(allowed_toolchains,
features=[], targets=[]):
def target_cross_toolchain(allowed_targets, allowed_toolchains, features=[]):
"""Generate pairs of target and toolchains
Args:
allowed_targets - a list of all possible targets
allowed_toolchains - a list of all possible toolchains
Kwargs:
features - the features that must be in the features array of a
target
targets - a list of available targets
"""
if len(targets) == 0:
targets=TARGET_MAP.keys()
for target, toolchains in get_mbed_official_release("5"):
for toolchain in toolchains:
if (toolchain in allowed_toolchains and
target in targets and
all(feature in TARGET_MAP[target].features
for feature in features)):
for target in allowed_targets:
for toolchain in allowed_toolchains:
if all(feature in TARGET_MAP[target].features
for feature in features):
yield target, toolchain
def target_cross_ide(allowed_ides,
features=[], targets=[]):
def target_cross_ide(allowed_targets, allowed_ides, features=[]):
"""Generate pairs of target and ides
Args:
allowed_targets - a list of all possible targets
allowed_ides - a list of all possible IDEs
Kwargs:
features - the features that must be in the features array of a
target
targets - a list of available targets
"""
if len(targets) == 0:
targets=TARGET_MAP.keys()
for target, toolchains in get_mbed_official_release("5"):
for target in allowed_targets:
for ide in allowed_ides:
if (EXPORTERS[ide].TOOLCHAIN in toolchains and
target in EXPORTERS[ide].TARGETS and
target in targets and
if all(feature in TARGET_MAP[target].features
for feature in features):
yield target, toolchain
if (target in EXPORTERS[ide].TARGETS and
all(feature in TARGET_MAP[target].features
for feature in features)):
yield target, ide
@ -160,7 +151,7 @@ def get_repo_list(example):
return repos
def source_repos(config):
def source_repos(config, examples):
""" Imports each of the repos and its dependencies (.lib files) associated
with the specific examples name from the json config file. Note if
there is already a clone of the repo then it will first be removed to
@ -173,13 +164,14 @@ def source_repos(config):
for example in config['examples']:
for repo_info in get_repo_list(example):
name = basename(repo_info['repo'])
if os.path.exists(name):
print("'%s' example directory already exists. Deleting..." % name)
rmtree(name)
subprocess.call(["mbed-cli", "import", repo_info['repo']])
if name in examples:
if os.path.exists(name):
print("'%s' example directory already exists. Deleting..." % name)
rmtree(name)
def clone_repos(config):
subprocess.call(["mbed-cli", "import", repo_info['repo']])
def clone_repos(config, examples):
""" Clones each of the repos associated with the specific examples name from the
json config file. Note if there is already a clone of the repo then it will first
be removed to ensure a clean, up to date cloning.
@ -191,13 +183,14 @@ def clone_repos(config):
for example in config['examples']:
for repo_info in get_repo_list(example):
name = basename(repo_info['repo'])
if os.path.exists(name):
print("'%s' example directory already exists. Deleting..." % name)
rmtree(name)
if name in examples:
if os.path.exists(name):
print("'%s' example directory already exists. Deleting..." % name)
rmtree(name)
subprocess.call([repo_info['type'], "clone", repo_info['repo']])
subprocess.call([repo_info['type'], "clone", repo_info['repo']])
def deploy_repos(config):
def deploy_repos(config, examples):
""" If the example directory exists as provided by the json config file,
pull in the examples dependencies by using `mbed-cli deploy`.
Args:
@ -208,13 +201,13 @@ def deploy_repos(config):
for example in config['examples']:
for repo_info in get_repo_list(example):
name = basename(repo_info['repo'])
if os.path.exists(name):
os.chdir(name)
subprocess.call(["mbed-cli", "deploy"])
os.chdir("..")
else:
print("'%s' example directory doesn't exist. Skipping..." % name)
if name in examples:
if os.path.exists(name):
os.chdir(name)
subprocess.call(["mbed-cli", "deploy"])
os.chdir("..")
else:
print("'%s' example directory doesn't exist. Skipping..." % name)
def get_num_failures(results, export=False):
@ -276,9 +269,9 @@ def export_repos(config, ides, targets, examples):
os.chdir(example_project_name)
# Check that the target, IDE, and features combinations are valid and return a
# list of valid combinations to work through
for target, ide in target_cross_ide(ides,
example['features'],
valid_targets(example['targets'],targets)):
for target, ide in target_cross_ide(valid_choices(example['targets'], targets),
valid_choices(example['exporters'], ides),
example['features']):
example_name = "{} {} {}".format(example_project_name, target,
ide)
def status(message):
@ -349,18 +342,15 @@ def compile_repos(config, toolchains, targets, examples):
compiled = True
pass_status = True
if example['compile']:
if len(example['toolchains']) > 0:
toolchains = example['toolchains']
for repo_info in get_repo_list(example):
name = basename(repo_info['repo'])
os.chdir(name)
# Check that the target, toolchain and features combinations are valid and return a
# list of valid combinations to work through
for target, toolchain in target_cross_toolchain(toolchains,
example['features'],
valid_targets(example['targets'],targets)):
for target, toolchain in target_cross_toolchain(valid_choices(example['targets'], targets),
valid_choices(example['toolchains'], toolchains),
example['features']):
proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain,
"-m", target, "--silent"])
proc.wait()