mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #203 from ARMmbed/get_config
Added support for viewing the configuration
commit
2904e10924
|
@ -103,7 +103,22 @@ class ConfigParameter:
|
|||
|
||||
# Return the string representation of this configuration parameter
|
||||
def __str__(self):
|
||||
return '"%s" = %s (set in "%s", defined in "%s")' % (self.name, self.value, self.set_by, self.defined_by)
|
||||
if self.value is not None:
|
||||
return '%s = %s (macro name: "%s")' % (self.name, self.value, self.macro_name)
|
||||
else:
|
||||
return '%s has no value' % self.name
|
||||
|
||||
# Return a verbose description of this configuration paramater as a string
|
||||
def get_verbose_description(self):
|
||||
desc = "Name: %s%s\n" % (self.name, " (required parameter)" if self.required else "")
|
||||
if self.help_text:
|
||||
desc += " Description: %s\n" % self.help_text
|
||||
desc += " Defined by: %s\n" % self.defined_by
|
||||
if not self.value:
|
||||
return desc + " No value set"
|
||||
desc += " Macro name: %s\n" % self.macro_name
|
||||
desc += " Value: %s (set by %s)" % (self.value, self.set_by)
|
||||
return desc
|
||||
|
||||
# A representation of a configuration macro. It handles both macros without a value (MACRO)
|
||||
# and with a value (MACRO=VALUE)
|
||||
|
@ -297,8 +312,14 @@ class Config:
|
|||
if p.required and (p.value is None):
|
||||
raise ConfigException("Required parameter '%s' defined by '%s' doesn't have a value" % (p.name, p.defined_by))
|
||||
|
||||
# Return the macro definitions generated for a dictionary of configuration parameters
|
||||
# params: a dictionary of (name, ConfigParameters instance) mappings
|
||||
@staticmethod
|
||||
def parameters_to_macros(params):
|
||||
return ['%s=%s' % (m.macro_name, m.value) for m in params.values() if m.value is not None]
|
||||
|
||||
# Return the configuration data converted to a list of C macros
|
||||
def get_config_data_macros(self):
|
||||
params, macros = self.get_config_data()
|
||||
self._check_required_parameters(params)
|
||||
return macros + ['%s=%s' % (m.macro_name, m.value) for m in params.values() if m.value is not None]
|
||||
return macros + self.parameters_to_macros(params)
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
#! /usr/bin/env python2
|
||||
"""
|
||||
mbed SDK
|
||||
Copyright (c) 2011-2013 ARM Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
"""
|
||||
import sys
|
||||
from os.path import isdir, abspath, dirname, join
|
||||
from os import _exit
|
||||
|
||||
# Be sure that the tools directory is in the search path
|
||||
ROOT = abspath(join(dirname(__file__), ".."))
|
||||
sys.path.insert(0, ROOT)
|
||||
|
||||
from tools.utils import args_error
|
||||
from tools.options import get_default_options_parser
|
||||
from tools.build_api import get_config
|
||||
from config import Config
|
||||
try:
|
||||
import tools.private_settings as ps
|
||||
except:
|
||||
ps = object()
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Parse Options
|
||||
parser = get_default_options_parser(add_clean=False, add_options=False)
|
||||
parser.add_option("--source", dest="source_dir",
|
||||
default=None, help="The source (input) directory", action="append")
|
||||
parser.add_option("--prefix", dest="prefix", action="append",
|
||||
default=None, help="Restrict listing to parameters that have this prefix")
|
||||
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
|
||||
default=False, help="Verbose diagnostic output")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
for path in options.source_dir :
|
||||
if not isdir(path) :
|
||||
args_error(parser, "[ERROR] you passed \"{}\" to --source, which does not exist".
|
||||
format(path))
|
||||
# Target
|
||||
if options.mcu is None :
|
||||
args_error(parser, "[ERROR] You should specify an MCU")
|
||||
target = options.mcu
|
||||
|
||||
# Toolchain
|
||||
if options.tool is None:
|
||||
args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
|
||||
toolchain = options.tool
|
||||
|
||||
options.prefix = options.prefix or [""]
|
||||
|
||||
try:
|
||||
params, macros = get_config(options.source_dir, target, toolchain)
|
||||
if not params and not macros:
|
||||
print "No configuration data available."
|
||||
_exit(0)
|
||||
if params:
|
||||
print "Configuration parameters"
|
||||
print "------------------------"
|
||||
for p in params:
|
||||
for s in options.prefix:
|
||||
if p.startswith(s):
|
||||
print(str(params[p]) if not options.verbose else params[p].get_verbose_description())
|
||||
break
|
||||
print ""
|
||||
|
||||
print "Macros"
|
||||
print "------"
|
||||
if macros:
|
||||
print 'Defined with "macros":', macros
|
||||
print "Generated from configuration parameters:", Config.parameters_to_macros(params)
|
||||
|
||||
except KeyboardInterrupt, e:
|
||||
print "\n[CTRL+c] exit"
|
||||
except Exception,e:
|
||||
if options.verbose:
|
||||
import traceback
|
||||
traceback.print_exc(file=sys.stdout)
|
||||
else:
|
||||
print "[ERROR] %s" % str(e)
|
||||
|
||||
sys.exit(1)
|
|
@ -19,7 +19,7 @@ from tools.toolchains import TOOLCHAINS
|
|||
from tools.targets import TARGET_NAMES
|
||||
|
||||
|
||||
def get_default_options_parser():
|
||||
def get_default_options_parser(add_clean=True, add_options=True):
|
||||
parser = OptionParser()
|
||||
|
||||
targetnames = TARGET_NAMES
|
||||
|
@ -35,10 +35,12 @@ def get_default_options_parser():
|
|||
help="build using the given TOOLCHAIN (%s)" % ', '.join(toolchainlist),
|
||||
metavar="TOOLCHAIN")
|
||||
|
||||
parser.add_option("-c", "--clean", action="store_true", default=False,
|
||||
help="clean the build directory")
|
||||
if add_clean:
|
||||
parser.add_option("-c", "--clean", action="store_true", default=False,
|
||||
help="clean the build directory")
|
||||
|
||||
parser.add_option("-o", "--options", action="append",
|
||||
help='Add a build option ("save-asm": save the asm generated by the compiler, "debug-info": generate debugging information, "analyze": run Goanna static code analyzer")')
|
||||
if add_options:
|
||||
parser.add_option("-o", "--options", action="append",
|
||||
help='Add a build option ("save-asm": save the asm generated by the compiler, "debug-info": generate debugging information, "analyze": run Goanna static code analyzer")')
|
||||
|
||||
return parser
|
||||
|
|
Loading…
Reference in New Issue