Clone of official tools

Committer:
theotherjimmy
Date:
Wed Oct 25 14:46:50 2017 -0500
Revision:
41:2a77626a4c21
Parent:
35:da9c89f8be7d
Child:
43:2a7da56ebd24
Update to track Mbed OS 5.6.3

Who changed what in which revision?

UserRevisionLine numberNew 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
theotherjimmy 41:2a77626a4c21 34 from tools.test_api import get_module_avail
The Other Jimmy 35:da9c89f8be7d 35 from argparse import ArgumentParser
screamer 13:ab47a20b66f0 36
theotherjimmy 41:2a77626a4c21 37 try:
theotherjimmy 41:2a77626a4c21 38 import mbed_lstools
theotherjimmy 41:2a77626a4c21 39 except:
theotherjimmy 41:2a77626a4c21 40 pass
screamer 13:ab47a20b66f0 41
screamer 29:1210849dba19 42 def main():
screamer 29:1210849dba19 43 """Entry Point"""
screamer 13:ab47a20b66f0 44 try:
screamer 13:ab47a20b66f0 45 # Parse Options
The Other Jimmy 35:da9c89f8be7d 46 parser = ArgumentParser()
screamer 13:ab47a20b66f0 47
screamer 22:9e85236d8716 48 parser.add_argument("-S", "--supported-toolchains",
screamer 29:1210849dba19 49 action="store_true",
screamer 29:1210849dba19 50 dest="supported_toolchains",
screamer 29:1210849dba19 51 default=False,
screamer 29:1210849dba19 52 help="Displays supported matrix of"
screamer 29:1210849dba19 53 " targets and toolchains")
screamer 13:ab47a20b66f0 54
screamer 22:9e85236d8716 55 parser.add_argument('-f', '--filter',
screamer 29:1210849dba19 56 dest='general_filter_regex',
screamer 29:1210849dba19 57 default=None,
screamer 29:1210849dba19 58 help='Filter targets')
screamer 13:ab47a20b66f0 59
screamer 22:9e85236d8716 60 parser.add_argument("-v", "--verbose",
screamer 29:1210849dba19 61 action="store_true",
screamer 29:1210849dba19 62 dest="verbose",
screamer 29:1210849dba19 63 default=False,
screamer 29:1210849dba19 64 help="Verbose diagnostic output")
screamer 13:ab47a20b66f0 65
screamer 22:9e85236d8716 66 options = parser.parse_args()
screamer 13:ab47a20b66f0 67
screamer 13:ab47a20b66f0 68 # Only prints matrix of supported toolchains
screamer 13:ab47a20b66f0 69 if options.supported_toolchains:
screamer 29:1210849dba19 70 print mcu_toolchain_matrix(
screamer 29:1210849dba19 71 platform_filter=options.general_filter_regex)
screamer 13:ab47a20b66f0 72 exit(0)
screamer 13:ab47a20b66f0 73
screamer 13:ab47a20b66f0 74 # If auto_detect attribute is present, we assume other auto-detection
screamer 13:ab47a20b66f0 75 # parameters like 'toolchains_filter' are also set.
screamer 29:1210849dba19 76 muts = get_autodetected_MUTS_list()
screamer 13:ab47a20b66f0 77
The Other Jimmy 35:da9c89f8be7d 78 mcu_filter = options.general_filter_regex or ".*"
The Other Jimmy 35:da9c89f8be7d 79
screamer 13:ab47a20b66f0 80 count = 0
screamer 29:1210849dba19 81 for mut in muts.values():
The Other Jimmy 35:da9c89f8be7d 82 if re.match(mcu_filter, mut['mcu']):
theotherjimmy 41:2a77626a4c21 83 interface_version = get_interface_version(mut['disk'])
The Other Jimmy 35:da9c89f8be7d 84 print ""
theotherjimmy 41:2a77626a4c21 85 print "[mbed] Detected %s, port %s, mounted %s, interface version %s:" % \
theotherjimmy 41:2a77626a4c21 86 (mut['mcu'], mut['port'], mut['disk'], interface_version)
theotherjimmy 41:2a77626a4c21 87
The Other Jimmy 35:da9c89f8be7d 88 print "[mbed] Supported toolchains for %s" % mut['mcu']
The Other Jimmy 35:da9c89f8be7d 89 print mcu_toolchain_matrix(platform_filter=mut['mcu'])
The Other Jimmy 35:da9c89f8be7d 90 count += 1
screamer 29:1210849dba19 91
screamer 13:ab47a20b66f0 92 if count == 0:
theotherjimmy 41:2a77626a4c21 93 print "[mbed] No mbed targets were detected on your system."
screamer 13:ab47a20b66f0 94
screamer 29:1210849dba19 95 except KeyboardInterrupt:
screamer 13:ab47a20b66f0 96 print "\n[CTRL+c] exit"
screamer 29:1210849dba19 97 except Exception as exc:
screamer 13:ab47a20b66f0 98 import traceback
screamer 13:ab47a20b66f0 99 traceback.print_exc(file=sys.stdout)
screamer 29:1210849dba19 100 print "[ERROR] %s" % str(exc)
screamer 13:ab47a20b66f0 101 sys.exit(1)
theotherjimmy 41:2a77626a4c21 102
theotherjimmy 41:2a77626a4c21 103 def get_interface_version(mount_point):
theotherjimmy 41:2a77626a4c21 104 """ Function returns interface version from the target mounted on the specified mount point
theotherjimmy 41:2a77626a4c21 105
theotherjimmy 41:2a77626a4c21 106 mount_point can be acquired via the following:
theotherjimmy 41:2a77626a4c21 107 muts = get_autodetected_MUTS_list()
theotherjimmy 41:2a77626a4c21 108 for mut in muts.values():
theotherjimmy 41:2a77626a4c21 109 mount_point = mut['disk']
theotherjimmy 41:2a77626a4c21 110
theotherjimmy 41:2a77626a4c21 111 @param mount_point Name of disk where platform is connected to host machine.
theotherjimmy 41:2a77626a4c21 112 """
theotherjimmy 41:2a77626a4c21 113 if get_module_avail('mbed_lstools'):
theotherjimmy 41:2a77626a4c21 114 try :
theotherjimmy 41:2a77626a4c21 115 mbeds = mbed_lstools.create()
theotherjimmy 41:2a77626a4c21 116 details_txt = mbeds.get_details_txt(mount_point)
theotherjimmy 41:2a77626a4c21 117
theotherjimmy 41:2a77626a4c21 118 if 'Interface Version' in details_txt:
theotherjimmy 41:2a77626a4c21 119 return details_txt['Interface Version']
theotherjimmy 41:2a77626a4c21 120
theotherjimmy 41:2a77626a4c21 121 elif 'Version' in details_txt:
theotherjimmy 41:2a77626a4c21 122 return details_txt['Version']
theotherjimmy 41:2a77626a4c21 123
theotherjimmy 41:2a77626a4c21 124 except :
theotherjimmy 41:2a77626a4c21 125 return 'unknown'
theotherjimmy 41:2a77626a4c21 126
theotherjimmy 41:2a77626a4c21 127 return 'unknown'
screamer 29:1210849dba19 128
screamer 29:1210849dba19 129 if __name__ == '__main__':
screamer 29:1210849dba19 130 main()