[Exporter tests] Implement filtering of targets and examples.

pull/3206/head
Sarah Marsh 2016-11-04 15:48:02 -05:00
parent 811e2b55e6
commit 4e2d3c42dd
2 changed files with 38 additions and 31 deletions

View File

@ -32,7 +32,8 @@ def main():
parser.add_argument("-c", dest="config", default="examples.json") parser.add_argument("-c", dest="config", default="examples.json")
parser.add_argument("-e", "--example", parser.add_argument("-e", "--example",
help=("filter the examples used in the script"), help=("filter the examples used in the script"),
type=argparse_many() type=argparse_many(lambda x: x),
default = EXAMPLES.keys())
subparsers = parser.add_subparsers() subparsers = parser.add_subparsers()
import_cmd = subparsers.add_parser("import") import_cmd = subparsers.add_parser("import")
import_cmd.set_defaults(fn=do_import) import_cmd.set_defaults(fn=do_import)
@ -55,7 +56,8 @@ def main():
metavar="MCU", metavar="MCU",
type=argparse_many( type=argparse_many(
argparse_force_uppercase_type( argparse_force_uppercase_type(
official_target_names, "MCU"))) official_target_names, "MCU")),
default=official_target_names)
export_cmd = subparsers.add_parser("export") export_cmd = subparsers.add_parser("export")
export_cmd.set_defaults(fn=do_export), export_cmd.set_defaults(fn=do_export),
export_cmd.add_argument( export_cmd.add_argument(
@ -68,7 +70,8 @@ def main():
metavar="MCU", metavar="MCU",
type=argparse_many( type=argparse_many(
argparse_force_uppercase_type( argparse_force_uppercase_type(
official_target_names, "MCU"))) official_target_names, "MCU")),
default=official_target_names)
args = parser.parse_args() args = parser.parse_args()
config = json.load(open(os.path.join(os.path.dirname(__file__), config = json.load(open(os.path.join(os.path.dirname(__file__),
args.config))) args.config)))
@ -78,7 +81,7 @@ def main():
def do_export(args, config): def do_export(args, config):
"""Do export and build step""" """Do export and build step"""
results = {} results = {}
results = lib.export_repos(config, args.ide) results = lib.export_repos(config, args.ide, args.mcu, args.example)
lib.print_summary(results, export=True) lib.print_summary(results, export=True)
failures = lib.get_num_failures(results, export=True) failures = lib.get_num_failures(results, export=True)
@ -107,7 +110,7 @@ def do_deploy(_, config):
def do_compile(args, config): def do_compile(args, config):
"""Do the compile step""" """Do the compile step"""
results = {} results = {}
results = lib.compile_repos(config, args.toolchains) results = lib.compile_repos(config, args.toolchains, args.mcu, args.example)
lib.print_summary(results) lib.print_summary(results)
failures = lib.get_num_failures(results) failures = lib.get_num_failures(results)

View File

@ -228,35 +228,36 @@ def get_num_failures(results, export=False):
return num_failures return num_failures
def export_repos(config, ides, targets, examples):
def export_repos(config, ides):
"""Exports and builds combinations of example programs, targets and IDEs. """Exports and builds combinations of example programs, targets and IDEs.
The results are returned in a [key: value] dictionary format: The results are returned in a [key: value] dictionary format:
Where key = The example name from the json config file Where key = The example name from the json config file
value = a list containing: pass_status, successes, export failures, build_failures, value = a list containing: pass_status, successes, export failures, build_failures,
and build_skips and build_skips
where pass_status = The overall pass status for the export of the full where pass_status = The overall pass status for the export of the full
set of example programs comprising the example suite. set of example programs comprising the example suite.
(IE they must build and export) IE they must build and export) True if all examples pass, false otherwise
True if all examples pass, false otherwise successes = list of examples that exported and built (if possible)
successes = list of examples that exported and built (if possible) If the exporter has no build functionality, then it is a pass
If the exporter has no build functionality, then it is a pass if exported
if exported export_failures = list of examples that failed to export.
export_failures = list of examples that failed to export. build_failures = list of examples that failed to build
build_failures = list of examples that failed to build build_skips = list of examples that cannot build
build_skips = list of examples that cannot build
Both successes and failures contain the example name, target and IDE Both successes and failures contain the example name, target and IDE
Args: Args:
config - the json object imported from the file. config - the json object imported from the file.
ides - List of IDES to export to ides - List of IDES to export to
""" """
results = {} results = {}
print("\nExporting example repos....\n") print("\nExporting example repos....\n")
for example in config['examples']: for example in config['examples']:
if example['name'] not in examples:
continue
export_failures = [] export_failures = []
build_failures = [] build_failures = []
build_skips = [] build_skips = []
@ -271,7 +272,7 @@ def export_repos(config, ides):
# list of valid combinations to work through # list of valid combinations to work through
for target, ide in target_cross_ide(ides, for target, ide in target_cross_ide(ides,
example['features'], example['features'],
example['targets']): example['targets'] or targets):
example_name = "{} {} {}".format(example_project_name, target, example_name = "{} {} {}".format(example_project_name, target,
ide) ide)
def status(message): def status(message):
@ -311,7 +312,7 @@ def export_repos(config, ides):
return results return results
def compile_repos(config, toolchains): def compile_repos(config, toolchains, targets, examples):
"""Compiles combinations of example programs, targets and compile chains. """Compiles combinations of example programs, targets and compile chains.
The results are returned in a [key: value] dictionary format: The results are returned in a [key: value] dictionary format:
@ -334,7 +335,9 @@ def compile_repos(config, toolchains):
""" """
results = {} results = {}
print("\nCompiling example repos....\n") print("\nCompiling example repos....\n")
for example in config['examples']: for example in config['examples']:
if example['name'] not in examples:
continue
failures = [] failures = []
successes = [] successes = []
compiled = True compiled = True
@ -350,7 +353,8 @@ def compile_repos(config, toolchains):
# Check that the target, toolchain and features combinations are valid and return a # Check that the target, toolchain and features combinations are valid and return a
# list of valid combinations to work through # list of valid combinations to work through
for target, toolchain in target_cross_toolchain(toolchains, for target, toolchain in target_cross_toolchain(toolchains,
example['features'], example['targets']): example['features'],
example['targets'] or targets):
proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain, proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain,
"-m", target, "--silent"]) "-m", target, "--silent"])
proc.wait() proc.wait()
@ -372,7 +376,7 @@ def compile_repos(config, toolchains):
return results return results
def update_mbedos_version(config, tag): def update_mbedos_version(config, tag, example):
""" For each example repo identified in the config json object, update the version of """ For each example repo identified in the config json object, update the version of
mbed-os to that specified by the supplied GitHub tag. This function assumes that each mbed-os to that specified by the supplied GitHub tag. This function assumes that each
example repo has already been cloned. example repo has already been cloned.