Adding --source and -D iptions on project.py

Marcus Shawcroft 2016-04-05 16:38:34 +01:00
parent dc7df8caeb
commit e74b59cc94
1 changed files with 72 additions and 46 deletions

View File

@ -1,5 +1,5 @@
import sys
from os.path import join, abspath, dirname, exists
from os.path import join, abspath, dirname, exists, basename
ROOT = abspath(join(dirname(__file__), ".."))
sys.path.insert(0, ROOT)
@ -77,6 +77,16 @@ if __name__ == '__main__':
default=False,
help="writes tools/export/README.md")
parser.add_option("--source",
dest="source_dir",
default=None,
help="The source (input) directory")
parser.add_option("-D", "",
action="append",
dest="macros",
help="Add a macro definition")
(options, args) = parser.parse_args()
# Print available tests in order and exit
@ -123,11 +133,22 @@ if __name__ == '__main__':
# Export results
successes = []
failures = []
zip = True
clean = True
for mcu in mcus.split(','):
# Program Number or name
p, n = options.program, options.program_name
p, n, src = options.program, options.program_name, options.source_dir
if src is not None:
# --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
project_name = basename(project_dir)
project_temp = project_dir
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:
if n is not None and p is not None:
args_error(parser, "[ERROR] specify either '-n' or '-p', not both")
if n:
@ -142,6 +163,7 @@ if __name__ == '__main__':
else:
args_error(parser, "[ERROR] Program with name '%s' not found" % n)
p = TEST_MAP[n].n
if p is None or (p < 0) or (p > (len(TESTS)-1)):
message = "[ERROR] You have to specify one of the following tests:\n"
message += '\n'.join(map(str, sorted(TEST_MAP.values())))
@ -157,7 +179,7 @@ if __name__ == '__main__':
# 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 = []
lib_symbols = [] + options.macros
for lib in LIBRARIES:
if lib['build_dir'] in test.dependencies:
lib_macros = lib.get('macros', None)
@ -172,13 +194,17 @@ if __name__ == '__main__':
test.dependencies.append(MBED_BASE)
# Build the project with the same directory structure of the mbed online IDE
project_dir = join(EXPORT_WORKSPACE, test.id)
project_name = test.id
project_dir = join(EXPORT_WORKSPACE, project_name)
project_temp = EXPORT_TMP
setup_user_prj(project_dir, test.source_dir, test.dependencies)
# Export to selected toolchain
tmp_path, report = export(project_dir, test.id, ide, mcu, EXPORT_WORKSPACE, EXPORT_TMP, extra_symbols=lib_symbols)
tmp_path, report = export(project_dir, project_name, ide, mcu, project_dir, project_temp, clean=clean, zip=zip, extra_symbols=lib_symbols)
print tmp_path
if report['success']:
zip_path = join(EXPORT_DIR, "%s_%s_%s.zip" % (test.id, ide, mcu))
zip_path = join(EXPORT_DIR, "%s_%s_%s.zip" % (project_name, ide, mcu))
if zip:
move(tmp_path, zip_path)
successes.append("%s::%s\t%s"% (mcu, ide, zip_path))
else: