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