Skip to content

Add app config command line switch for test and make #2593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions tools/build_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ def get_mbed_official_release(version):
def prepare_toolchain(src_paths, target, toolchain_name,
macros=None, options=None, clean=False, jobs=1,
notify=None, silent=False, verbose=False,
extra_verbose=False, config=None):
extra_verbose=False, config=None,
app_config=None):
""" Prepares resource related objects - toolchain, target, config

Positional arguments:
Expand All @@ -294,14 +295,15 @@ def prepare_toolchain(src_paths, target, toolchain_name,
verbose - Write the actual tools command lines used if True
extra_verbose - even more output!
config - a Config object to use instead of creating one
app_config - location of a chosen mbed_app.json file
"""

# We need to remove all paths which are repeated to avoid
# multiple compilations and linking with the same objects
src_paths = [src_paths[0]] + list(set(src_paths[1:]))

# If the configuration object was not yet created, create it now
config = config or Config(target, src_paths)
config = config or Config(target, src_paths, app_config=app_config)

# If the 'target' argument is a string, convert it to a target instance
if isinstance(target, basestring):
Expand Down Expand Up @@ -369,7 +371,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
clean=False, notify=None, verbose=False, name=None,
macros=None, inc_dirs=None, jobs=1, silent=False,
report=None, properties=None, project_id=None,
project_description=None, extra_verbose=False, config=None):
project_description=None, extra_verbose=False, config=None,
app_config=None):
""" Build a project. A project may be a test or a user program.

Positional arguments:
Expand Down Expand Up @@ -397,6 +400,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
project_description - the human-readable version of what this thing does
extra_verbose - even more output!
config - a Config object to use instead of creating one
app_config - location of a chosen mbed_app.json file
"""

# Convert src_path to a list if needed
Expand All @@ -415,7 +419,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
toolchain = prepare_toolchain(
src_paths, target, toolchain_name, macros=macros, options=options,
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
extra_verbose=extra_verbose, config=config)
extra_verbose=extra_verbose, config=config, app_config=app_config)

# The first path will give the name to the library
if name is None:
Expand Down Expand Up @@ -489,7 +493,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
archive=True, notify=None, verbose=False, macros=None,
inc_dirs=None, jobs=1, silent=False, report=None,
properties=None, extra_verbose=False, project_id=None,
remove_config_header_file=False):
remove_config_header_file=False, app_config=None):
""" Build a library

Positional arguments:
Expand All @@ -516,6 +520,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
extra_verbose - even more output!
project_id - the name that goes in the report
remove_config_header_file - delete config header file when done building
app_config - location of a chosen mbed_app.json file
"""

# Convert src_path to a list if needed
Expand All @@ -539,7 +544,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
toolchain = prepare_toolchain(
src_paths, target, toolchain_name, macros=macros, options=options,
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
extra_verbose=extra_verbose)
extra_verbose=extra_verbose, app_config=app_config)

# The first path will give the name to the library
if name is None:
Expand Down
27 changes: 15 additions & 12 deletions tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class Config(object):
"UVISOR", "BLE", "CLIENT", "IPV4", "IPV6", "COMMON_PAL", "STORAGE"
]

def __init__(self, target, top_level_dirs=None):
def __init__(self, target, top_level_dirs=None, app_config=None):
"""Construct a mbed configuration

Positional arguments:
Expand All @@ -359,7 +359,8 @@ def __init__(self, target, top_level_dirs=None):

Keyword argumets:
top_level_dirs - a list of top level source directories (where
mbed_abb_config.json could be found)
mbed_app_config.json could be found)
app_config - location of a chosen mbed_app.json file

NOTE: Construction of a Config object will look for the application
configuration file in top_level_dirs. If found once, it'll parse it and
Expand All @@ -368,22 +369,24 @@ def __init__(self, target, top_level_dirs=None):
exception is raised. top_level_dirs may be None (in this case,
the constructor will not search for a configuration file)
"""
app_config_location = None
for directory in top_level_dirs or []:
full_path = os.path.join(directory, self.__mbed_app_config_name)
if os.path.isfile(full_path):
if app_config_location is not None:
raise ConfigException("Duplicate '%s' file in '%s' and '%s'"
% (self.__mbed_app_config_name,
app_config_location, full_path))
else:
app_config_location = full_path
app_config_location = app_config
if app_config_location is None:
for directory in top_level_dirs or []:
full_path = os.path.join(directory, self.__mbed_app_config_name)
if os.path.isfile(full_path):
if app_config_location is not None:
raise ConfigException("Duplicate '%s' file in '%s' and '%s'"
% (self.__mbed_app_config_name,
app_config_location, full_path))
else:
app_config_location = full_path
try:
self.app_config_data = json_file_to_dict(app_config_location) \
if app_config_location else {}
except ValueError as exc:
sys.stderr.write(str(exc) + "\n")
self.app_config_data = {}

# Check the keys in the application configuration data
unknown_keys = set(self.app_config_data.keys()) - \
self.__allowed_keys["application"]
Expand Down
5 changes: 3 additions & 2 deletions tools/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

if __name__ == '__main__':
# Parse Options
parser = get_default_options_parser()
parser = get_default_options_parser(add_app_config=True)
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument("-p",
type=argparse_many(test_known),
Expand Down Expand Up @@ -274,7 +274,8 @@
silent=options.silent,
macros=options.macros,
jobs=options.jobs,
name=options.artifact_name)
name=options.artifact_name,
app_config=options.app_config)
print 'Image: %s'% bin_file

if options.disk:
Expand Down
11 changes: 9 additions & 2 deletions tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
from tools.toolchains import TOOLCHAINS
from tools.targets import TARGET_NAMES
from tools.utils import argparse_force_uppercase_type, \
argparse_lowercase_hyphen_type, argparse_many
argparse_lowercase_hyphen_type, argparse_many, \
argparse_filestring_type

def get_default_options_parser(add_clean=True, add_options=True):
def get_default_options_parser(add_clean=True, add_options=True,
add_app_config=False):
"""Create a new options parser with the default compiler options added

Keyword arguments:
Expand Down Expand Up @@ -80,4 +82,9 @@ def get_default_options_parser(add_clean=True, add_options=True):
'std-lib'],
"build option"))

if add_app_config:
parser.add_argument("--app-config", default=None, dest="app_config",
type=argparse_filestring_type,
help="Path of an app configuration file (Default is to look for 'mbed_app.json')")

return parser
11 changes: 7 additions & 4 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
if __name__ == '__main__':
try:
# Parse Options
parser = get_default_options_parser()
parser = get_default_options_parser(add_app_config=True)

parser.add_argument("-D",
action="append",
Expand Down Expand Up @@ -117,7 +117,8 @@

# Find all tests in the relevant paths
for path in all_paths:
all_tests.update(find_tests(path, mcu, toolchain, options.options))
all_tests.update(find_tests(path, mcu, toolchain, options.options,
app_config=options.app_config))

# Filter tests by name if specified
if options.names:
Expand Down Expand Up @@ -177,7 +178,8 @@
verbose=options.verbose,
notify=notify,
archive=False,
remove_config_header_file=True)
remove_config_header_file=True,
app_config=options.app_config)

library_build_success = True
except ToolException, e:
Expand All @@ -203,7 +205,8 @@
verbose=options.verbose,
notify=notify,
jobs=options.jobs,
continue_on_build_fail=options.continue_on_build_fail)
continue_on_build_fail=options.continue_on_build_fail,
app_config=options.app_config)

# If a path to a test spec is provided, write it to a file
if options.test_spec:
Expand Down
Loading