mirror of https://github.com/ARMmbed/mbed-os.git
Modified exporters so they support extra macros from external libraries like CppUTest library
parent
cce551af35
commit
66cd258254
|
@ -50,7 +50,8 @@ def online_build_url_resolver(url):
|
||||||
return {'path':'', 'name':''}
|
return {'path':'', 'name':''}
|
||||||
|
|
||||||
|
|
||||||
def export(project_path, project_name, ide, target, destination='/tmp/', tempdir=None, clean=True, build_url_resolver=online_build_url_resolver):
|
def export(project_path, project_name, ide, target, destination='/tmp/',
|
||||||
|
tempdir=None, clean=True, extra_symbols=None, build_url_resolver=online_build_url_resolver):
|
||||||
# Convention: we are using capitals for toolchain and target names
|
# Convention: we are using capitals for toolchain and target names
|
||||||
if target is not None:
|
if target is not None:
|
||||||
target = target.upper()
|
target = target.upper()
|
||||||
|
@ -75,7 +76,7 @@ def export(project_path, project_name, ide, target, destination='/tmp/', tempdir
|
||||||
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
|
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
exporter = Exporter(target, tempdir, project_name, build_url_resolver)
|
exporter = Exporter(target, tempdir, project_name, build_url_resolver, extra_symbols=extra_symbols)
|
||||||
exporter.scan_and_copy_resources(project_path, tempdir)
|
exporter.scan_and_copy_resources(project_path, tempdir)
|
||||||
exporter.generate()
|
exporter.generate()
|
||||||
report['success'] = True
|
report['success'] = True
|
||||||
|
|
|
@ -48,7 +48,7 @@ class CodeRed(Exporter):
|
||||||
'linker_script': self.resources.linker_script,
|
'linker_script': self.resources.linker_script,
|
||||||
'object_files': self.resources.objects,
|
'object_files': self.resources.objects,
|
||||||
'libraries': libraries,
|
'libraries': libraries,
|
||||||
'symbols': self.toolchain.get_symbols()
|
'symbols': self.get_symbols()
|
||||||
}
|
}
|
||||||
self.gen_file('codered_%s_project.tmpl' % self.target.lower(), ctx, '.project')
|
self.gen_file('codered_%s_project.tmpl' % self.target.lower(), ctx, '.project')
|
||||||
self.gen_file('codered_%s_cproject.tmpl' % self.target.lower(), ctx, '.cproject')
|
self.gen_file('codered_%s_cproject.tmpl' % self.target.lower(), ctx, '.cproject')
|
||||||
|
|
|
@ -55,6 +55,6 @@ class CodeSourcery(Exporter):
|
||||||
'library_paths': self.resources.lib_dirs,
|
'library_paths': self.resources.lib_dirs,
|
||||||
'linker_script': self.resources.linker_script,
|
'linker_script': self.resources.linker_script,
|
||||||
'libraries': libraries,
|
'libraries': libraries,
|
||||||
'symbols': self.toolchain.get_symbols()
|
'symbols': self.get_symbols()
|
||||||
}
|
}
|
||||||
self.gen_file('codesourcery_%s.tmpl' % self.target.lower(), ctx, 'Makefile')
|
self.gen_file('codesourcery_%s.tmpl' % self.target.lower(), ctx, 'Makefile')
|
||||||
|
|
|
@ -77,7 +77,7 @@ class CoIDE(Exporter):
|
||||||
'library_paths': self.resources.lib_dirs,
|
'library_paths': self.resources.lib_dirs,
|
||||||
'object_files': self.resources.objects,
|
'object_files': self.resources.objects,
|
||||||
'libraries': libraries,
|
'libraries': libraries,
|
||||||
'symbols': self.toolchain.get_symbols()
|
'symbols': self.get_symbols()
|
||||||
}
|
}
|
||||||
target = self.target.lower()
|
target = self.target.lower()
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ class DS5_5(Exporter):
|
||||||
'scatter_file': self.resources.linker_script,
|
'scatter_file': self.resources.linker_script,
|
||||||
'object_files': self.resources.objects + self.resources.libraries,
|
'object_files': self.resources.objects + self.resources.libraries,
|
||||||
'source_files': source_files,
|
'source_files': source_files,
|
||||||
'symbols': self.toolchain.get_symbols()
|
'symbols': self.get_symbols()
|
||||||
}
|
}
|
||||||
target = self.target.lower()
|
target = self.target.lower()
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class IntermediateFile(Exporter):
|
||||||
'script_file': self.resources.linker_script,
|
'script_file': self.resources.linker_script,
|
||||||
'library_paths': self.resources.lib_dirs,
|
'library_paths': self.resources.lib_dirs,
|
||||||
'libraries': libraries,
|
'libraries': libraries,
|
||||||
'symbols': self.toolchain.get_symbols(),
|
'symbols': self.get_symbols(),
|
||||||
'object_files': self.resources.objects,
|
'object_files': self.resources.objects,
|
||||||
'sys_libs': self.toolchain.sys_libs,
|
'sys_libs': self.toolchain.sys_libs,
|
||||||
'cc_org': self.toolchain.cc[1:],
|
'cc_org': self.toolchain.cc[1:],
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Exporter():
|
||||||
TEMPLATE_DIR = dirname(__file__)
|
TEMPLATE_DIR = dirname(__file__)
|
||||||
DOT_IN_RELATIVE_PATH = False
|
DOT_IN_RELATIVE_PATH = False
|
||||||
|
|
||||||
def __init__(self, target, inputDir, program_name, build_url_resolver):
|
def __init__(self, target, inputDir, program_name, build_url_resolver, extra_symbols=None):
|
||||||
self.inputDir = inputDir
|
self.inputDir = inputDir
|
||||||
self.target = target
|
self.target = target
|
||||||
self.program_name = program_name
|
self.program_name = program_name
|
||||||
|
@ -26,6 +26,7 @@ class Exporter():
|
||||||
self.build_url_resolver = build_url_resolver
|
self.build_url_resolver = build_url_resolver
|
||||||
jinja_loader = FileSystemLoader(os.path.dirname(os.path.abspath(__file__)))
|
jinja_loader = FileSystemLoader(os.path.dirname(os.path.abspath(__file__)))
|
||||||
self.jinja_environment = Environment(loader=jinja_loader)
|
self.jinja_environment = Environment(loader=jinja_loader)
|
||||||
|
self.extra_symbols = extra_symbols
|
||||||
|
|
||||||
def get_toolchain(self):
|
def get_toolchain(self):
|
||||||
return self.TOOLCHAIN
|
return self.TOOLCHAIN
|
||||||
|
@ -97,6 +98,16 @@ class Exporter():
|
||||||
logging.debug("Generating: %s" % target_path)
|
logging.debug("Generating: %s" % target_path)
|
||||||
open(target_path, "w").write(target_text)
|
open(target_path, "w").write(target_text)
|
||||||
|
|
||||||
|
def get_symbols(self, add_extra_symbols=True):
|
||||||
|
""" This function returns symbols which must be exported.
|
||||||
|
Please add / overwrite symbols in each exporter separately
|
||||||
|
"""
|
||||||
|
symbols = self.toolchain.get_symbols()
|
||||||
|
# We have extra symbols from e.g. libraries, we want to have them also added to export
|
||||||
|
if add_extra_symbols:
|
||||||
|
if self.extra_symbols is not None:
|
||||||
|
symbols.extend(self.extra_symbols)
|
||||||
|
return symbols
|
||||||
|
|
||||||
def zip_working_directory_and_clean_up(tempdirectory=None, destination=None, program_name=None, clean=True):
|
def zip_working_directory_and_clean_up(tempdirectory=None, destination=None, program_name=None, clean=True):
|
||||||
uid = str(uuid.uuid4())
|
uid = str(uuid.uuid4())
|
||||||
|
|
|
@ -89,6 +89,6 @@ class GccArm(Exporter):
|
||||||
'library_paths': self.resources.lib_dirs,
|
'library_paths': self.resources.lib_dirs,
|
||||||
'linker_script': self.resources.linker_script,
|
'linker_script': self.resources.linker_script,
|
||||||
'libraries': libraries,
|
'libraries': libraries,
|
||||||
'symbols': self.toolchain.get_symbols()
|
'symbols': self.get_symbols()
|
||||||
}
|
}
|
||||||
self.gen_file('gcc_arm_%s.tmpl' % self.target.lower(), ctx, 'Makefile')
|
self.gen_file('gcc_arm_%s.tmpl' % self.target.lower(), ctx, 'Makefile')
|
||||||
|
|
|
@ -57,7 +57,7 @@ class IAREmbeddedWorkbench(Exporter):
|
||||||
'linker_script': self.resources.linker_script,
|
'linker_script': self.resources.linker_script,
|
||||||
'object_files': self.resources.objects,
|
'object_files': self.resources.objects,
|
||||||
'libraries': self.resources.libraries,
|
'libraries': self.resources.libraries,
|
||||||
'symbols': self.toolchain.get_symbols(),
|
'symbols': self.get_symbols(),
|
||||||
'source_files': sources,
|
'source_files': sources,
|
||||||
}
|
}
|
||||||
self.gen_file('iar_%s.ewp.tmpl' % self.target.lower(), ctx, '%s.ewp' % self.program_name)
|
self.gen_file('iar_%s.ewp.tmpl' % self.target.lower(), ctx, '%s.ewp' % self.program_name)
|
||||||
|
|
|
@ -39,7 +39,7 @@ class KDS(Exporter):
|
||||||
'linker_script': self.resources.linker_script,
|
'linker_script': self.resources.linker_script,
|
||||||
'object_files': self.resources.objects,
|
'object_files': self.resources.objects,
|
||||||
'libraries': libraries,
|
'libraries': libraries,
|
||||||
'symbols': self.toolchain.get_symbols()
|
'symbols': self.get_symbols()
|
||||||
}
|
}
|
||||||
self.gen_file('kds_%s_project.tmpl' % self.target.lower(), ctx, '.project')
|
self.gen_file('kds_%s_project.tmpl' % self.target.lower(), ctx, '.project')
|
||||||
self.gen_file('kds_%s_cproject.tmpl' % self.target.lower(), ctx, '.cproject')
|
self.gen_file('kds_%s_cproject.tmpl' % self.target.lower(), ctx, '.cproject')
|
||||||
|
|
|
@ -122,7 +122,7 @@ class Uvision4(Exporter):
|
||||||
'scatter_file': self.resources.linker_script,
|
'scatter_file': self.resources.linker_script,
|
||||||
'object_files': self.resources.objects + self.resources.libraries,
|
'object_files': self.resources.objects + self.resources.libraries,
|
||||||
'source_files': source_files.items(),
|
'source_files': source_files.items(),
|
||||||
'symbols': self.toolchain.get_symbols() + ['__ASSERT_MSG'],
|
'symbols': self.get_symbols() + ['__ASSERT_MSG'],
|
||||||
'hex_files' : self.resources.hex_files,
|
'hex_files' : self.resources.hex_files,
|
||||||
'flags' : self.get_flags(),
|
'flags' : self.get_flags(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ ROOT = abspath(join(dirname(__file__), ".."))
|
||||||
sys.path.insert(0, ROOT)
|
sys.path.insert(0, ROOT)
|
||||||
|
|
||||||
from shutil import move, rmtree
|
from shutil import move, rmtree
|
||||||
from os.path import join, exists, basename
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
from workspace_tools.paths import EXPORT_DIR, EXPORT_WORKSPACE, EXPORT_TMP
|
from workspace_tools.paths import EXPORT_DIR, EXPORT_WORKSPACE, EXPORT_TMP
|
||||||
|
@ -13,6 +12,8 @@ from workspace_tools.export import export, setup_user_prj, EXPORTERS
|
||||||
from workspace_tools.utils import args_error
|
from workspace_tools.utils import args_error
|
||||||
from workspace_tools.tests import TESTS, Test, TEST_MAP
|
from workspace_tools.tests import TESTS, Test, TEST_MAP
|
||||||
from workspace_tools.targets import TARGET_NAMES
|
from workspace_tools.targets import TARGET_NAMES
|
||||||
|
from workspace_tools.libraries import LIBRARIES
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import workspace_tools.private_settings as ps
|
import workspace_tools.private_settings as ps
|
||||||
except:
|
except:
|
||||||
|
@ -101,6 +102,16 @@ if __name__ == '__main__':
|
||||||
args_error(parser, message)
|
args_error(parser, message)
|
||||||
test = Test(p)
|
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 = []
|
||||||
|
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:
|
if not options.build:
|
||||||
# Substitute the library builds with the sources
|
# Substitute the library builds with the sources
|
||||||
# TODO: Substitute also the other library build paths
|
# TODO: Substitute also the other library build paths
|
||||||
|
@ -113,7 +124,7 @@ if __name__ == '__main__':
|
||||||
setup_user_prj(project_dir, test.source_dir, test.dependencies)
|
setup_user_prj(project_dir, test.source_dir, test.dependencies)
|
||||||
|
|
||||||
# Export to selected toolchain
|
# Export to selected toolchain
|
||||||
tmp_path, report = export(project_dir, test.id, ide, mcu, EXPORT_WORKSPACE, EXPORT_TMP)
|
tmp_path, report = export(project_dir, test.id, ide, mcu, EXPORT_WORKSPACE, EXPORT_TMP, extra_symbols=lib_symbols)
|
||||||
if report['success']:
|
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" % (test.id, ide, mcu))
|
||||||
move(tmp_path, zip_path)
|
move(tmp_path, zip_path)
|
||||||
|
|
Loading…
Reference in New Issue