Skip to content

Commit 8b10c2a

Browse files
committed
Merge pull request #1487 from 0xc0170/dev_progen_addition
Progen boilerplate addition
2 parents 477f9d8 + 3575c11 commit 8b10c2a

File tree

4 files changed

+135
-15
lines changed

4 files changed

+135
-15
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
url='https://github.com/mbedmicro/mbed',
4141
packages=find_packages(),
4242
license=LICENSE,
43-
install_requires=["PrettyTable>=0.7.2", "PySerial>=2.7", "IntelHex>=1.3", "colorama>=0.3.3", "Jinja2>=2.7.3"])
43+
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"])
4444

4545
# Restore previous private_settings if needed
4646
if backup:

workspace_tools/export/__init__.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
from workspace_tools.utils import mkdir
2222
from workspace_tools.export import uvision4, codesourcery, codered, gccarm, ds5_5, iar, emblocks, coide, kds, zip, simplicityv3, atmelstudio
2323
from workspace_tools.export.exporters import zip_working_directory_and_clean_up, OldLibrariesException
24-
from workspace_tools.targets import TARGET_NAMES, EXPORT_MAP
24+
from workspace_tools.targets import TARGET_NAMES, EXPORT_MAP, TARGET_MAP
25+
26+
from project_generator_definitions.definitions import ProGenDef
2527

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

63-
report = {'success': False}
65+
report = {'success': False, 'errormsg':''}
6466
if ide is None or ide == "zip":
6567
# Simple ZIP exporter
6668
try:
@@ -73,20 +75,36 @@ def export(project_path, project_name, ide, target, destination='/tmp/',
7375
report['errormsg'] = ERROR_MESSAGE_NOT_EXPORT_LIBS
7476
else:
7577
if ide not in EXPORTERS:
76-
report['errormsg'] = "Unsupported toolchain"
78+
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
7779
else:
7880
Exporter = EXPORTERS[ide]
7981
target = EXPORT_MAP.get(target, target)
80-
if target not in Exporter.TARGETS:
81-
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
82+
# use progen targets or mbed exporters targets, check progen attribute
83+
use_progen = False
84+
supported = True
85+
try:
86+
if Exporter.PROGEN_ACTIVE:
87+
use_progen = True
88+
except AttributeError:
89+
pass
90+
if use_progen:
91+
if not ProGenDef(ide).is_supported(TARGET_MAP[target].progen_target):
92+
supported = False
8293
else:
94+
if target not in Exporter.TARGETS:
95+
supported = False
96+
97+
if supported:
98+
# target checked, export
8399
try:
84100
exporter = Exporter(target, tempdir, project_name, build_url_resolver, extra_symbols=extra_symbols)
85101
exporter.scan_and_copy_resources(project_path, tempdir)
86102
exporter.generate()
87103
report['success'] = True
88104
except OldLibrariesException, e:
89105
report['errormsg'] = ERROR_MESSAGE_NOT_EXPORT_LIBS
106+
else:
107+
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
90108

91109
zip_path = None
92110
if report['success']:

workspace_tools/export/exporters.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
from workspace_tools.toolchains import TOOLCHAIN_CLASSES
1313
from workspace_tools.targets import TARGET_MAP
1414

15+
from project_generator.generate import Generator
16+
from project_generator.project import Project
17+
from project_generator.settings import ProjectSettings
18+
1519
class OldLibrariesException(Exception): pass
1620

17-
class Exporter():
21+
class Exporter(object):
1822
TEMPLATE_DIR = dirname(__file__)
1923
DOT_IN_RELATIVE_PATH = False
2024

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

49+
def progen_get_project_data(self):
50+
""" Get ProGen project data """
51+
# provide default data, some tools don't require any additional
52+
# tool specific settings
53+
sources = []
54+
for r_type in ['c_sources', 'cpp_sources', 's_sources']:
55+
for file in getattr(self.resources, r_type):
56+
sources.append(file)
57+
58+
project_data = {
59+
'common': {
60+
'sources': {
61+
'Source Files': sources + self.resources.hex_files +
62+
self.resources.objects + self.resources.libraries,
63+
},
64+
'includes': {
65+
'Include Files': self.resources.headers,
66+
},
67+
'target': [TARGET_MAP[self.target].progen_target],
68+
'macros': self.get_symbols(),
69+
'export_dir': [self.inputDir],
70+
'linker_file': [self.resources.linker_script],
71+
}
72+
}
73+
return project_data
74+
75+
def progen_gen_file(self, tool_name, project_data):
76+
"""" Generate project using ProGen Project API """
77+
settings = ProjectSettings()
78+
project = Project(self.program_name, [project_data], settings)
79+
project.generate(tool_name, copied=True)
80+
4581
def __scan_all(self, path):
4682
resources = []
4783

0 commit comments

Comments
 (0)