2013-08-16 15:39:30 +00:00
|
|
|
import sys
|
2016-06-09 22:51:26 +00:00
|
|
|
from os.path import join, abspath, dirname, exists, basename
|
2013-08-16 15:39:30 +00:00
|
|
|
ROOT = abspath(join(dirname(__file__), ".."))
|
2013-12-19 13:02:57 +00:00
|
|
|
sys.path.insert(0, ROOT)
|
2013-08-16 15:39:30 +00:00
|
|
|
|
2014-10-15 21:42:48 +00:00
|
|
|
from shutil import move, rmtree
|
2016-06-24 22:15:01 +00:00
|
|
|
from argparse import ArgumentParser
|
2016-06-09 22:51:26 +00:00
|
|
|
from os import path
|
2013-08-16 15:39:30 +00:00
|
|
|
|
2016-06-09 20:34:53 +00:00
|
|
|
from tools.paths import EXPORT_DIR, EXPORT_WORKSPACE, EXPORT_TMP
|
|
|
|
from tools.paths import MBED_BASE, MBED_LIBRARIES
|
|
|
|
from tools.export import export, setup_user_prj, EXPORTERS, mcu_ide_matrix
|
2016-06-09 22:51:26 +00:00
|
|
|
from tools.utils import args_error, mkdir
|
2016-06-09 20:34:53 +00:00
|
|
|
from tools.tests import TESTS, Test, TEST_MAP
|
2016-06-24 22:15:01 +00:00
|
|
|
from tools.tests import test_known, test_name_known
|
2016-06-09 20:34:53 +00:00
|
|
|
from tools.targets import TARGET_NAMES
|
|
|
|
from tools.libraries import LIBRARIES
|
2016-06-24 22:15:01 +00:00
|
|
|
from utils import argparse_lowercase_type, argparse_uppercase_type, argparse_filestring_type, argparse_many
|
2016-06-29 00:46:22 +00:00
|
|
|
from utils import argparse_force_lowercase_type, argparse_force_uppercase_type
|
2014-11-11 14:56:26 +00:00
|
|
|
|
2013-08-16 15:39:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# Parse Options
|
2016-06-24 22:15:01 +00:00
|
|
|
parser = ArgumentParser()
|
2014-05-29 13:42:03 +00:00
|
|
|
|
2014-10-14 16:04:32 +00:00
|
|
|
targetnames = TARGET_NAMES
|
|
|
|
targetnames.sort()
|
|
|
|
toolchainlist = EXPORTERS.keys()
|
|
|
|
toolchainlist.sort()
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-m", "--mcu",
|
2014-11-11 16:04:59 +00:00
|
|
|
metavar="MCU",
|
|
|
|
default='LPC1768',
|
2016-06-24 22:15:01 +00:00
|
|
|
required=True,
|
2016-06-29 00:46:22 +00:00
|
|
|
type=argparse_many(argparse_force_uppercase_type(targetnames, "MCU")),
|
2014-11-11 16:04:59 +00:00
|
|
|
help="generate project for the given MCU (%s)"% ', '.join(targetnames))
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-i",
|
2014-11-11 16:04:59 +00:00
|
|
|
dest="ide",
|
|
|
|
default='uvision',
|
2016-06-24 22:15:01 +00:00
|
|
|
required=True,
|
2016-06-29 21:17:41 +00:00
|
|
|
type=argparse_force_lowercase_type(toolchainlist, "toolchain"),
|
2014-11-11 16:04:59 +00:00
|
|
|
help="The target IDE: %s"% str(toolchainlist))
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-c", "--clean",
|
2014-11-11 16:04:59 +00:00
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="clean the export directory")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
group = parser.add_mutually_exclusive_group(required=True)
|
|
|
|
group.add_argument("-p",
|
|
|
|
type=test_known,
|
2014-11-11 16:04:59 +00:00
|
|
|
dest="program",
|
|
|
|
help="The index of the desired test program: [0-%d]"% (len(TESTS)-1))
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
group.add_argument("-n",
|
|
|
|
type=test_name_known,
|
|
|
|
dest="program",
|
2014-11-11 16:04:59 +00:00
|
|
|
help="The name of the desired test program")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-b",
|
2014-11-11 16:04:59 +00:00
|
|
|
dest="build",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="use the mbed library build, instead of the sources")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
group.add_argument("-L", "--list-tests",
|
2014-11-11 16:04:59 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="list_tests",
|
|
|
|
default=False,
|
|
|
|
help="list available programs in order and exit")
|
2014-10-14 16:04:32 +00:00
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
group.add_argument("-S", "--list-matrix",
|
2014-12-30 18:26:43 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="supported_ides",
|
|
|
|
default=False,
|
|
|
|
help="displays supported matrix of MCUs and IDEs")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-E",
|
2014-12-30 18:26:43 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="supported_ides_html",
|
|
|
|
default=False,
|
2016-06-09 20:40:54 +00:00
|
|
|
help="writes tools/export/README.md")
|
2014-12-30 18:26:43 +00:00
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
group.add_argument("--source",
|
|
|
|
nargs="*",
|
|
|
|
type=argparse_filestring_type,
|
2016-06-09 22:51:26 +00:00
|
|
|
dest="source_dir",
|
2016-06-24 22:15:01 +00:00
|
|
|
default=[],
|
2016-06-09 22:51:26 +00:00
|
|
|
help="The source (input) directory")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-D",
|
|
|
|
nargs="*",
|
2016-06-09 22:51:26 +00:00
|
|
|
dest="macros",
|
|
|
|
help="Add a macro definition")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
options = parser.parse_args()
|
2014-05-29 13:42:03 +00:00
|
|
|
|
2014-10-14 16:04:32 +00:00
|
|
|
# Print available tests in order and exit
|
|
|
|
if options.list_tests is True:
|
|
|
|
print '\n'.join(map(str, sorted(TEST_MAP.values())))
|
|
|
|
sys.exit()
|
2014-10-16 10:45:46 +00:00
|
|
|
|
2014-12-30 18:26:43 +00:00
|
|
|
# Only prints matrix of supported IDEs
|
|
|
|
if options.supported_ides:
|
|
|
|
print mcu_ide_matrix()
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
# Only prints matrix of supported IDEs
|
|
|
|
if options.supported_ides_html:
|
|
|
|
html = mcu_ide_matrix(verbose_html=True)
|
|
|
|
try:
|
2015-01-27 09:50:51 +00:00
|
|
|
with open("./export/README.md","w") as f:
|
2015-01-26 16:43:08 +00:00
|
|
|
f.write("Exporter IDE/Platform Support\n")
|
|
|
|
f.write("-----------------------------------\n")
|
2015-01-27 09:50:51 +00:00
|
|
|
f.write("\n")
|
2015-01-26 16:43:08 +00:00
|
|
|
f.write(html)
|
|
|
|
except IOError as e:
|
|
|
|
print "I/O error({0}): {1}".format(e.errno, e.strerror)
|
|
|
|
except:
|
|
|
|
print "Unexpected error:", sys.exc_info()[0]
|
|
|
|
raise
|
2014-12-30 18:26:43 +00:00
|
|
|
exit(0)
|
|
|
|
|
2014-10-15 21:42:48 +00:00
|
|
|
# Clean Export Directory
|
|
|
|
if options.clean:
|
|
|
|
if exists(EXPORT_DIR):
|
|
|
|
rmtree(EXPORT_DIR)
|
2014-10-14 16:04:32 +00:00
|
|
|
|
2014-11-11 16:04:59 +00:00
|
|
|
# Export results
|
|
|
|
successes = []
|
|
|
|
failures = []
|
2016-06-09 22:51:26 +00:00
|
|
|
zip = True
|
|
|
|
clean = True
|
|
|
|
|
|
|
|
# source_dir = use relative paths, otherwise sources are copied
|
|
|
|
sources_relative = True if options.source_dir else False
|
2014-11-11 16:04:59 +00:00
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
for mcu in options.mcu:
|
2014-11-11 16:04:59 +00:00
|
|
|
# Program Number or name
|
2016-06-29 21:17:41 +00:00
|
|
|
p, src, ide = options.program, options.source_dir, options.ide
|
2016-06-09 22:51:26 +00:00
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
if src:
|
2016-06-09 22:51:26 +00:00
|
|
|
# --source is used to generate IDE files to toolchain directly in the source tree and doesn't generate zip file
|
|
|
|
project_dir = options.source_dir
|
2016-06-24 22:15:01 +00:00
|
|
|
project_name = TESTS[p]
|
2016-06-27 15:16:46 +00:00
|
|
|
project_temp = path.join(options.source_dir[0], 'projectfiles', '%s_%s' % (ide, mcu))
|
2016-06-09 22:51:26 +00:00
|
|
|
mkdir(project_temp)
|
|
|
|
lib_symbols = []
|
|
|
|
if options.macros:
|
|
|
|
lib_symbols += options.macros
|
|
|
|
zip = False # don't create zip
|
|
|
|
clean = False # don't cleanup because we use the actual source tree to generate IDE files
|
|
|
|
else:
|
|
|
|
test = Test(p)
|
|
|
|
|
|
|
|
# Some libraries have extra macros (called by exporter symbols) to we need to pass
|
|
|
|
# them to maintain compilation macros integrity between compiled library and
|
|
|
|
# header files we might use with it
|
|
|
|
lib_symbols = []
|
|
|
|
if options.macros:
|
|
|
|
lib_symbols += options.macros
|
|
|
|
for lib in LIBRARIES:
|
|
|
|
if lib['build_dir'] in test.dependencies:
|
|
|
|
lib_macros = lib.get('macros', None)
|
|
|
|
if lib_macros is not None:
|
|
|
|
lib_symbols.extend(lib_macros)
|
|
|
|
|
|
|
|
if not options.build:
|
|
|
|
# Substitute the library builds with the sources
|
|
|
|
# TODO: Substitute also the other library build paths
|
|
|
|
if MBED_LIBRARIES in test.dependencies:
|
|
|
|
test.dependencies.remove(MBED_LIBRARIES)
|
|
|
|
test.dependencies.append(MBED_BASE)
|
|
|
|
|
|
|
|
# Build the project with the same directory structure of the mbed online IDE
|
|
|
|
project_name = test.id
|
2016-06-13 09:13:09 +00:00
|
|
|
project_dir = [join(EXPORT_WORKSPACE, project_name)]
|
2016-06-09 22:51:26 +00:00
|
|
|
project_temp = EXPORT_TMP
|
2016-06-13 09:13:09 +00:00
|
|
|
setup_user_prj(project_dir[0], test.source_dir, test.dependencies)
|
2014-11-11 16:04:59 +00:00
|
|
|
|
|
|
|
# Export to selected toolchain
|
2016-06-29 21:17:41 +00:00
|
|
|
tmp_path, report = export(project_dir, project_name, ide, mcu, project_dir[0], project_temp, clean=clean, make_zip=zip, extra_symbols=lib_symbols, sources_relative=sources_relative)
|
|
|
|
if report['success']:
|
|
|
|
if not zip:
|
|
|
|
zip_path = join(project_temp, project_name)
|
2016-06-15 17:40:06 +00:00
|
|
|
else:
|
2016-06-29 21:17:41 +00:00
|
|
|
zip_path = join(EXPORT_DIR, "%s_%s_%s.zip" % (project_name, ide, mcu))
|
|
|
|
move(tmp_path, zip_path)
|
|
|
|
successes.append("%s::%s\t%s"% (mcu, ide, zip_path))
|
|
|
|
else:
|
|
|
|
failures.append("%s::%s\t%s"% (mcu, ide, report['errormsg']))
|
2014-11-11 16:04:59 +00:00
|
|
|
|
|
|
|
# Prints export results
|
|
|
|
print
|
|
|
|
if len(successes) > 0:
|
|
|
|
print "Successful exports:"
|
|
|
|
for success in successes:
|
|
|
|
print " * %s"% success
|
|
|
|
if len(failures) > 0:
|
|
|
|
print "Failed exports:"
|
|
|
|
for failure in failures:
|
|
|
|
print " * %s"% failure
|