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)
|
|
|
|
|
2016-08-31 18:24:59 +00:00
|
|
|
from tools.utils import argparse_force_uppercase_type
|
2016-10-17 15:56:28 +00:00
|
|
|
import examples_lib as lib
|
2016-11-01 20:46:51 +00:00
|
|
|
from examples_lib import SUPPORTED_TOOLCHAINS, SUPPORTED_IDES
|
2016-10-31 21:00:15 +00:00
|
|
|
|
|
|
|
EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__),
|
|
|
|
"examples.json")))
|
|
|
|
|
2016-08-31 18:24:59 +00:00
|
|
|
|
2016-08-29 16:26:37 +00:00
|
|
|
def main():
|
|
|
|
"""Entry point"""
|
2016-08-31 18:24:59 +00:00
|
|
|
parser = ArgumentParser()
|
2016-10-17 15:56:28 +00:00
|
|
|
parser.add_argument("-c", dest="config", default="examples.json")
|
2016-08-31 20:16:09 +00:00
|
|
|
subparsers = parser.add_subparsers()
|
|
|
|
import_cmd = subparsers.add_parser("import")
|
|
|
|
import_cmd.set_defaults(fn=do_import)
|
2016-11-04 22:35:36 +00:00
|
|
|
clone_cmd = subparsers.add_parser("clone")
|
|
|
|
clone_cmd.set_defaults(fn=do_clone)
|
|
|
|
deploy_cmd = subparsers.add_parser("deploy")
|
|
|
|
deploy_cmd.set_defaults(fn=do_deploy)
|
2016-10-17 15:56:28 +00:00
|
|
|
version_cmd = subparsers.add_parser("tag")
|
|
|
|
version_cmd.add_argument("tag")
|
|
|
|
version_cmd.set_defaults(fn=do_versionning)
|
2016-08-31 20:16:09 +00:00
|
|
|
compile_cmd = subparsers.add_parser("compile")
|
2016-10-31 21:00:15 +00:00
|
|
|
compile_cmd.set_defaults(fn=do_compile),
|
2016-08-31 20:16:09 +00:00
|
|
|
compile_cmd.add_argument(
|
2016-08-31 18:24:59 +00:00
|
|
|
"toolchains", nargs="*", default=SUPPORTED_TOOLCHAINS,
|
|
|
|
type=argparse_force_uppercase_type(SUPPORTED_TOOLCHAINS,
|
2016-10-31 21:00:15 +00:00
|
|
|
"toolchain")),
|
|
|
|
export_cmd = subparsers.add_parser("export")
|
|
|
|
export_cmd.set_defaults(fn=do_export),
|
|
|
|
export_cmd.add_argument(
|
|
|
|
"ide", nargs="*", default=SUPPORTED_IDES,
|
|
|
|
type=argparse_force_uppercase_type(SUPPORTED_IDES,
|
|
|
|
"ide"))
|
2016-08-31 18:24:59 +00:00
|
|
|
args = parser.parse_args()
|
2016-10-17 15:56:28 +00:00
|
|
|
config = json.load(open(os.path.join(os.path.dirname(__file__),
|
|
|
|
args.config)))
|
|
|
|
return args.fn(args, config)
|
2016-08-31 20:16:09 +00:00
|
|
|
|
2016-10-31 21:00:15 +00:00
|
|
|
|
2016-11-01 20:46:51 +00:00
|
|
|
def do_export(args, config):
|
2016-10-31 21:47:27 +00:00
|
|
|
"""Do export and build step"""
|
2016-11-01 20:46:51 +00:00
|
|
|
results = {}
|
|
|
|
results = lib.export_repos(config, args.ide)
|
|
|
|
|
|
|
|
lib.print_summary(results, export=True)
|
|
|
|
failures = lib.get_num_failures(results, export=True)
|
|
|
|
print("Number of failures = %d" % failures)
|
|
|
|
return failures
|
2016-10-31 21:00:15 +00:00
|
|
|
|
|
|
|
|
2016-10-17 15:56:28 +00:00
|
|
|
def do_import(_, config):
|
2016-08-31 20:16:09 +00:00
|
|
|
"""Do the import step of this process"""
|
2016-10-17 15:56:28 +00:00
|
|
|
lib.source_repos(config)
|
2016-09-01 21:01:12 +00:00
|
|
|
return 0
|
2016-08-31 20:16:09 +00:00
|
|
|
|
2016-11-01 20:46:51 +00:00
|
|
|
|
2016-11-04 22:35:36 +00:00
|
|
|
def do_clone(_, config):
|
|
|
|
"""Do the clone step of this process"""
|
|
|
|
lib.clone_repos(config)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
def do_deploy(_, config):
|
|
|
|
"""Do the deploy step of this process"""
|
|
|
|
lib.deploy_repos(config)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2016-10-17 15:56:28 +00:00
|
|
|
def do_compile(args, config):
|
2016-08-31 20:16:09 +00:00
|
|
|
"""Do the compile step"""
|
2016-10-17 15:56:28 +00:00
|
|
|
results = {}
|
|
|
|
results = lib.compile_repos(config, args.toolchains)
|
|
|
|
|
2016-11-01 20:46:51 +00:00
|
|
|
lib.print_summary(results)
|
2016-10-17 15:56:28 +00:00
|
|
|
failures = lib.get_num_failures(results)
|
|
|
|
print("Number of failures = %d" % failures)
|
|
|
|
return failures
|
|
|
|
|
|
|
|
def do_versionning(args, config):
|
|
|
|
""" Test update the mbed-os to the version specified by the tag """
|
|
|
|
lib.update_mbedos_version(config, args.tag)
|
|
|
|
return 0
|
2016-08-31 18:24:59 +00:00
|
|
|
|
2016-08-29 16:26:37 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2016-08-29 18:46:39 +00:00
|
|
|
sys.exit(main())
|