Denislam Valeev / Mbed OS Nucleo_rtos_basic
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers get_config.py Source File

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 import sys
00020 from os.path import isdir, abspath, dirname, join
00021 from os import _exit
00022 
00023 # Be sure that the tools directory is in the search path
00024 ROOT = abspath(join(dirname(__file__), ".."))
00025 sys.path.insert(0, ROOT)
00026 
00027 from tools.utils import args_error
00028 from tools.options import get_default_options_parser
00029 from tools.options import extract_mcus
00030 from tools.build_api import get_config
00031 from config import Config
00032 from utils import argparse_filestring_type
00033 try:
00034     import tools.private_settings as ps
00035 except:
00036     ps = object()
00037 
00038 if __name__ == '__main__':
00039     # Parse Options
00040     parser = get_default_options_parser(add_clean=False, add_options=False)
00041     parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, required=True,
00042                         default=[], help="The source (input) directory", action="append")
00043     parser.add_argument("--prefix", dest="prefix", action="append",
00044                       default=[], help="Restrict listing to parameters that have this prefix")
00045     parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
00046                       default=False, help="Verbose diagnostic output")
00047 
00048     options = parser.parse_args()
00049 
00050     # Target
00051     if options.mcu is None :
00052         args_error(parser, "argument -m/--mcu is required")
00053     target = extract_mcus(parser, options)[0]
00054 
00055     # Toolchain
00056     if options.tool is None:
00057         args_error(parser, "argument -t/--toolchain is required")
00058     toolchain = options.tool[0]
00059 
00060     options.prefix = options.prefix or [""]
00061 
00062     try:
00063         params, macros, features = get_config(options.source_dir, target, toolchain)
00064         if not params and not macros:
00065             print "No configuration data available."
00066             _exit(0)
00067         if params:
00068             print "Configuration parameters"
00069             print "------------------------"
00070             for p in sorted(params):
00071                 for s in options.prefix:
00072                     if p.startswith(s):
00073                         print(str(params[p]) if not options.verbose else params[p].get_verbose_description())
00074                         break
00075             print ""
00076 
00077         print "Macros"
00078         print "------"
00079         if macros:
00080             print 'Defined with "macros":', Config.config_macros_to_macros(macros)
00081         print "Generated from configuration parameters:", Config.parameters_to_macros(params)
00082 
00083     except KeyboardInterrupt, e:
00084         print "\n[CTRL+c] exit"
00085     except Exception,e:
00086         if options.verbose:
00087             import traceback
00088             traceback.print_exc(file=sys.stdout)
00089         else:
00090             print "[ERROR] %s" % str(e)
00091 
00092         sys.exit(1)