Clone of official tools

Committer:
Screamer@Y5070-M.virtuoso
Date:
Tue Jun 14 11:07:30 2016 +0100
Revision:
9:2d27d77ada5c
Child:
13:ab47a20b66f0
Updated tools based on latest live tools code

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@Y5070-M.virtuoso 9:2d27d77ada5c 31 try:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 32 import tools.private_settings as ps
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 33 except:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 34 ps = object()
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 35
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 36 if __name__ == '__main__':
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 37 # Parse Options
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 38 parser = get_default_options_parser(add_clean=False, add_options=False)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 39 parser.add_option("--source", dest="source_dir",
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 40 default=None, help="The source (input) directory", action="append")
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 41 parser.add_option("--prefix", dest="prefix", action="append",
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 42 default=None, help="Restrict listing to parameters that have this prefix")
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 43 parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 44 default=False, help="Verbose diagnostic output")
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 45
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 46 (options, args) = parser.parse_args()
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 47
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 48 for path in options.source_dir :
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 49 if not isdir(path) :
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 50 args_error(parser, "[ERROR] you passed \"{}\" to --source, which does not exist".
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 51 format(path))
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 52 # Target
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 53 if options.mcu is None :
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 54 args_error(parser, "[ERROR] You should specify an MCU")
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 55 target = options.mcu
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 56
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 57 # Toolchain
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 58 if options.tool is None:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 59 args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 60 toolchain = options.tool
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 61
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 62 options.prefix = options.prefix or [""]
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 63
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 64 try:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 65 params, macros = get_config(options.source_dir, target, toolchain)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 66 if not params and not macros:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 67 print "No configuration data available."
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 68 _exit(0)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 69 if params:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 70 print "Configuration parameters"
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 71 print "------------------------"
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 72 for p in params:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 73 for s in options.prefix:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 74 if p.startswith(s):
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 75 print(str(params[p]) if not options.verbose else params[p].get_verbose_description())
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 76 break
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 77 print ""
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 78
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 79 print "Macros"
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 80 print "------"
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 81 if macros:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 82 print 'Defined with "macros":', macros
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 83 print "Generated from configuration parameters:", Config.parameters_to_macros(params)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 84
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 85 except KeyboardInterrupt, e:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 86 print "\n[CTRL+c] exit"
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 87 except Exception,e:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 88 if options.verbose:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 89 import traceback
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 90 traceback.print_exc(file=sys.stdout)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 91 else:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 92 print "[ERROR] %s" % str(e)
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 93
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 94 sys.exit(1)