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