|
29 | 29 | sys.path.insert(0, ROOT) |
30 | 30 |
|
31 | 31 |
|
32 | | -from tools.toolchains import TOOLCHAINS, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS |
33 | | -from tools.toolchains import mbedToolchain |
34 | | -from tools.targets import TARGET_NAMES, TARGET_MAP, Target |
| 32 | +from tools.toolchains import TOOLCHAINS |
| 33 | +from tools.targets import TARGET_NAMES, Target |
35 | 34 | from tools.options import get_default_options_parser |
36 | 35 | from tools.options import extract_profile |
37 | 36 | from tools.options import extract_mcus |
38 | 37 | from tools.build_api import build_library, build_mbed_libs, build_lib |
39 | 38 | from tools.build_api import mcu_toolchain_matrix |
40 | 39 | from tools.build_api import print_build_results |
41 | | -from tools.build_api import get_toolchain_name |
42 | | -from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT |
43 | | -from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, CLI_COLOR_MAP |
| 40 | +from tools.build_api import target_supports_toolchain |
| 41 | +from tools.build_api import find_valid_toolchain |
44 | 42 | from tools.notifier.term import TerminalNotifier |
45 | 43 | from tools.utils import argparse_filestring_type, args_error, argparse_many |
46 | | -from tools.utils import argparse_filestring_type, argparse_dir_not_parent |
| 44 | +from tools.utils import argparse_dir_not_parent |
| 45 | +from tools.utils import NoValidToolchainException |
| 46 | +from tools.utils import print_end_warnings |
47 | 47 | from tools.paths import is_relative_to_root |
48 | 48 |
|
49 | | -if __name__ == '__main__': |
| 49 | +def main(): |
50 | 50 | start = time() |
51 | 51 |
|
52 | 52 | # Parse Options |
|
169 | 169 | failures = [] |
170 | 170 | successes = [] |
171 | 171 | skipped = [] |
| 172 | + end_warnings = [] |
172 | 173 |
|
173 | | - toolchain_names = set() |
174 | 174 | for toolchain in toolchains: |
175 | 175 | for target_name in targets: |
176 | 176 | target = Target.get_target(target_name) |
177 | | - toolchain_names.add(get_toolchain_name(target, toolchain)) |
178 | 177 |
|
179 | | - for toolchain_name in toolchain_names: |
180 | | - if not TOOLCHAIN_CLASSES[toolchain_name].check_executable(): |
181 | | - search_path = TOOLCHAIN_PATHS[toolchain_name] or "No path set" |
182 | | - args_error(parser, "Could not find executable for %s.\n" |
183 | | - "Currently set search path: %s" |
184 | | - % (toolchain_name, search_path)) |
| 178 | + try: |
| 179 | + toolchain_name, internal_tc_name, end_warnings = find_valid_toolchain( |
| 180 | + target, toolchain |
| 181 | + ) |
| 182 | + except NoValidToolchainException as e: |
| 183 | + print_end_warnings(e.end_warnings) |
| 184 | + args_error(parser, str(e)) |
185 | 185 |
|
186 | | - for toolchain in toolchains: |
187 | | - for target in targets: |
188 | | - tt_id = "%s::%s" % (toolchain, target) |
189 | | - if toolchain not in TARGET_MAP[target].supported_toolchains: |
| 186 | + tt_id = "%s::%s" % (internal_tc_name, target_name) |
| 187 | + if not target_supports_toolchain(target, toolchain): |
190 | 188 | # Log this later |
191 | 189 | print("%s skipped: toolchain not supported" % tt_id) |
192 | 190 | skipped.append(tt_id) |
193 | 191 | else: |
194 | 192 | try: |
195 | 193 | notifier = TerminalNotifier(options.verbose, options.silent) |
196 | | - mcu = TARGET_MAP[target] |
197 | | - profile = extract_profile(parser, options, toolchain) |
| 194 | + profile = extract_profile(parser, options, internal_tc_name) |
198 | 195 |
|
199 | | - if mcu.is_PSA_secure_target and \ |
| 196 | + if target.is_PSA_secure_target and \ |
200 | 197 | not is_relative_to_root(options.source_dir): |
201 | 198 | options.source_dir = ROOT |
202 | 199 |
|
203 | 200 | if options.source_dir: |
204 | 201 | lib_build_res = build_library( |
205 | | - options.source_dir, options.build_dir, mcu, toolchain, |
| 202 | + options.source_dir, options.build_dir, target, toolchain_name, |
206 | 203 | jobs=options.jobs, |
207 | 204 | clean=options.clean, |
208 | 205 | archive=(not options.no_archive), |
|
214 | 211 | ) |
215 | 212 | else: |
216 | 213 | lib_build_res = build_mbed_libs( |
217 | | - mcu, toolchain, |
| 214 | + target, toolchain_name, |
218 | 215 | jobs=options.jobs, |
219 | 216 | clean=options.clean, |
220 | 217 | macros=options.macros, |
|
225 | 222 |
|
226 | 223 | for lib_id in libraries: |
227 | 224 | build_lib( |
228 | | - lib_id, mcu, toolchain, |
| 225 | + lib_id, target, toolchain_name, |
229 | 226 | clean=options.clean, |
230 | 227 | macros=options.macros, |
231 | 228 | jobs=options.jobs, |
|
236 | 233 | successes.append(tt_id) |
237 | 234 | else: |
238 | 235 | skipped.append(tt_id) |
| 236 | + except KeyboardInterrupt as e: |
| 237 | + print("\n[CTRL+c] exit") |
| 238 | + print_end_warnings(end_warnings) |
| 239 | + sys.exit(0) |
239 | 240 | except Exception as e: |
240 | 241 | if options.verbose: |
241 | 242 | import traceback |
242 | 243 | traceback.print_exc(file=sys.stdout) |
| 244 | + print_end_warnings(end_warnings) |
243 | 245 | sys.exit(1) |
244 | 246 | failures.append(tt_id) |
245 | 247 | print(e) |
|
254 | 256 | if report: |
255 | 257 | print(print_build_results(report, report_name)) |
256 | 258 |
|
| 259 | + print_end_warnings(end_warnings) |
257 | 260 | if failures: |
258 | 261 | sys.exit(1) |
| 262 | + |
| 263 | + |
| 264 | +if __name__ == '__main__': |
| 265 | + main() |
0 commit comments