Skip to content

Commit da3b07d

Browse files
authored
Merge pull request #2245 from theotherjimmy/exporter-refactor
Refactor export subsystem
2 parents 2a2cf25 + 6564bda commit da3b07d

23 files changed

+836
-811
lines changed

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ PySerial>=2.7
33
PrettyTable>=0.7.2
44
Jinja2>=2.7.3
55
IntelHex>=1.3
6-
project-generator>=0.9.7,<0.10.0
7-
project-generator-definitions>=0.2.26,<0.3.0
6+
project-generator==0.9.10
7+
project_generator_definitions>=0.2.26,<0.3.0
88
junit-xml
99
pyYAML
1010
requests

tools/build_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
mbed SDK
3-
Copyright (c) 2011-2013 ARM Limited
3+
Copyright (c) 2011-2016 ARM Limited
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -326,7 +326,7 @@ def prepare_toolchain(src_paths, target, toolchain_name,
326326
return toolchain
327327

328328
def scan_resources(src_paths, toolchain, dependencies_paths=None,
329-
inc_dirs=None):
329+
inc_dirs=None, base_path=None):
330330
""" Scan resources using initialized toolcain
331331
332332
Positional arguments
@@ -338,9 +338,9 @@ def scan_resources(src_paths, toolchain, dependencies_paths=None,
338338
"""
339339

340340
# Scan src_path
341-
resources = toolchain.scan_resources(src_paths[0])
341+
resources = toolchain.scan_resources(src_paths[0], base_path=base_path)
342342
for path in src_paths[1:]:
343-
resources.add(toolchain.scan_resources(path))
343+
resources.add(toolchain.scan_resources(path, base_path=base_path))
344344

345345
# Scan dependency paths for include dirs
346346
if dependencies_paths is not None:

tools/export/__init__.py

Lines changed: 46 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
"""The generic interface for all exporters.
12
"""
2-
mbed SDK
3-
Copyright (c) 2011-2013 ARM Limited
4-
5-
Licensed under the Apache License, Version 2.0 (the "License");
6-
you may not use this file except in compliance with the License.
7-
You may obtain a copy of the License at
8-
9-
http://www.apache.org/licenses/LICENSE-2.0
10-
11-
Unless required by applicable law or agreed to in writing, software
12-
distributed under the License is distributed on an "AS IS" BASIS,
13-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
See the License for the specific language governing permissions and
15-
limitations under the License.
16-
"""
3+
# mbed SDK
4+
# Copyright (c) 2011-2016 ARM Limited
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
1717
import os, tempfile
1818
from os.path import join, exists, basename
1919
from shutil import copytree, rmtree, copy
2020
import yaml
2121

22-
from tools.utils import mkdir
23-
from tools.export import uvision4, uvision5, codered, gccarm, ds5_5, iar, emblocks, coide, kds, zip, simplicityv3, atmelstudio, sw4stm32, e2studio
24-
from tools.export.exporters import zip_working_directory_and_clean_up, OldLibrariesException, FailedBuildException
22+
from tools.export import uvision4, uvision5, codered, gccarm, ds5_5, iar
23+
from tools.export import emblocks, coide, kds, simplicityv3, atmelstudio
24+
from tools.export import sw4stm32, e2studio, zip
25+
from tools.export.exporters import OldLibrariesException, FailedBuildException
2526
from tools.targets import TARGET_NAMES, EXPORT_MAP, TARGET_MAP
2627

2728
from project_generator_definitions.definitions import ProGenDef
@@ -41,6 +42,7 @@
4142
'atmelstudio' : atmelstudio.AtmelStudio,
4243
'sw4stm32' : sw4stm32.Sw4STM32,
4344
'e2studio' : e2studio.E2Studio,
45+
'zip' : zip.ZIP,
4446
}
4547

4648
ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN = """
@@ -52,162 +54,25 @@
5254
To export this project please <a href='http://mbed.org/compiler/?import=http://mbed.org/users/mbed_official/code/mbed-export/k&mode=lib' target='_blank'>import the export version of the mbed library</a>.
5355
"""
5456

55-
def online_build_url_resolver(url):
56-
# TODO: Retrieve the path and name of an online library build URL
57-
return {'path':'', 'name':''}
58-
59-
60-
def export(project_path, project_name, ide, target, destination='/tmp/',
61-
tempdir=None, pgen_build = False, clean=True, extra_symbols=None, make_zip=True, sources_relative=False,
62-
build_url_resolver=online_build_url_resolver, progen_build=False):
63-
# Convention: we are using capitals for toolchain and target names
64-
if target is not None:
65-
target = target.upper()
66-
67-
if tempdir is None:
68-
tempdir = tempfile.mkdtemp()
69-
70-
use_progen = False
71-
supported = True
72-
report = {'success': False, 'errormsg':'', 'skip': False}
73-
74-
if ide is None or ide == "zip":
75-
# Simple ZIP exporter
76-
try:
77-
ide = "zip"
78-
exporter = zip.ZIP(target, tempdir, project_name, build_url_resolver, extra_symbols=extra_symbols)
79-
exporter.scan_and_copy_resources(project_path, tempdir, sources_relative)
80-
exporter.generate()
81-
report['success'] = True
82-
except OldLibrariesException, e:
83-
report['errormsg'] = ERROR_MESSAGE_NOT_EXPORT_LIBS
84-
else:
85-
if ide not in EXPORTERS:
86-
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
87-
report['skip'] = True
88-
else:
89-
Exporter = EXPORTERS[ide]
90-
target = EXPORT_MAP.get(target, target)
91-
try:
92-
if Exporter.PROGEN_ACTIVE:
93-
use_progen = True
94-
except AttributeError:
95-
pass
96-
97-
if target not in Exporter.TARGETS or Exporter.TOOLCHAIN not in TARGET_MAP[target].supported_toolchains:
98-
supported = False
99-
100-
if use_progen:
101-
if not ProGenDef(ide).is_supported(TARGET_MAP[target].progen['target']):
102-
supported = False
103-
104-
if supported:
105-
# target checked, export
106-
try:
107-
exporter = Exporter(target, tempdir, project_name, build_url_resolver, extra_symbols=extra_symbols, sources_relative=sources_relative)
108-
exporter.scan_and_copy_resources(project_path, tempdir, sources_relative)
109-
if progen_build:
110-
#try to build with pgen ide builders
111-
try:
112-
exporter.generate(progen_build=True)
113-
report['success'] = True
114-
except FailedBuildException, f:
115-
report['errormsg'] = "Build Failed"
116-
else:
117-
exporter.generate()
118-
report['success'] = True
119-
except OldLibrariesException, e:
120-
report['errormsg'] = ERROR_MESSAGE_NOT_EXPORT_LIBS
121-
122-
else:
123-
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
124-
report['skip'] = True
57+
def mcu_ide_matrix(verbose_html=False):
58+
"""Shows target map using prettytable
12559
126-
zip_path = None
127-
if report['success']:
128-
# readme.txt to contain more exported data
129-
exporter_yaml = {
130-
'project_generator': {
131-
'active' : False,
132-
}
133-
}
134-
if use_progen:
135-
try:
136-
import pkg_resources
137-
version = pkg_resources.get_distribution('project_generator').version
138-
exporter_yaml['project_generator']['version'] = version
139-
exporter_yaml['project_generator']['active'] = True;
140-
exporter_yaml['project_generator_definitions'] = {}
141-
version = pkg_resources.get_distribution('project_generator_definitions').version
142-
exporter_yaml['project_generator_definitions']['version'] = version
143-
except ImportError:
144-
pass
145-
with open(os.path.join(tempdir, 'exporter.yaml'), 'w') as outfile:
146-
yaml.dump(exporter_yaml, outfile, default_flow_style=False)
147-
# add readme file to every offline export.
148-
open(os.path.join(tempdir, 'GettingStarted.htm'),'w').write('<meta http-equiv="refresh" content="0; url=http://mbed.org/handbook/Getting-Started-mbed-Exporters#%s"/>'% (ide))
149-
# copy .hgignore file to exported direcotry as well.
150-
if exists(os.path.join(exporter.TEMPLATE_DIR,'.hgignore')):
151-
copy(os.path.join(exporter.TEMPLATE_DIR,'.hgignore'), tempdir)
152-
if make_zip:
153-
zip_path = zip_working_directory_and_clean_up(tempdir, destination, project_name, clean)
154-
else:
155-
zip_path = destination
156-
157-
return zip_path, report
158-
159-
160-
###############################################################################
161-
# Generate project folders following the online conventions
162-
###############################################################################
163-
def copy_tree(src, dst, clean=True):
164-
if exists(dst):
165-
if clean:
166-
rmtree(dst)
167-
else:
168-
return
169-
170-
copytree(src, dst)
171-
172-
173-
def setup_user_prj(user_dir, prj_path, lib_paths=None):
174-
"""
175-
Setup a project with the same directory structure of the mbed online IDE
60+
Keyword argumets:
61+
verbose_html - print the matrix in html format
17662
"""
177-
mkdir(user_dir)
178-
179-
# Project Path
180-
copy_tree(prj_path, join(user_dir, "src"))
181-
182-
# Project Libraries
183-
user_lib = join(user_dir, "lib")
184-
mkdir(user_lib)
185-
186-
if lib_paths is not None:
187-
for lib_path in lib_paths:
188-
copy_tree(lib_path, join(user_lib, basename(lib_path)))
189-
190-
def mcu_ide_matrix(verbose_html=False, platform_filter=None):
191-
""" Shows target map using prettytable """
192-
supported_ides = []
193-
for key in EXPORTERS.iterkeys():
194-
supported_ides.append(key)
195-
supported_ides.sort()
196-
from prettytable import PrettyTable, ALL # Only use it in this function so building works without extra modules
63+
supported_ides = sorted(EXPORTERS.keys())
64+
# Only use it in this function so building works without extra modules
65+
from prettytable import PrettyTable, ALL
19766

19867
# All tests status table print
199-
columns = ["Platform"] + supported_ides
200-
pt = PrettyTable(columns)
68+
table_printer = PrettyTable(["Platform"] + supported_ides)
20169
# Align table
202-
for col in columns:
203-
pt.align[col] = "c"
204-
pt.align["Platform"] = "l"
70+
for col in supported_ides:
71+
table_printer.align[col] = "c"
72+
table_printer.align["Platform"] = "l"
20573

20674
perm_counter = 0
207-
target_counter = 0
20875
for target in sorted(TARGET_NAMES):
209-
target_counter += 1
210-
21176
row = [target] # First column is platform name
21277
for ide in supported_ides:
21378
text = "-"
@@ -218,20 +83,24 @@ def mcu_ide_matrix(verbose_html=False, platform_filter=None):
21883
text = "x"
21984
perm_counter += 1
22085
row.append(text)
221-
pt.add_row(row)
86+
table_printer.add_row(row)
22287

223-
pt.border = True
224-
pt.vrules = ALL
225-
pt.hrules = ALL
226-
# creates a html page suitable for a browser
227-
# result = pt.get_html_string(format=True) if verbose_html else pt.get_string()
88+
table_printer.border = True
89+
table_printer.vrules = ALL
90+
table_printer.hrules = ALL
22891
# creates a html page in a shorter format suitable for readme.md
229-
result = pt.get_html_string() if verbose_html else pt.get_string()
92+
if verbose_html:
93+
result = table_printer.get_html_string()
94+
else:
95+
result = table_printer.get_string()
23096
result += "\n"
23197
result += "Total IDEs: %d\n"% (len(supported_ides))
232-
if verbose_html: result += "<br>"
233-
result += "Total platforms: %d\n"% (target_counter)
234-
if verbose_html: result += "<br>"
98+
if verbose_html:
99+
result += "<br>"
100+
result += "Total platforms: %d\n"% (len(TARGET_NAMES))
101+
if verbose_html:
102+
result += "<br>"
235103
result += "Total permutations: %d"% (perm_counter)
236-
if verbose_html: result = result.replace("&amp;", "&")
104+
if verbose_html:
105+
result = result.replace("&amp;", "&")
237106
return result

tools/export/atmelstudio.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
mbed SDK
3-
Copyright (c) 2011-2015 ARM Limited
3+
Copyright (c) 2011-2016 ARM Limited
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -61,19 +61,19 @@ def generate(self):
6161

6262
ctx = {
6363
'target': self.target,
64-
'name': self.program_name,
64+
'name': self.project_name,
6565
'source_files': source_files,
6666
'source_folders': source_folders,
6767
'object_files': self.resources.objects,
6868
'include_paths': self.resources.inc_dirs,
6969
'library_paths': self.resources.lib_dirs,
7070
'linker_script': self.resources.linker_script,
7171
'libraries': libraries,
72-
'symbols': self.get_symbols(),
72+
'symbols': self.toolchain.get_symbols(),
7373
'solution_uuid': solution_uuid.upper(),
7474
'project_uuid': project_uuid.upper()
7575
}
76-
ctx.update(self.progen_flags)
76+
ctx.update(self.flags)
7777
target = self.target.lower()
78-
self.gen_file('atmelstudio6_2.atsln.tmpl', ctx, '%s.atsln' % self.program_name)
79-
self.gen_file('atmelstudio6_2.cppproj.tmpl', ctx, '%s.cppproj' % self.program_name)
78+
self.gen_file('atmelstudio6_2.atsln.tmpl', ctx, '%s.atsln' % self.project_name)
79+
self.gen_file('atmelstudio6_2.cppproj.tmpl', ctx, '%s.cppproj' % self.project_name)

tools/export/codered.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
mbed SDK
3-
Copyright (c) 2011-2013 ARM Limited
3+
Copyright (c) 2011-2016 ARM Limited
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -48,13 +48,13 @@ def generate(self):
4848
libraries.append(l[3:])
4949

5050
ctx = {
51-
'name': self.program_name,
51+
'name': self.project_name,
5252
'include_paths': self.resources.inc_dirs,
5353
'linker_script': self.resources.linker_script,
5454
'object_files': self.resources.objects,
5555
'libraries': libraries,
56-
'symbols': self.get_symbols()
56+
'symbols': self.toolchain.get_symbols()
5757
}
58-
ctx.update(self.progen_flags)
58+
ctx.update(self.flags)
5959
self.gen_file('codered_%s_project.tmpl' % self.target.lower(), ctx, '.project')
6060
self.gen_file('codered_%s_cproject.tmpl' % self.target.lower(), ctx, '.cproject')

tools/export/coide.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
mbed SDK
3-
Copyright (c) 2014 ARM Limited
3+
Copyright (c) 2014-2016 ARM Limited
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -98,17 +98,17 @@ def generate(self):
9898
self.resources.linker_script = ''
9999

100100
ctx = {
101-
'name': self.program_name,
101+
'name': self.project_name,
102102
'source_files': source_files,
103103
'header_files': header_files,
104104
'include_paths': self.resources.inc_dirs,
105105
'scatter_file': self.resources.linker_script,
106106
'library_paths': self.resources.lib_dirs,
107107
'object_files': self.resources.objects,
108108
'libraries': libraries,
109-
'symbols': self.get_symbols()
109+
'symbols': self.toolchain.get_symbols()
110110
}
111111
target = self.target.lower()
112112

113113
# Project file
114-
self.gen_file('coide_%s.coproj.tmpl' % target, ctx, '%s.coproj' % self.program_name)
114+
self.gen_file('coide_%s.coproj.tmpl' % target, ctx, '%s.coproj' % self.project_name)

0 commit comments

Comments
 (0)