mirror of https://github.com/ARMmbed/mbed-os.git
Add test command switch for app config file
parent
5b90bf7b1d
commit
7c72a22508
|
@ -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:
|
||||
|
@ -294,6 +295,7 @@ 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
|
||||
|
@ -301,7 +303,7 @@ def prepare_toolchain(src_paths, target, toolchain_name,
|
|||
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):
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
@ -359,7 +359,8 @@ class Config(object):
|
|||
|
||||
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
|
||||
|
@ -368,22 +369,24 @@ class Config(object):
|
|||
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"]
|
||||
|
|
|
@ -94,6 +94,10 @@ if __name__ == '__main__':
|
|||
default=False,
|
||||
help="Verbose diagnostic output")
|
||||
|
||||
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')")
|
||||
|
||||
options = parser.parse_args()
|
||||
|
||||
# Filter tests by path if specified
|
||||
|
@ -117,7 +121,8 @@ if __name__ == '__main__':
|
|||
|
||||
# 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:
|
||||
|
@ -177,7 +182,8 @@ if __name__ == '__main__':
|
|||
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:
|
||||
|
@ -203,7 +209,8 @@ if __name__ == '__main__':
|
|||
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:
|
||||
|
|
|
@ -1990,18 +1990,20 @@ def test_path_to_name(path, base):
|
|||
|
||||
return "-".join(name_parts).lower()
|
||||
|
||||
def find_tests(base_dir, target_name, toolchain_name, options=None):
|
||||
def find_tests(base_dir, target_name, toolchain_name, options=None, app_config=None):
|
||||
""" Finds all tests in a directory recursively
|
||||
base_dir: path to the directory to scan for tests (ex. 'path/to/project')
|
||||
target_name: name of the target to use for scanning (ex. 'K64F')
|
||||
toolchain_name: name of the toolchain to use for scanning (ex. 'GCC_ARM')
|
||||
options: Compile options to pass to the toolchain (ex. ['debug-info'])
|
||||
app_config - location of a chosen mbed_app.json file
|
||||
"""
|
||||
|
||||
tests = {}
|
||||
|
||||
# Prepare the toolchain
|
||||
toolchain = prepare_toolchain([base_dir], target_name, toolchain_name, options=options, silent=True)
|
||||
toolchain = prepare_toolchain([base_dir], target_name, toolchain_name, options=options,
|
||||
silent=True, app_config=app_config)
|
||||
|
||||
# Scan the directory for paths to probe for 'TESTS' folders
|
||||
base_resources = scan_resources([base_dir], toolchain)
|
||||
|
@ -2060,7 +2062,7 @@ def norm_relative_path(path, start):
|
|||
def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
|
||||
options=None, clean=False, notify=None, verbose=False, jobs=1,
|
||||
macros=None, silent=False, report=None, properties=None,
|
||||
continue_on_build_fail=False):
|
||||
continue_on_build_fail=False, app_config=None):
|
||||
"""Given the data structure from 'find_tests' and the typical build parameters,
|
||||
build all the tests
|
||||
|
||||
|
@ -2101,7 +2103,8 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
|
|||
project_id=test_name,
|
||||
report=report,
|
||||
properties=properties,
|
||||
verbose=verbose)
|
||||
verbose=verbose,
|
||||
app_config=app_config)
|
||||
|
||||
except Exception, e:
|
||||
if not isinstance(e, NotSupportedException):
|
||||
|
|
Loading…
Reference in New Issue