Skip to content

progen addition #1487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 8, 2016
Merged
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
url='https://github.com/mbedmicro/mbed',
packages=find_packages(),
license=LICENSE,
install_requires=["PrettyTable>=0.7.2", "PySerial>=2.7", "IntelHex>=1.3", "colorama>=0.3.3", "Jinja2>=2.7.3"])
install_requires=["PrettyTable>=0.7.2", "PySerial>=2.7", "IntelHex>=1.3", "colorama>=0.3.3", "Jinja2>=2.7.3", "project-generator>=0.8.4,<0.9.0"])

# Restore previous private_settings if needed
if backup:
Expand Down
28 changes: 23 additions & 5 deletions workspace_tools/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
from workspace_tools.utils import mkdir
from workspace_tools.export import uvision4, codesourcery, codered, gccarm, ds5_5, iar, emblocks, coide, kds, zip, simplicityv3, atmelstudio
from workspace_tools.export.exporters import zip_working_directory_and_clean_up, OldLibrariesException
from workspace_tools.targets import TARGET_NAMES, EXPORT_MAP
from workspace_tools.targets import TARGET_NAMES, EXPORT_MAP, TARGET_MAP

from project_generator_definitions.definitions import ProGenDef

EXPORTERS = {
'uvision': uvision4.Uvision4,
Expand Down Expand Up @@ -60,7 +62,7 @@ def export(project_path, project_name, ide, target, destination='/tmp/',
if tempdir is None:
tempdir = tempfile.mkdtemp()

report = {'success': False}
report = {'success': False, 'errormsg':''}
if ide is None or ide == "zip":
# Simple ZIP exporter
try:
Expand All @@ -73,20 +75,36 @@ def export(project_path, project_name, ide, target, destination='/tmp/',
report['errormsg'] = ERROR_MESSAGE_NOT_EXPORT_LIBS
else:
if ide not in EXPORTERS:
report['errormsg'] = "Unsupported toolchain"
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
else:
Exporter = EXPORTERS[ide]
target = EXPORT_MAP.get(target, target)
if target not in Exporter.TARGETS:
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
# use progen targets or mbed exporters targets, check progen attribute
use_progen = False
supported = True
try:
if Exporter.PROGEN_ACTIVE:
use_progen = True
except AttributeError:
pass
if use_progen:
if not ProGenDef(ide).is_supported(TARGET_MAP[target].progen_target):
supported = False
else:
if target not in Exporter.TARGETS:
supported = False

if supported:
# target checked, export
try:
exporter = Exporter(target, tempdir, project_name, build_url_resolver, extra_symbols=extra_symbols)
exporter.scan_and_copy_resources(project_path, tempdir)
exporter.generate()
report['success'] = True
except OldLibrariesException, e:
report['errormsg'] = ERROR_MESSAGE_NOT_EXPORT_LIBS
else:
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)

zip_path = None
if report['success']:
Expand Down
38 changes: 37 additions & 1 deletion workspace_tools/export/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
from workspace_tools.toolchains import TOOLCHAIN_CLASSES
from workspace_tools.targets import TARGET_MAP

from project_generator.generate import Generator
from project_generator.project import Project
from project_generator.settings import ProjectSettings

class OldLibrariesException(Exception): pass

class Exporter():
class Exporter(object):
TEMPLATE_DIR = dirname(__file__)
DOT_IN_RELATIVE_PATH = False

Expand Down Expand Up @@ -42,6 +46,38 @@ def __scan_and_copy(self, src_path, trg_path):
self.toolchain.copy_files(r, trg_path, rel_path=src_path)
return resources

def progen_get_project_data(self):
""" Get ProGen project data """
# provide default data, some tools don't require any additional
# tool specific settings
sources = []
for r_type in ['c_sources', 'cpp_sources', 's_sources']:
for file in getattr(self.resources, r_type):
sources.append(file)

project_data = {
'common': {
'sources': {
'Source Files': sources + self.resources.hex_files +
self.resources.objects + self.resources.libraries,
},
'includes': {
'Include Files': self.resources.headers,
},
'target': [TARGET_MAP[self.target].progen_target],
'macros': self.get_symbols(),
'export_dir': [self.inputDir],
'linker_file': [self.resources.linker_script],
}
}
return project_data

def progen_gen_file(self, tool_name, project_data):
"""" Generate project using ProGen Project API """
settings = ProjectSettings()
project = Project(self.program_name, [project_data], settings)
project.generate(tool_name, copied=True)

def __scan_all(self, path):
resources = []

Expand Down
Loading