Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
detect_targets.py@38:399953da035d, 2017-07-13 (annotated)
- Committer:
 - The Other Jimmy 
 - Date:
 - Thu Jul 13 15:26:26 2017 -0500
 - Revision:
 - 38:399953da035d
 - Parent:
 - 35:da9c89f8be7d
 - Child:
 - 41:2a77626a4c21
 
Update to tools release 5.5.2
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| screamer | 13:ab47a20b66f0 | 1 | #! /usr/bin/env python2 | 
| screamer | 13:ab47a20b66f0 | 2 | """ | 
| screamer | 13:ab47a20b66f0 | 3 | mbed SDK | 
| screamer | 13:ab47a20b66f0 | 4 | Copyright (c) 2011-2013 ARM Limited | 
| screamer | 13:ab47a20b66f0 | 5 | |
| screamer | 13:ab47a20b66f0 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); | 
| screamer | 13:ab47a20b66f0 | 7 | you may not use this file except in compliance with the License. | 
| screamer | 13:ab47a20b66f0 | 8 | You may obtain a copy of the License at | 
| screamer | 13:ab47a20b66f0 | 9 | |
| screamer | 13:ab47a20b66f0 | 10 | http://www.apache.org/licenses/LICENSE-2.0 | 
| screamer | 13:ab47a20b66f0 | 11 | |
| screamer | 13:ab47a20b66f0 | 12 | Unless required by applicable law or agreed to in writing, software | 
| screamer | 13:ab47a20b66f0 | 13 | distributed under the License is distributed on an "AS IS" BASIS, | 
| screamer | 13:ab47a20b66f0 | 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| screamer | 13:ab47a20b66f0 | 15 | See the License for the specific language governing permissions and | 
| screamer | 13:ab47a20b66f0 | 16 | limitations under the License. | 
| screamer | 13:ab47a20b66f0 | 17 | """ | 
| screamer | 13:ab47a20b66f0 | 18 | import sys | 
| screamer | 13:ab47a20b66f0 | 19 | import os | 
| The Other Jimmy  | 
35:da9c89f8be7d | 20 | import re | 
| screamer | 13:ab47a20b66f0 | 21 | |
| screamer | 13:ab47a20b66f0 | 22 | ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) | 
| screamer | 13:ab47a20b66f0 | 23 | sys.path.insert(0, ROOT) | 
| screamer | 13:ab47a20b66f0 | 24 | |
| screamer | 13:ab47a20b66f0 | 25 | from tools.options import get_default_options_parser | 
| screamer | 13:ab47a20b66f0 | 26 | |
| screamer | 13:ab47a20b66f0 | 27 | # Check: Extra modules which are required by core test suite | 
| screamer | 13:ab47a20b66f0 | 28 | from tools.utils import check_required_modules | 
| screamer | 13:ab47a20b66f0 | 29 | check_required_modules(['prettytable']) | 
| screamer | 13:ab47a20b66f0 | 30 | |
| screamer | 13:ab47a20b66f0 | 31 | # Imports related to mbed build api | 
| screamer | 13:ab47a20b66f0 | 32 | from tools.build_api import mcu_toolchain_matrix | 
| screamer | 13:ab47a20b66f0 | 33 | from tools.test_api import get_autodetected_MUTS_list | 
| The Other Jimmy  | 
35:da9c89f8be7d | 34 | from argparse import ArgumentParser | 
| screamer | 13:ab47a20b66f0 | 35 | |
| screamer | 13:ab47a20b66f0 | 36 | |
| screamer | 29:1210849dba19 | 37 | def main(): | 
| screamer | 29:1210849dba19 | 38 | """Entry Point""" | 
| screamer | 13:ab47a20b66f0 | 39 | try: | 
| screamer | 13:ab47a20b66f0 | 40 | # Parse Options | 
| The Other Jimmy  | 
35:da9c89f8be7d | 41 | parser = ArgumentParser() | 
| screamer | 13:ab47a20b66f0 | 42 | |
| screamer | 22:9e85236d8716 | 43 | parser.add_argument("-S", "--supported-toolchains", | 
| screamer | 29:1210849dba19 | 44 | action="store_true", | 
| screamer | 29:1210849dba19 | 45 | dest="supported_toolchains", | 
| screamer | 29:1210849dba19 | 46 | default=False, | 
| screamer | 29:1210849dba19 | 47 | help="Displays supported matrix of" | 
| screamer | 29:1210849dba19 | 48 | " targets and toolchains") | 
| screamer | 13:ab47a20b66f0 | 49 | |
| screamer | 22:9e85236d8716 | 50 | parser.add_argument('-f', '--filter', | 
| screamer | 29:1210849dba19 | 51 | dest='general_filter_regex', | 
| screamer | 29:1210849dba19 | 52 | default=None, | 
| screamer | 29:1210849dba19 | 53 | help='Filter targets') | 
| screamer | 13:ab47a20b66f0 | 54 | |
| screamer | 22:9e85236d8716 | 55 | parser.add_argument("-v", "--verbose", | 
| screamer | 29:1210849dba19 | 56 | action="store_true", | 
| screamer | 29:1210849dba19 | 57 | dest="verbose", | 
| screamer | 29:1210849dba19 | 58 | default=False, | 
| screamer | 29:1210849dba19 | 59 | help="Verbose diagnostic output") | 
| screamer | 13:ab47a20b66f0 | 60 | |
| screamer | 22:9e85236d8716 | 61 | options = parser.parse_args() | 
| screamer | 13:ab47a20b66f0 | 62 | |
| screamer | 13:ab47a20b66f0 | 63 | # Only prints matrix of supported toolchains | 
| screamer | 13:ab47a20b66f0 | 64 | if options.supported_toolchains: | 
| screamer | 29:1210849dba19 | 65 | print mcu_toolchain_matrix( | 
| screamer | 29:1210849dba19 | 66 | platform_filter=options.general_filter_regex) | 
| screamer | 13:ab47a20b66f0 | 67 | exit(0) | 
| screamer | 13:ab47a20b66f0 | 68 | |
| screamer | 13:ab47a20b66f0 | 69 | # If auto_detect attribute is present, we assume other auto-detection | 
| screamer | 13:ab47a20b66f0 | 70 | # parameters like 'toolchains_filter' are also set. | 
| screamer | 29:1210849dba19 | 71 | muts = get_autodetected_MUTS_list() | 
| screamer | 13:ab47a20b66f0 | 72 | |
| The Other Jimmy  | 
35:da9c89f8be7d | 73 | mcu_filter = options.general_filter_regex or ".*" | 
| The Other Jimmy  | 
35:da9c89f8be7d | 74 | |
| screamer | 13:ab47a20b66f0 | 75 | count = 0 | 
| screamer | 29:1210849dba19 | 76 | for mut in muts.values(): | 
| The Other Jimmy  | 
35:da9c89f8be7d | 77 | if re.match(mcu_filter, mut['mcu']): | 
| The Other Jimmy  | 
35:da9c89f8be7d | 78 | print "" | 
| The Other Jimmy  | 
35:da9c89f8be7d | 79 | print "[mbed] Detected %s, port %s, mounted %s" % \ | 
| The Other Jimmy  | 
35:da9c89f8be7d | 80 | (mut['mcu'], mut['port'], mut['disk']) | 
| The Other Jimmy  | 
35:da9c89f8be7d | 81 | print "[mbed] Supported toolchains for %s" % mut['mcu'] | 
| The Other Jimmy  | 
35:da9c89f8be7d | 82 | print mcu_toolchain_matrix(platform_filter=mut['mcu']) | 
| The Other Jimmy  | 
35:da9c89f8be7d | 83 | count += 1 | 
| screamer | 29:1210849dba19 | 84 | |
| screamer | 13:ab47a20b66f0 | 85 | if count == 0: | 
| screamer | 13:ab47a20b66f0 | 86 | print "[mbed] No mbed targets where detected on your system." | 
| screamer | 13:ab47a20b66f0 | 87 | |
| screamer | 29:1210849dba19 | 88 | except KeyboardInterrupt: | 
| screamer | 13:ab47a20b66f0 | 89 | print "\n[CTRL+c] exit" | 
| screamer | 29:1210849dba19 | 90 | except Exception as exc: | 
| screamer | 13:ab47a20b66f0 | 91 | import traceback | 
| screamer | 13:ab47a20b66f0 | 92 | traceback.print_exc(file=sys.stdout) | 
| screamer | 29:1210849dba19 | 93 | print "[ERROR] %s" % str(exc) | 
| screamer | 13:ab47a20b66f0 | 94 | sys.exit(1) | 
| screamer | 29:1210849dba19 | 95 | |
| screamer | 29:1210849dba19 | 96 | if __name__ == '__main__': | 
| screamer | 29:1210849dba19 | 97 | main() | 
