Skip to content

Commit c3737b4

Browse files
authored
Merge pull request #2593 from ConorPKeegan/devel_app_config_switch
Add app config command line switch for test and make
2 parents 582da03 + ac51eb6 commit c3737b4

File tree

9 files changed

+513
-30
lines changed

9 files changed

+513
-30
lines changed

tools/build_api.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ def get_mbed_official_release(version):
276276
def prepare_toolchain(src_paths, target, toolchain_name,
277277
macros=None, options=None, clean=False, jobs=1,
278278
notify=None, silent=False, verbose=False,
279-
extra_verbose=False, config=None):
279+
extra_verbose=False, config=None,
280+
app_config=None):
280281
""" Prepares resource related objects - toolchain, target, config
281282
282283
Positional arguments:
@@ -294,14 +295,15 @@ def prepare_toolchain(src_paths, target, toolchain_name,
294295
verbose - Write the actual tools command lines used if True
295296
extra_verbose - even more output!
296297
config - a Config object to use instead of creating one
298+
app_config - location of a chosen mbed_app.json file
297299
"""
298300

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

303305
# If the configuration object was not yet created, create it now
304-
config = config or Config(target, src_paths)
306+
config = config or Config(target, src_paths, app_config=app_config)
305307

306308
# If the 'target' argument is a string, convert it to a target instance
307309
if isinstance(target, basestring):
@@ -369,7 +371,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
369371
clean=False, notify=None, verbose=False, name=None,
370372
macros=None, inc_dirs=None, jobs=1, silent=False,
371373
report=None, properties=None, project_id=None,
372-
project_description=None, extra_verbose=False, config=None):
374+
project_description=None, extra_verbose=False, config=None,
375+
app_config=None):
373376
""" Build a project. A project may be a test or a user program.
374377
375378
Positional arguments:
@@ -397,6 +400,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
397400
project_description - the human-readable version of what this thing does
398401
extra_verbose - even more output!
399402
config - a Config object to use instead of creating one
403+
app_config - location of a chosen mbed_app.json file
400404
"""
401405

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

420424
# The first path will give the name to the library
421425
if name is None:
@@ -489,7 +493,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
489493
archive=True, notify=None, verbose=False, macros=None,
490494
inc_dirs=None, jobs=1, silent=False, report=None,
491495
properties=None, extra_verbose=False, project_id=None,
492-
remove_config_header_file=False):
496+
remove_config_header_file=False, app_config=None):
493497
""" Build a library
494498
495499
Positional arguments:
@@ -516,6 +520,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
516520
extra_verbose - even more output!
517521
project_id - the name that goes in the report
518522
remove_config_header_file - delete config header file when done building
523+
app_config - location of a chosen mbed_app.json file
519524
"""
520525

521526
# Convert src_path to a list if needed
@@ -539,7 +544,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
539544
toolchain = prepare_toolchain(
540545
src_paths, target, toolchain_name, macros=macros, options=options,
541546
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
542-
extra_verbose=extra_verbose)
547+
extra_verbose=extra_verbose, app_config=app_config)
543548

544549
# The first path will give the name to the library
545550
if name is None:

tools/config.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ class Config(object):
350350
"UVISOR", "BLE", "CLIENT", "IPV4", "IPV6", "COMMON_PAL", "STORAGE"
351351
]
352352

353-
def __init__(self, target, top_level_dirs=None):
353+
def __init__(self, target, top_level_dirs=None, app_config=None):
354354
"""Construct a mbed configuration
355355
356356
Positional arguments:
@@ -359,7 +359,8 @@ def __init__(self, target, top_level_dirs=None):
359359
360360
Keyword argumets:
361361
top_level_dirs - a list of top level source directories (where
362-
mbed_abb_config.json could be found)
362+
mbed_app_config.json could be found)
363+
app_config - location of a chosen mbed_app.json file
363364
364365
NOTE: Construction of a Config object will look for the application
365366
configuration file in top_level_dirs. If found once, it'll parse it and
@@ -368,22 +369,24 @@ def __init__(self, target, top_level_dirs=None):
368369
exception is raised. top_level_dirs may be None (in this case,
369370
the constructor will not search for a configuration file)
370371
"""
371-
app_config_location = None
372-
for directory in top_level_dirs or []:
373-
full_path = os.path.join(directory, self.__mbed_app_config_name)
374-
if os.path.isfile(full_path):
375-
if app_config_location is not None:
376-
raise ConfigException("Duplicate '%s' file in '%s' and '%s'"
377-
% (self.__mbed_app_config_name,
378-
app_config_location, full_path))
379-
else:
380-
app_config_location = full_path
372+
app_config_location = app_config
373+
if app_config_location is None:
374+
for directory in top_level_dirs or []:
375+
full_path = os.path.join(directory, self.__mbed_app_config_name)
376+
if os.path.isfile(full_path):
377+
if app_config_location is not None:
378+
raise ConfigException("Duplicate '%s' file in '%s' and '%s'"
379+
% (self.__mbed_app_config_name,
380+
app_config_location, full_path))
381+
else:
382+
app_config_location = full_path
381383
try:
382384
self.app_config_data = json_file_to_dict(app_config_location) \
383385
if app_config_location else {}
384386
except ValueError as exc:
385387
sys.stderr.write(str(exc) + "\n")
386388
self.app_config_data = {}
389+
387390
# Check the keys in the application configuration data
388391
unknown_keys = set(self.app_config_data.keys()) - \
389392
self.__allowed_keys["application"]

tools/make.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
if __name__ == '__main__':
5454
# Parse Options
55-
parser = get_default_options_parser()
55+
parser = get_default_options_parser(add_app_config=True)
5656
group = parser.add_mutually_exclusive_group(required=False)
5757
group.add_argument("-p",
5858
type=argparse_many(test_known),
@@ -274,7 +274,8 @@
274274
silent=options.silent,
275275
macros=options.macros,
276276
jobs=options.jobs,
277-
name=options.artifact_name)
277+
name=options.artifact_name,
278+
app_config=options.app_config)
278279
print 'Image: %s'% bin_file
279280

280281
if options.disk:

tools/options.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
from tools.toolchains import TOOLCHAINS
1919
from tools.targets import TARGET_NAMES
2020
from tools.utils import argparse_force_uppercase_type, \
21-
argparse_lowercase_hyphen_type, argparse_many
21+
argparse_lowercase_hyphen_type, argparse_many, \
22+
argparse_filestring_type
2223

23-
def get_default_options_parser(add_clean=True, add_options=True):
24+
def get_default_options_parser(add_clean=True, add_options=True,
25+
add_app_config=False):
2426
"""Create a new options parser with the default compiler options added
2527
2628
Keyword arguments:
@@ -80,4 +82,9 @@ def get_default_options_parser(add_clean=True, add_options=True):
8082
'std-lib'],
8183
"build option"))
8284

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

tools/test.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
if __name__ == '__main__':
4242
try:
4343
# Parse Options
44-
parser = get_default_options_parser()
44+
parser = get_default_options_parser(add_app_config=True)
4545

4646
parser.add_argument("-D",
4747
action="append",
@@ -117,7 +117,8 @@
117117

118118
# Find all tests in the relevant paths
119119
for path in all_paths:
120-
all_tests.update(find_tests(path, mcu, toolchain, options.options))
120+
all_tests.update(find_tests(path, mcu, toolchain, options.options,
121+
app_config=options.app_config))
121122

122123
# Filter tests by name if specified
123124
if options.names:
@@ -177,7 +178,8 @@
177178
verbose=options.verbose,
178179
notify=notify,
179180
archive=False,
180-
remove_config_header_file=True)
181+
remove_config_header_file=True,
182+
app_config=options.app_config)
181183

182184
library_build_success = True
183185
except ToolException, e:
@@ -203,7 +205,8 @@
203205
verbose=options.verbose,
204206
notify=notify,
205207
jobs=options.jobs,
206-
continue_on_build_fail=options.continue_on_build_fail)
208+
continue_on_build_fail=options.continue_on_build_fail,
209+
app_config=options.app_config)
207210

208211
# If a path to a test spec is provided, write it to a file
209212
if options.test_spec:

0 commit comments

Comments
 (0)