]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/workspace_tools/project.py
2 from os
.path
import join
, abspath
, dirname
, exists
3 ROOT
= abspath(join(dirname(__file__
), ".."))
4 sys
.path
.insert(0, ROOT
)
6 from shutil
import move
, rmtree
7 from optparse
import OptionParser
9 from workspace_tools
.paths
import EXPORT_DIR
, EXPORT_WORKSPACE
, EXPORT_TMP
10 from workspace_tools
.paths
import MBED_BASE
, MBED_LIBRARIES
11 from workspace_tools
.export
import export
, setup_user_prj
, EXPORTERS
, mcu_ide_matrix
12 from workspace_tools
.utils
import args_error
13 from workspace_tools
.tests
import TESTS
, Test
, TEST_MAP
14 from workspace_tools
.targets
import TARGET_NAMES
15 from workspace_tools
.libraries
import LIBRARIES
18 import workspace_tools
.private_settings
as ps
23 if __name__
== '__main__':
25 parser
= OptionParser()
27 targetnames
= TARGET_NAMES
29 toolchainlist
= EXPORTERS
.keys()
32 parser
.add_option("-m", "--mcu",
35 help="generate project for the given MCU (%s)"% ', '.join(targetnames
))
37 parser
.add_option("-i",
40 help="The target IDE: %s"% str(toolchainlist
))
42 parser
.add_option("-c", "--clean",
45 help="clean the export directory")
47 parser
.add_option("-p",
50 help="The index of the desired test program: [0-%d]"% (len(TESTS
)-1))
52 parser
.add_option("-n",
54 help="The name of the desired test program")
56 parser
.add_option("-b",
60 help="use the mbed library build, instead of the sources")
62 parser
.add_option("-L", "--list-tests",
66 help="list available programs in order and exit")
68 parser
.add_option("-S", "--list-matrix",
70 dest
="supported_ides",
72 help="displays supported matrix of MCUs and IDEs")
74 parser
.add_option("-E",
76 dest
="supported_ides_html",
78 help="writes workspace_tools/export/README.md")
80 (options
, args
) = parser
.parse_args()
82 # Print available tests in order and exit
83 if options
.list_tests
is True:
84 print '\n'.join(map(str, sorted(TEST_MAP
.values())))
87 # Only prints matrix of supported IDEs
88 if options
.supported_ides
:
89 print mcu_ide_matrix()
92 # Only prints matrix of supported IDEs
93 if options
.supported_ides_html
:
94 html
= mcu_ide_matrix(verbose_html
=True)
96 with
open("./export/README.md","w") as f
:
97 f
.write("Exporter IDE/Platform Support\n")
98 f
.write("-----------------------------------\n")
102 print "I/O error({0}): {1}".format(e
.errno
, e
.strerror
)
104 print "Unexpected error:", sys
.exc_info()[0]
108 # Clean Export Directory
110 if exists(EXPORT_DIR
):
114 if options
.mcu
is None :
115 args_error(parser
, "[ERROR] You should specify an MCU")
119 if options
.ide
is None:
120 args_error(parser
, "[ERROR] You should specify an IDE")
127 for mcu
in mcus
.split(','):
128 # Program Number or name
129 p
, n
= options
.program
, options
.program_name
131 if n
is not None and p
is not None:
132 args_error(parser
, "[ERROR] specify either '-n' or '-p', not both")
134 if not n
in TEST_MAP
.keys():
135 # Check if there is an alias for this in private_settings.py
136 if getattr(ps
, "test_alias", None) is not None:
137 alias
= ps
.test_alias
.get(n
, "")
138 if not alias
in TEST_MAP
.keys():
139 args_error(parser
, "[ERROR] Program with name '%s' not found" % n
)
143 args_error(parser
, "[ERROR] Program with name '%s' not found" % n
)
145 if p
is None or (p
< 0) or (p
> (len(TESTS
)-1)):
146 message
= "[ERROR] You have to specify one of the following tests:\n"
147 message
+= '\n'.join(map(str, sorted(TEST_MAP
.values())))
148 args_error(parser
, message
)
151 if p
is None or (p
< 0) or (p
> (len(TESTS
)-1)):
152 message
= "[ERROR] You have to specify one of the following tests:\n"
153 message
+= '\n'.join(map(str, sorted(TEST_MAP
.values())))
154 args_error(parser
, message
)
157 # Some libraries have extra macros (called by exporter symbols) to we need to pass
158 # them to maintain compilation macros integrity between compiled library and
159 # header files we might use with it
161 for lib
in LIBRARIES
:
162 if lib
['build_dir'] in test
.dependencies
:
163 lib_macros
= lib
.get('macros', None)
164 if lib_macros
is not None:
165 lib_symbols
.extend(lib_macros
)
167 if not options
.build
:
168 # Substitute the library builds with the sources
169 # TODO: Substitute also the other library build paths
170 if MBED_LIBRARIES
in test
.dependencies
:
171 test
.dependencies
.remove(MBED_LIBRARIES
)
172 test
.dependencies
.append(MBED_BASE
)
174 # Build the project with the same directory structure of the mbed online IDE
175 project_dir
= join(EXPORT_WORKSPACE
, test
.id)
176 setup_user_prj(project_dir
, test
.source_dir
, test
.dependencies
)
178 # Export to selected toolchain
179 tmp_path
, report
= export(project_dir
, test
.id, ide
, mcu
, EXPORT_WORKSPACE
, EXPORT_TMP
, extra_symbols
=lib_symbols
)
180 if report
['success']:
181 zip_path
= join(EXPORT_DIR
, "%s_%s_%s.zip" % (test
.id, ide
, mcu
))
182 move(tmp_path
, zip_path
)
183 successes
.append("%s::%s\t%s"% (mcu
, ide
, zip_path
))
185 failures
.append("%s::%s\t%s"% (mcu
, ide
, report
['errormsg']))
187 # Prints export results
189 if len(successes
) > 0:
190 print "Successful exports:"
191 for success
in successes
:
192 print " * %s"% success
193 if len(failures
) > 0:
194 print "Failed exports:"
195 for failure
in failures
:
196 print " * %s"% failure