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