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