BA
/
BaBoRo1
Embed:
(wiki syntax)
Show/hide line numbers
get_config.py
00001 #! /usr/bin/env python2 00002 """ 00003 mbed SDK 00004 Copyright (c) 2011-2013 ARM Limited 00005 00006 Licensed under the Apache License, Version 2.0 (the "License"); 00007 you may not use this file except in compliance with the License. 00008 You may obtain a copy of the License at 00009 00010 http://www.apache.org/licenses/LICENSE-2.0 00011 00012 Unless required by applicable law or agreed to in writing, software 00013 distributed under the License is distributed on an "AS IS" BASIS, 00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 See the License for the specific language governing permissions and 00016 limitations under the License. 00017 00018 """ 00019 from __future__ import print_function 00020 import sys 00021 from os.path import isdir, abspath, dirname, join 00022 from os import _exit 00023 00024 # Be sure that the tools directory is in the search path 00025 ROOT = abspath(join(dirname(__file__), "..")) 00026 sys.path.insert(0, ROOT) 00027 00028 from tools.utils import args_error 00029 from tools.options import get_default_options_parser 00030 from tools.options import extract_mcus 00031 from tools.build_api import get_config 00032 from tools.config import Config 00033 from tools.utils import argparse_filestring_type 00034 try: 00035 import tools.private_settings as ps 00036 except: 00037 ps = object() 00038 00039 if __name__ == '__main__': 00040 # Parse Options 00041 parser = get_default_options_parser(add_clean=False, add_options=False) 00042 parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, required=True, 00043 default=[], help="The source (input) directory", action="append") 00044 parser.add_argument("--prefix", dest="prefix", action="append", 00045 default=[], help="Restrict listing to parameters that have this prefix") 00046 parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", 00047 default=False, help="Verbose diagnostic output") 00048 00049 options = parser.parse_args() 00050 00051 # Target 00052 if options.mcu is None : 00053 args_error(parser, "argument -m/--mcu is required") 00054 target = extract_mcus(parser, options)[0] 00055 00056 # Toolchain 00057 if options.tool is None: 00058 args_error(parser, "argument -t/--toolchain is required") 00059 toolchain = options.tool[0] 00060 00061 options.prefix = options.prefix or [""] 00062 00063 try: 00064 params, macros, features = get_config(options.source_dir, target, toolchain) 00065 if not params and not macros: 00066 print("No configuration data available.") 00067 _exit(0) 00068 if params: 00069 print("Configuration parameters") 00070 print("------------------------") 00071 for p in sorted(params): 00072 for s in options.prefix: 00073 if p.startswith(s): 00074 print(str(params[p]) if not options.verbose else params[p].get_verbose_description()) 00075 break 00076 print("") 00077 00078 print("Macros") 00079 print("------") 00080 if macros: 00081 print('Defined with "macros":', Config.config_macros_to_macros(macros)) 00082 print("Generated from configuration parameters:", Config.parameters_to_macros(params)) 00083 00084 except KeyboardInterrupt as e: 00085 print("\n[CTRL+c] exit") 00086 except Exception as e: 00087 if options.verbose: 00088 import traceback 00089 traceback.print_exc(file=sys.stdout) 00090 else: 00091 print("[ERROR] %s" % str(e)) 00092 00093 sys.exit(1)
Generated on Tue Jul 12 2022 12:21:54 by
