Skip to content

Tools: Persist config errors until validation occurs #7277

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 4 commits into from
Jul 5, 2018
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
22 changes: 1 addition & 21 deletions tools/build_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,7 @@ def get_config(src_paths, target, toolchain_name, app_config=None):
app_config=app_config)

# Scan src_path for config files
resources = toolchain.scan_resources(src_paths[0])
for path in src_paths[1:]:
resources.add(toolchain.scan_resources(path))

# Update configuration files until added features creates no changes
prev_features = set()
while True:
# Update the configuration with any .json files found while scanning
toolchain.config.add_config_files(resources.json_files)

# Add features while we find new ones
features = set(toolchain.config.get_features())
if features == prev_features:
break

for feature in features:
if feature in resources.features:
resources += resources.features[feature]

prev_features = features
toolchain.config.validate_config()
scan_resources(src_paths, toolchain)
if toolchain.config.has_regions:
_ = list(toolchain.config.regions)

Expand Down
41 changes: 25 additions & 16 deletions tools/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ class ConfigException(Exception):
errors"""
pass

class UndefinedParameter(ConfigException):
def __init__(self, param, name, kind, label):
self.param = param
self.name = name
self.kind = kind
self.label = label

def __str__(self):
return "Attempt to override undefined parameter '{}' in '{}'".format(
self.param,
ConfigParameter.get_display_name(self.name, self.kind, self.label),
)

class ConfigParameter(object):
"""This class keeps information about a single configuration parameter"""

Expand Down Expand Up @@ -430,6 +443,7 @@ def __init__(self, tgt, top_level_dirs=None, app_config=None):
search for a configuration file).
"""
config_errors = []
self.config_errors = []
self.app_config_location = app_config
if self.app_config_location is None and top_level_dirs:
self.app_config_location = self.find_app_config(top_level_dirs)
Expand Down Expand Up @@ -571,7 +585,7 @@ def sectors(self):
raise ConfigException("No sector info available")

def _get_cmsis_part(self):
if not self.target.bootloader_supported:
if not getattr(self.target, "bootloader_supported", False):
raise ConfigException("Bootloader not supported on this target.")
if not hasattr(self.target, "device_name"):
raise ConfigException("Bootloader not supported on this target: "
Expand Down Expand Up @@ -788,7 +802,6 @@ def _process_config_and_overrides(self, data, params, unit_name, unit_kind):
unit_name - the unit (library/application) that defines this parameter
unit_kind - the kind of the unit ("library" or "application")
"""
self.config_errors = []
_process_config_parameters(data.get("config", {}), params, unit_name,
unit_kind)
for label, overrides in data.get("target_overrides", {}).items():
Expand Down Expand Up @@ -857,13 +870,8 @@ def _process_config_and_overrides(self, data, params, unit_name, unit_kind):
continue
else:
self.config_errors.append(
ConfigException(
"Attempt to override undefined parameter" +
(" '%s' in '%s'"
% (full_name,
ConfigParameter.get_display_name(unit_name,
unit_kind,
label)))))
UndefinedParameter(
full_name, unit_name, unit_kind, label))

for cumulatives in self.cumulative_overrides.values():
cumulatives.update_target(self.target)
Expand Down Expand Up @@ -911,10 +919,7 @@ def get_target_config_data(self):
continue
if (full_name not in params) or \
(params[full_name].defined_by[7:] not in rel_names):
raise ConfigException(
"Attempt to override undefined parameter '%s' in '%s'"
% (name,
ConfigParameter.get_display_name(tname, "target")))
raise UndefinedParameter(name, tname, "target", "")
# Otherwise update the value of the parameter
params[full_name].set_value(val, tname, "target")
return params
Expand Down Expand Up @@ -1050,8 +1055,13 @@ def validate_config(self):

Arguments: None
"""
if self.config_errors:
raise self.config_errors[0]
params, _ = self.get_config_data()
for error in self.config_errors:
if (isinstance(error, UndefinedParameter) and
error.param in params):
continue
else:
raise error
return True


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