Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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