3 Copyright (c) 2011-2013 ARM Limited
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
9 http://www.apache.org/licenses/LICENSE-2.0
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.
18 from os.path import join, exists, basename
19 from shutil import copytree, rmtree, copy
21 from workspace_tools.utils import mkdir
22 from workspace_tools.export import uvision4, codesourcery, codered, gccarm, ds5_5, iar, emblocks, coide, kds, zip
23 from workspace_tools.export.exporters import zip_working_directory_and_clean_up, OldLibrariesException
24 from workspace_tools.targets import TARGET_NAMES, EXPORT_MAP
27 'uvision': uvision4.Uvision4,
28 'lpcxpresso': codered.CodeRed,
29 'codesourcery': codesourcery.CodeSourcery,
30 'gcc_arm': gccarm.GccArm,
32 'iar': iar.IAREmbeddedWorkbench,
33 'emblocks' : emblocks.IntermediateFile,
34 'coide' : coide.CoIDE,
38 ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN = """
39 Sorry, the target %s is not currently supported on the %s toolchain.
40 Please refer to <a href='/handbook/Exporting-to-offline-toolchains' target='_blank'>Exporting to offline toolchains</a> for more information.
43 ERROR_MESSAGE_NOT_EXPORT_LIBS = """
44 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>.
47 def online_build_url_resolver(url):
48 # TODO: Retrieve the path and name of an online library build URL
49 return {'path':'', 'name':''}
52 def export(project_path, project_name, ide, target, destination='/tmp/',
53 tempdir=None, clean=True, extra_symbols=None, build_url_resolver=online_build_url_resolver):
54 # Convention: we are using capitals for toolchain and target names
55 if target is not None:
56 target = target.upper()
59 tempdir = tempfile.mkdtemp()
61 report = {'success': False}
62 if ide is None or ide == "zip":
66 exporter = zip.ZIP(target, tempdir, project_name, build_url_resolver, extra_symbols=extra_symbols)
67 exporter.scan_and_copy_resources(project_path, tempdir)
69 report['success'] = True
70 except OldLibrariesException, e:
71 report['errormsg'] = ERROR_MESSAGE_NOT_EXPORT_LIBS
73 if ide not in EXPORTERS:
74 report['errormsg'] = "Unsupported toolchain"
76 Exporter = EXPORTERS[ide]
77 target = EXPORT_MAP.get(target, target)
78 if target not in Exporter.TARGETS:
79 report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
82 exporter = Exporter(target, tempdir, project_name, build_url_resolver, extra_symbols=extra_symbols)
83 exporter.scan_and_copy_resources(project_path, tempdir)
85 report['success'] = True
86 except OldLibrariesException, e:
87 report['errormsg'] = ERROR_MESSAGE_NOT_EXPORT_LIBS
91 # add readme file to every offline export.
92 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))
93 # copy .hgignore file to exported direcotry as well.
94 copy(os.path.join(exporter.TEMPLATE_DIR,'.hgignore'),tempdir)
95 zip_path = zip_working_directory_and_clean_up(tempdir, destination, project_name, clean)
97 return zip_path, report
100 ###############################################################################
101 # Generate project folders following the online conventions
102 ###############################################################################
103 def copy_tree(src, dst, clean=True):
113 def setup_user_prj(user_dir, prj_path, lib_paths=None):
115 Setup a project with the same directory structure of the mbed online IDE
120 copy_tree(prj_path, join(user_dir, "src"))
123 user_lib = join(user_dir, "lib")
126 if lib_paths is not None:
127 for lib_path in lib_paths:
128 copy_tree(lib_path, join(user_lib, basename(lib_path)))
130 def mcu_ide_matrix(verbose_html=False, platform_filter=None):
131 """ Shows target map using prettytable """
133 for key in EXPORTERS.iterkeys():
134 supported_ides.append(key)
135 supported_ides.sort()
136 from prettytable import PrettyTable, ALL # Only use it in this function so building works without extra modules
138 # All tests status table print
139 columns = ["Platform"] + supported_ides
140 pt = PrettyTable(columns)
144 pt.align["Platform"] = "l"
148 for target in sorted(TARGET_NAMES):
151 row = [target] # First column is platform name
152 for ide in supported_ides:
154 if target in EXPORTERS[ide].TARGETS:
166 # creates a html page suitable for a browser
167 # result = pt.get_html_string(format=True) if verbose_html else pt.get_string()
168 # creates a html page in a shorter format suitable for readme.md
169 result = pt.get_html_string() if verbose_html else pt.get_string()
171 result += "Total IDEs: %d\n"% (len(supported_ides))
172 if verbose_html: result += "<br>"
173 result += "Total platforms: %d\n"% (target_counter)
174 if verbose_html: result += "<br>"
175 result += "Total permutations: %d"% (perm_counter)
176 if verbose_html: result = result.replace("&", "&")