diff options
-rw-r--r-- | buildstream/buildelement.py | 12 | ||||
-rw-r--r-- | buildstream/plugin.py | 25 | ||||
-rw-r--r-- | buildstream/plugins/elements/compose.py | 4 | ||||
-rw-r--r-- | buildstream/plugins/elements/dpkg_deploy.py | 5 | ||||
-rw-r--r-- | buildstream/plugins/elements/script.py | 6 | ||||
-rw-r--r-- | buildstream/plugins/elements/x86image.py | 3 | ||||
-rw-r--r-- | tests/project/data/plugins/elements/custom.py | 1 |
7 files changed, 52 insertions, 4 deletions
diff --git a/buildstream/buildelement.py b/buildstream/buildelement.py index 859b682ad..4776c90d5 100644 --- a/buildstream/buildelement.py +++ b/buildstream/buildelement.py @@ -114,11 +114,15 @@ class BuildElement(Element): def configure(self, node): self.commands = {} + command_names = [prefix + step for step in _command_steps for prefix in _command_prefixes] - for step in _command_steps: - for prefix in _command_prefixes: - command_name = prefix + step - self.commands[command_name] = self._get_commands(node, command_name) + # FIXME: Currently this forcefully validates configurations + # for all BuildElement subclasses so they are unable to + # extend the configuration + self.node_validate(node, command_names) + + for command_name in command_names: + self.commands[command_name] = self._get_commands(node, command_name) def preflight(self): pass diff --git a/buildstream/plugin.py b/buildstream/plugin.py index 775215462..110d865f5 100644 --- a/buildstream/plugin.py +++ b/buildstream/plugin.py @@ -207,6 +207,31 @@ class Plugin(): """ return _yaml.node_get(node, expected_type, member_name, default_value=default_value) + def node_validate(self, node, valid_keys): + """This should be used in :func:`~buildstream.plugin.Plugin.configure` + implementations to assert that users have only entered + valid configuration keys. + + Args: + node (dict): A dictionary loaded from YAML + valid_keys (iterable): A list of valid keys for the node + + Raises: + :class:`.LoadError`: When an invalid key is found + + **Example:** + + .. code:: python + + # Ensure our node only contains valid autotools config keys + self.node_validate(node, [ + 'configure-commands', 'build-commands', + 'install-commands', 'strip-commands' + ]) + + """ + _yaml.validate_node(node, valid_keys) + def node_get_list_element(self, node, expected_type, member_name, indices): """Fetch the value of a list element from a node member, raising an error if the value is incorrectly typed. diff --git a/buildstream/plugins/elements/compose.py b/buildstream/plugins/elements/compose.py index 4d58c1ccc..9d701c72f 100644 --- a/buildstream/plugins/elements/compose.py +++ b/buildstream/plugins/elements/compose.py @@ -48,6 +48,10 @@ class ComposeElement(Element): BST_STRICT_REBUILD = True def configure(self, node): + self.node_validate(node, [ + 'integrate', 'include', 'exclude', 'include-orphans' + ]) + # We name this variable 'integration' only to avoid # collision with the Element.integrate() method. self.integration = self.node_get_member(node, bool, 'integrate') diff --git a/buildstream/plugins/elements/dpkg_deploy.py b/buildstream/plugins/elements/dpkg_deploy.py index e2b3470a0..c87357cbe 100644 --- a/buildstream/plugins/elements/dpkg_deploy.py +++ b/buildstream/plugins/elements/dpkg_deploy.py @@ -141,6 +141,11 @@ class DpkgDeployElement(ScriptElement): prefixes = ["pre-", "", "post-"] groups = ["build-commands"] + self.node_validate(node, [ + 'pre-build-commands', 'build-commands', 'post-build-commands', + 'base', 'input' + ]) + self.__input = self.node_subst_member(node, 'input') self.layout_add(self.node_subst_member(node, 'base'), "/") self.layout_add(None, '/buildstream') diff --git a/buildstream/plugins/elements/script.py b/buildstream/plugins/elements/script.py index 7198af8aa..2b3ca969d 100644 --- a/buildstream/plugins/elements/script.py +++ b/buildstream/plugins/elements/script.py @@ -48,6 +48,12 @@ class ScriptElement(buildstream.ScriptElement): cmds = [] prefixes = ["pre-", "", "post-"] + + self.node_validate(node, [ + 'pre-commands', 'commands', 'post-commands', + 'root-read-only', 'layout' + ]) + if "commands" not in node: raise ElementError("{}: Unexpectedly missing command group 'commands'" .format(self)) diff --git a/buildstream/plugins/elements/x86image.py b/buildstream/plugins/elements/x86image.py index 410b53de8..4bd0ca91a 100644 --- a/buildstream/plugins/elements/x86image.py +++ b/buildstream/plugins/elements/x86image.py @@ -41,6 +41,9 @@ class X86ImageElement(ScriptElement): "partition-commands", "final-commands" ] + + self.node_validate(node, (prefix + group for group in groups for prefix in prefixes)) + for group in groups: cmds = [] if group not in node: diff --git a/tests/project/data/plugins/elements/custom.py b/tests/project/data/plugins/elements/custom.py index 2894a92f3..97379316c 100644 --- a/tests/project/data/plugins/elements/custom.py +++ b/tests/project/data/plugins/elements/custom.py @@ -5,6 +5,7 @@ class CustomElement(Element): def configure(self, node): print("Element Data: %s" % node) + self.node_validate(node, ['configuration']) self.configuration = self.node_subst_member(node, "configuration", default_value='') def preflight(self): |