Skip to content

Commit 203fc36

Browse files
authored
Merge pull request #5559 from yennster/tools-config-fix
Fix for default test config file
2 parents 63a9237 + b3ba9a5 commit 203fc36

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

tools/config/__init__.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,20 @@ class Config(object):
372372
"LOWPAN_BORDER_ROUTER", "LOWPAN_HOST", "LOWPAN_ROUTER", "NANOSTACK_FULL", "THREAD_BORDER_ROUTER", "THREAD_END_DEVICE", "THREAD_ROUTER", "ETHERNET_HOST"
373373
]
374374

375+
@classmethod
376+
def find_app_config(cls, top_level_dirs):
377+
app_config_location = None
378+
for directory in top_level_dirs:
379+
full_path = os.path.join(directory, cls.__mbed_app_config_name)
380+
if os.path.isfile(full_path):
381+
if app_config_location is not None:
382+
raise ConfigException("Duplicate '%s' file in '%s' and '%s'"
383+
% (cls.__mbed_app_config_name,
384+
cls.app_config_location, full_path))
385+
else:
386+
app_config_location = full_path
387+
return app_config_location
388+
375389
def __init__(self, tgt, top_level_dirs=None, app_config=None):
376390
"""Construct a mbed configuration
377391
@@ -391,16 +405,8 @@ def __init__(self, tgt, top_level_dirs=None, app_config=None):
391405
"""
392406
config_errors = []
393407
self.app_config_location = app_config
394-
if self.app_config_location is None:
395-
for directory in top_level_dirs or []:
396-
full_path = os.path.join(directory, self.__mbed_app_config_name)
397-
if os.path.isfile(full_path):
398-
if self.app_config_location is not None:
399-
raise ConfigException("Duplicate '%s' file in '%s' and '%s'"
400-
% (self.__mbed_app_config_name,
401-
self.app_config_location, full_path))
402-
else:
403-
self.app_config_location = full_path
408+
if self.app_config_location is None and top_level_dirs:
409+
self.app_config_location = self.find_app_config(top_level_dirs)
404410
try:
405411
self.app_config_data = json_file_to_dict(self.app_config_location) \
406412
if self.app_config_location else {}

tools/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
if not config:
145145
args_error(parser, "argument --test-config contains invalid path or identifier")
146146
elif not options.app_config:
147-
config = TestConfig.get_default_config(mcu)
147+
config = TestConfig.get_default_config(options.source_dir or ['.'], mcu)
148148
else:
149149
config = options.app_config
150150

tools/test_configs/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from os.path import dirname, abspath, join
1+
from os.path import dirname, abspath, join, exists
22

33
from tools.utils import json_file_to_dict
44
from tools.targets import TARGET_MAP
5+
from tools.config import Config
56

67
CONFIG_DIR = dirname(abspath(__file__))
78
CONFIG_MAP = json_file_to_dict(join(CONFIG_DIR, "config_paths.json"))
@@ -28,12 +29,14 @@ def get_config_path(conf_name, target_name):
2829
else:
2930
return None
3031

31-
def get_default_config(target_name):
32+
def get_default_config(source_dir, target_name):
3233
if target_name in TARGET_CONFIGS:
3334
config_name = TARGET_CONFIGS[target_name]['default_test_configuration']
3435
if config_name == "NONE":
3536
return None
3637
return join(CONFIG_DIR, CONFIG_MAP[config_name])
38+
elif Config.find_app_config(source_dir):
39+
return None
3740
elif (target_name in TARGET_MAP and 'LWIP' in TARGET_MAP[target_name].features):
3841
return join(CONFIG_DIR, CONFIG_MAP["ETHERNET"])
3942
else:

0 commit comments

Comments
 (0)