Clone of official tools

Committer:
The Other Jimmy
Date:
Wed Jan 04 11:58:24 2017 -0600
Revision:
31:8ea194f6145b
Parent:
22:9e85236d8716
Child:
38:399953da035d
Update tools to follow mbed-os tools release 5.3.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 1 #! /usr/bin/env python2
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 2 """
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 3 mbed SDK
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 4 Copyright (c) 2011-2013 ARM Limited
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 5
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 6 Licensed under the Apache License, Version 2.0 (the "License");
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 7 you may not use this file except in compliance with the License.
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 8 You may obtain a copy of the License at
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 9
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 10 http://www.apache.org/licenses/LICENSE-2.0
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 11
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 12 Unless required by applicable law or agreed to in writing, software
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 13 distributed under the License is distributed on an "AS IS" BASIS,
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 15 See the License for the specific language governing permissions and
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 16 limitations under the License.
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 17
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 18 """
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 19 import sys
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 20 from os.path import isdir, abspath, dirname, join
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 21 from os import _exit
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 22
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 23 # Be sure that the tools directory is in the search path
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 24 ROOT = abspath(join(dirname(__file__), ".."))
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 25 sys.path.insert(0, ROOT)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 26
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 27 from tools.utils import args_error
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 28 from tools.options import get_default_options_parser
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 29 from tools.build_api import get_config
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 30 from config import Config
screamer 22:9e85236d8716 31 from utils import argparse_filestring_type
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 32 try:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 33 import tools.private_settings as ps
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 34 except:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 35 ps = object()
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 36
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 37 if __name__ == '__main__':
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 38 # Parse Options
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 39 parser = get_default_options_parser(add_clean=False, add_options=False)
The Other Jimmy 31:8ea194f6145b 40 parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, required=True,
screamer 22:9e85236d8716 41 default=[], help="The source (input) directory", action="append")
screamer 22:9e85236d8716 42 parser.add_argument("--prefix", dest="prefix", action="append",
screamer 22:9e85236d8716 43 default=[], help="Restrict listing to parameters that have this prefix")
screamer 22:9e85236d8716 44 parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 45 default=False, help="Verbose diagnostic output")
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 46
screamer 22:9e85236d8716 47 options = parser.parse_args()
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 48
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 49 # Target
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 50 if options.mcu is None :
The Other Jimmy 31:8ea194f6145b 51 args_error(parser, "argument -m/--mcu is required")
screamer 22:9e85236d8716 52 target = options.mcu[0]
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 53
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 54 # Toolchain
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 55 if options.tool is None:
The Other Jimmy 31:8ea194f6145b 56 args_error(parser, "argument -t/--toolchain is required")
screamer 22:9e85236d8716 57 toolchain = options.tool[0]
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 58
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 59 options.prefix = options.prefix or [""]
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 60
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 61 try:
screamer 13:ab47a20b66f0 62 params, macros, features = get_config(options.source_dir, target, toolchain)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 63 if not params and not macros:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 64 print "No configuration data available."
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 65 _exit(0)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 66 if params:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 67 print "Configuration parameters"
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 68 print "------------------------"
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 69 for p in params:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 70 for s in options.prefix:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 71 if p.startswith(s):
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 72 print(str(params[p]) if not options.verbose else params[p].get_verbose_description())
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 73 break
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 74 print ""
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 75
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 76 print "Macros"
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 77 print "------"
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 78 if macros:
screamer 13:ab47a20b66f0 79 print 'Defined with "macros":', Config.config_macros_to_macros(macros)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 80 print "Generated from configuration parameters:", Config.parameters_to_macros(params)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 81
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 82 except KeyboardInterrupt, e:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 83 print "\n[CTRL+c] exit"
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 84 except Exception,e:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 85 if options.verbose:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 86 import traceback
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 87 traceback.print_exc(file=sys.stdout)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 88 else:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 89 print "[ERROR] %s" % str(e)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 90
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 91 sys.exit(1)