1
+ """The generic interface for all exporters.
1
2
"""
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.
17
17
import os , tempfile
18
18
from os .path import join , exists , basename
19
19
from shutil import copytree , rmtree , copy
20
20
import yaml
21
21
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
25
26
from tools .targets import TARGET_NAMES , EXPORT_MAP , TARGET_MAP
26
27
27
28
from project_generator_definitions .definitions import ProGenDef
41
42
'atmelstudio' : atmelstudio .AtmelStudio ,
42
43
'sw4stm32' : sw4stm32 .Sw4STM32 ,
43
44
'e2studio' : e2studio .E2Studio ,
45
+ 'zip' : zip .ZIP ,
44
46
}
45
47
46
48
ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN = """
52
54
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>.
53
55
"""
54
56
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
125
59
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
176
62
"""
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
197
66
198
67
# All tests status table print
199
- columns = ["Platform" ] + supported_ides
200
- pt = PrettyTable (columns )
68
+ table_printer = PrettyTable (["Platform" ] + supported_ides )
201
69
# 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"
205
73
206
74
perm_counter = 0
207
- target_counter = 0
208
75
for target in sorted (TARGET_NAMES ):
209
- target_counter += 1
210
-
211
76
row = [target ] # First column is platform name
212
77
for ide in supported_ides :
213
78
text = "-"
@@ -218,20 +83,24 @@ def mcu_ide_matrix(verbose_html=False, platform_filter=None):
218
83
text = "x"
219
84
perm_counter += 1
220
85
row .append (text )
221
- pt .add_row (row )
86
+ table_printer .add_row (row )
222
87
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
228
91
# 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 ()
230
96
result += "\n "
231
97
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>"
235
103
result += "Total permutations: %d" % (perm_counter )
236
- if verbose_html : result = result .replace ("&" , "&" )
104
+ if verbose_html :
105
+ result = result .replace ("&" , "&" )
237
106
return result
0 commit comments