Skip to content

Commit fab0849

Browse files
author
Cruz Monrreal
authored
Merge pull request #7277 from theotherjimmy/error-on-unknown-config
Tools: Persist config errors until validation occurs
2 parents f12afde + 5795f53 commit fab0849

File tree

2 files changed

+26
-37
lines changed

2 files changed

+26
-37
lines changed

tools/build_api.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,7 @@ def get_config(src_paths, target, toolchain_name, app_config=None):
137137
app_config=app_config)
138138

139139
# Scan src_path for config files
140-
resources = toolchain.scan_resources(src_paths[0])
141-
for path in src_paths[1:]:
142-
resources.add(toolchain.scan_resources(path))
143-
144-
# Update configuration files until added features creates no changes
145-
prev_features = set()
146-
while True:
147-
# Update the configuration with any .json files found while scanning
148-
toolchain.config.add_config_files(resources.json_files)
149-
150-
# Add features while we find new ones
151-
features = set(toolchain.config.get_features())
152-
if features == prev_features:
153-
break
154-
155-
for feature in features:
156-
if feature in resources.features:
157-
resources += resources.features[feature]
158-
159-
prev_features = features
160-
toolchain.config.validate_config()
140+
scan_resources(src_paths, toolchain)
161141
if toolchain.config.has_regions:
162142
_ = list(toolchain.config.regions)
163143

tools/config/__init__.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ class ConfigException(Exception):
6868
errors"""
6969
pass
7070

71+
class UndefinedParameter(ConfigException):
72+
def __init__(self, param, name, kind, label):
73+
self.param = param
74+
self.name = name
75+
self.kind = kind
76+
self.label = label
77+
78+
def __str__(self):
79+
return "Attempt to override undefined parameter '{}' in '{}'".format(
80+
self.param,
81+
ConfigParameter.get_display_name(self.name, self.kind, self.label),
82+
)
83+
7184
class ConfigParameter(object):
7285
"""This class keeps information about a single configuration parameter"""
7386

@@ -430,6 +443,7 @@ def __init__(self, tgt, top_level_dirs=None, app_config=None):
430443
search for a configuration file).
431444
"""
432445
config_errors = []
446+
self.config_errors = []
433447
self.app_config_location = app_config
434448
if self.app_config_location is None and top_level_dirs:
435449
self.app_config_location = self.find_app_config(top_level_dirs)
@@ -571,7 +585,7 @@ def sectors(self):
571585
raise ConfigException("No sector info available")
572586

573587
def _get_cmsis_part(self):
574-
if not self.target.bootloader_supported:
588+
if not getattr(self.target, "bootloader_supported", False):
575589
raise ConfigException("Bootloader not supported on this target.")
576590
if not hasattr(self.target, "device_name"):
577591
raise ConfigException("Bootloader not supported on this target: "
@@ -788,7 +802,6 @@ def _process_config_and_overrides(self, data, params, unit_name, unit_kind):
788802
unit_name - the unit (library/application) that defines this parameter
789803
unit_kind - the kind of the unit ("library" or "application")
790804
"""
791-
self.config_errors = []
792805
_process_config_parameters(data.get("config", {}), params, unit_name,
793806
unit_kind)
794807
for label, overrides in data.get("target_overrides", {}).items():
@@ -857,13 +870,8 @@ def _process_config_and_overrides(self, data, params, unit_name, unit_kind):
857870
continue
858871
else:
859872
self.config_errors.append(
860-
ConfigException(
861-
"Attempt to override undefined parameter" +
862-
(" '%s' in '%s'"
863-
% (full_name,
864-
ConfigParameter.get_display_name(unit_name,
865-
unit_kind,
866-
label)))))
873+
UndefinedParameter(
874+
full_name, unit_name, unit_kind, label))
867875

868876
for cumulatives in self.cumulative_overrides.values():
869877
cumulatives.update_target(self.target)
@@ -911,10 +919,7 @@ def get_target_config_data(self):
911919
continue
912920
if (full_name not in params) or \
913921
(params[full_name].defined_by[7:] not in rel_names):
914-
raise ConfigException(
915-
"Attempt to override undefined parameter '%s' in '%s'"
916-
% (name,
917-
ConfigParameter.get_display_name(tname, "target")))
922+
raise UndefinedParameter(name, tname, "target", "")
918923
# Otherwise update the value of the parameter
919924
params[full_name].set_value(val, tname, "target")
920925
return params
@@ -1050,8 +1055,13 @@ def validate_config(self):
10501055
10511056
Arguments: None
10521057
"""
1053-
if self.config_errors:
1054-
raise self.config_errors[0]
1058+
params, _ = self.get_config_data()
1059+
for error in self.config_errors:
1060+
if (isinstance(error, UndefinedParameter) and
1061+
error.param in params):
1062+
continue
1063+
else:
1064+
raise error
10551065
return True
10561066

10571067

@@ -1071,7 +1081,6 @@ def load_resources(self, resources):
10711081
"""
10721082
# Update configuration files until added features creates no changes
10731083
prev_features = set()
1074-
self.validate_config()
10751084
while True:
10761085
# Add/update the configuration with any .json files found while
10771086
# scanning

0 commit comments

Comments
 (0)