Skip to content

Commit cfdb28d

Browse files
committed
Refactor export subsystem
Makes several broad changes: - removes dead code that dealt with the online build system - replaces export function with a much simpler one that: - does not copy any sources - the zip file hits the disk - the mbed_config.h hits the disk - the project files hit the disk - nothing else hits the disk - exporters use Resource object scanned with a toolchain - progen exporters don't optionally build a project instead they have a build function that may be called afterwards - much of the code passes pylint (have a score of 9 or above): - project.py - project_api.py - export/__init__.py - export/exporters.py - test/export/build_test.py
1 parent 36468c9 commit cfdb28d

21 files changed

+819
-784
lines changed

tools/build_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def prepare_toolchain(src_paths, target, toolchain_name,
252252

253253
return toolchain
254254

255-
def scan_resources(src_paths, toolchain, dependencies_paths=None, inc_dirs=None):
255+
def scan_resources(src_paths, toolchain, dependencies_paths=None, inc_dirs=None, base_path=None):
256256
""" Scan resources using initialized toolcain
257257
src_paths: the paths to source directories
258258
toolchain: valid toolchain object
@@ -261,9 +261,9 @@ def scan_resources(src_paths, toolchain, dependencies_paths=None, inc_dirs=None)
261261
"""
262262

263263
# Scan src_path
264-
resources = toolchain.scan_resources(src_paths[0])
264+
resources = toolchain.scan_resources(src_paths[0], base_path=base_path)
265265
for path in src_paths[1:]:
266-
resources.add(toolchain.scan_resources(path))
266+
resources.add(toolchain.scan_resources(path, base_path=base_path))
267267

268268
# Scan dependency paths for include dirs
269269
if dependencies_paths is not None:
@@ -495,7 +495,7 @@ def build_lib(lib_id, target, toolchain_name, options=None, verbose=False, clean
495495
"""
496496
lib = Library(lib_id)
497497
if not lib.is_supported(target, toolchain_name):
498-
print 'Library "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target.name, toolchain)
498+
print 'Library "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target.name, toolchain_name)
499499
return False
500500

501501
# We need to combine macros from parameter list with macros from library definition

tools/export/__init__.py

Lines changed: 45 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-2013 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
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
@@ -52,162 +53,25 @@
5253
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>.
5354
"""
5455

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
56+
def mcu_ide_matrix(verbose_html=False):
57+
"""Shows target map using prettytable
12558
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
59+
Keyword argumets:
60+
verbose_html - print the matrix in html format
17661
"""
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
62+
supported_ides = sorted(EXPORTERS.keys())
63+
# Only use it in this function so building works without extra modules
64+
from prettytable import PrettyTable, ALL
19765

19866
# All tests status table print
199-
columns = ["Platform"] + supported_ides
200-
pt = PrettyTable(columns)
67+
table_printer = PrettyTable(["Platform"] + supported_ides)
20168
# Align table
202-
for col in columns:
203-
pt.align[col] = "c"
204-
pt.align["Platform"] = "l"
69+
for col in supported_ides:
70+
table_printer.align[col] = "c"
71+
table_printer.align["Platform"] = "l"
20572

20673
perm_counter = 0
207-
target_counter = 0
20874
for target in sorted(TARGET_NAMES):
209-
target_counter += 1
210-
21175
row = [target] # First column is platform name
21276
for ide in supported_ides:
21377
text = "-"
@@ -218,20 +82,24 @@ def mcu_ide_matrix(verbose_html=False, platform_filter=None):
21882
text = "x"
21983
perm_counter += 1
22084
row.append(text)
221-
pt.add_row(row)
85+
table_printer.add_row(row)
22286

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()
87+
table_printer.border = True
88+
table_printer.vrules = ALL
89+
table_printer.hrules = ALL
22890
# 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()
91+
if verbose_html:
92+
result = table_printer.get_html_string()
93+
else:
94+
result = table_printer.get_string()
23095
result += "\n"
23196
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>"
97+
if verbose_html:
98+
result += "<br>"
99+
result += "Total platforms: %d\n"% (len(TARGET_NAMES))
100+
if verbose_html:
101+
result += "<br>"
235102
result += "Total permutations: %d"% (perm_counter)
236-
if verbose_html: result = result.replace("&amp;", "&")
103+
if verbose_html:
104+
result = result.replace("&amp;", "&")
237105
return result

tools/export/atmelstudio.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ 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,
@@ -73,7 +73,7 @@ def generate(self):
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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,
5656
'symbols': self.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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ 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,
@@ -111,4 +111,4 @@ def generate(self):
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)

tools/export/ds5_5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def generate(self):
5252
})
5353

5454
ctx = {
55-
'name': self.program_name,
55+
'name': self.project_name,
5656
'include_paths': self.resources.inc_dirs,
5757
'scatter_file': self.resources.linker_script,
5858
'object_files': self.resources.objects + self.resources.libraries,

tools/export/e2studio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def generate(self):
3333
libraries.append(l[3:])
3434

3535
ctx = {
36-
'name': self.program_name,
36+
'name': self.project_name,
3737
'include_paths': self.resources.inc_dirs,
3838
'linker_script': self.resources.linker_script,
3939

@@ -44,4 +44,4 @@ def generate(self):
4444
self.gen_file('e2studio_%s_project.tmpl' % self.target.lower(), ctx, '.project')
4545
self.gen_file('e2studio_%s_cproject.tmpl' % self.target.lower(), ctx, '.cproject')
4646
self.gen_file('e2studio_%s_gdbinit.tmpl' % self.target.lower(), ctx, '.gdbinit')
47-
self.gen_file('e2studio_launch.tmpl', ctx, '%s OpenOCD.launch' % self.program_name)
47+
self.gen_file('e2studio_launch.tmpl', ctx, '%s OpenOCD.launch' % self.project_name)

tools/export/emblocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def generate(self):
6060
self.resources.linker_script = ''
6161

6262
ctx = {
63-
'name': self.program_name,
63+
'name': self.project_name,
6464
'target': self.target,
6565
'toolchain': self.toolchain.name,
6666
'source_files': source_files,
@@ -77,4 +77,4 @@ def generate(self):
7777
}
7878

7979
# EmBlocks intermediate file template
80-
self.gen_file('emblocks.eix.tmpl', ctx, '%s.eix' % self.program_name)
80+
self.gen_file('emblocks.eix.tmpl', ctx, '%s.eix' % self.project_name)

0 commit comments

Comments
 (0)