Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew 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 """
switches 0:0e018d759a2a 19 import sys
switches 0:0e018d759a2a 20 from os.path import isdir, abspath, dirname, join
switches 0:0e018d759a2a 21 from os import _exit
switches 0:0e018d759a2a 22
switches 0:0e018d759a2a 23 # Be sure that the tools directory is in the search path
switches 0:0e018d759a2a 24 ROOT = abspath(join(dirname(__file__), ".."))
switches 0:0e018d759a2a 25 sys.path.insert(0, ROOT)
switches 0:0e018d759a2a 26
switches 0:0e018d759a2a 27 from tools.utils import args_error
switches 0:0e018d759a2a 28 from tools.options import get_default_options_parser
switches 0:0e018d759a2a 29 from tools.build_api import get_config
switches 0:0e018d759a2a 30 from config import Config
switches 0:0e018d759a2a 31 from utils import argparse_filestring_type
switches 0:0e018d759a2a 32 try:
switches 0:0e018d759a2a 33 import tools.private_settings as ps
switches 0:0e018d759a2a 34 except:
switches 0:0e018d759a2a 35 ps = object()
switches 0:0e018d759a2a 36
switches 0:0e018d759a2a 37 if __name__ == '__main__':
switches 0:0e018d759a2a 38 # Parse Options
switches 0:0e018d759a2a 39 parser = get_default_options_parser(add_clean=False, add_options=False)
switches 0:0e018d759a2a 40 parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, required=True,
switches 0:0e018d759a2a 41 default=[], help="The source (input) directory", action="append")
switches 0:0e018d759a2a 42 parser.add_argument("--prefix", dest="prefix", action="append",
switches 0:0e018d759a2a 43 default=[], help="Restrict listing to parameters that have this prefix")
switches 0:0e018d759a2a 44 parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
switches 0:0e018d759a2a 45 default=False, help="Verbose diagnostic output")
switches 0:0e018d759a2a 46
switches 0:0e018d759a2a 47 options = parser.parse_args()
switches 0:0e018d759a2a 48
switches 0:0e018d759a2a 49 # Target
switches 0:0e018d759a2a 50 if options.mcu is None :
switches 0:0e018d759a2a 51 args_error(parser, "argument -m/--mcu is required")
switches 0:0e018d759a2a 52 target = options.mcu[0]
switches 0:0e018d759a2a 53
switches 0:0e018d759a2a 54 # Toolchain
switches 0:0e018d759a2a 55 if options.tool is None:
switches 0:0e018d759a2a 56 args_error(parser, "argument -t/--toolchain is required")
switches 0:0e018d759a2a 57 toolchain = options.tool[0]
switches 0:0e018d759a2a 58
switches 0:0e018d759a2a 59 options.prefix = options.prefix or [""]
switches 0:0e018d759a2a 60
switches 0:0e018d759a2a 61 try:
switches 0:0e018d759a2a 62 params, macros, features = get_config(options.source_dir, target, toolchain)
switches 0:0e018d759a2a 63 if not params and not macros:
switches 0:0e018d759a2a 64 print "No configuration data available."
switches 0:0e018d759a2a 65 _exit(0)
switches 0:0e018d759a2a 66 if params:
switches 0:0e018d759a2a 67 print "Configuration parameters"
switches 0:0e018d759a2a 68 print "------------------------"
switches 0:0e018d759a2a 69 for p in params:
switches 0:0e018d759a2a 70 for s in options.prefix:
switches 0:0e018d759a2a 71 if p.startswith(s):
switches 0:0e018d759a2a 72 print(str(params[p]) if not options.verbose else params[p].get_verbose_description())
switches 0:0e018d759a2a 73 break
switches 0:0e018d759a2a 74 print ""
switches 0:0e018d759a2a 75
switches 0:0e018d759a2a 76 print "Macros"
switches 0:0e018d759a2a 77 print "------"
switches 0:0e018d759a2a 78 if macros:
switches 0:0e018d759a2a 79 print 'Defined with "macros":', Config.config_macros_to_macros(macros)
switches 0:0e018d759a2a 80 print "Generated from configuration parameters:", Config.parameters_to_macros(params)
switches 0:0e018d759a2a 81
switches 0:0e018d759a2a 82 except KeyboardInterrupt, e:
switches 0:0e018d759a2a 83 print "\n[CTRL+c] exit"
switches 0:0e018d759a2a 84 except Exception,e:
switches 0:0e018d759a2a 85 if options.verbose:
switches 0:0e018d759a2a 86 import traceback
switches 0:0e018d759a2a 87 traceback.print_exc(file=sys.stdout)
switches 0:0e018d759a2a 88 else:
switches 0:0e018d759a2a 89 print "[ERROR] %s" % str(e)
switches 0:0e018d759a2a 90
switches 0:0e018d759a2a 91 sys.exit(1)