Qinusty pushed to branch Qinusty/526-fail-on-warnings at BuildStream / buildstream
Commits:
-
2eeb5245
by Josh Smith at 2018-08-09T16:49:45Z
-
d37e5c5b
by Josh Smith at 2018-08-09T16:50:08Z
-
fc7d6a0c
by Josh Smith at 2018-08-09T16:50:08Z
-
bec0190f
by Josh Smith at 2018-08-09T16:50:08Z
16 changed files:
- buildstream/_project.py
- buildstream/_stream.py
- buildstream/_versions.py
- buildstream/data/projectconfig.yaml
- buildstream/plugin.py
- buildstream/plugins/sources/git.py
- doc/source/format_project.rst
- + tests/frontend/configurable_warnings.py
- + tests/frontend/configuredwarning/elements/corewarn.bst
- + tests/frontend/configuredwarning/elements/warninga.bst
- + tests/frontend/configuredwarning/elements/warningb.bst
- + tests/frontend/configuredwarning/plugins/corewarn.py
- + tests/frontend/configuredwarning/plugins/warninga.py
- + tests/frontend/configuredwarning/plugins/warningb.py
- + tests/frontend/configuredwarning/project.conf
- tests/frontend/overlaps.py
Changes:
... | ... | @@ -32,6 +32,7 @@ from ._options import OptionPool |
32 | 32 |
from ._artifactcache import ArtifactCache
|
33 | 33 |
from ._elementfactory import ElementFactory
|
34 | 34 |
from ._sourcefactory import SourceFactory
|
35 |
+from .plugin import all_warnings, CoreWarnings
|
|
35 | 36 |
from ._projectrefs import ProjectRefs, ProjectRefStorage
|
36 | 37 |
from ._versions import BST_FORMAT_VERSION
|
37 | 38 |
from ._loader import Loader
|
... | ... | @@ -106,7 +107,7 @@ class Project(): |
106 | 107 |
self.first_pass_config = ProjectConfig()
|
107 | 108 |
|
108 | 109 |
self.junction = junction # The junction Element object, if this is a subproject
|
109 |
- self.fail_on_overlap = False # Whether overlaps are treated as errors
|
|
110 |
+ |
|
110 | 111 |
self.ref_storage = None # ProjectRefStorage setting
|
111 | 112 |
self.base_environment = {} # The base set of environment variables
|
112 | 113 |
self.base_env_nocache = None # The base nocache mask (list) for the environment
|
... | ... | @@ -121,6 +122,10 @@ class Project(): |
121 | 122 |
self._cli_options = cli_options
|
122 | 123 |
self._cache_key = None
|
123 | 124 |
|
125 |
+ self._fail_on_overlap = False # Whether to fail on overlaps or not # Deprecated use _warning_is_fatal()
|
|
126 |
+ self._fatal_warnings = [] # A list of warnings which should trigger an error
|
|
127 |
+ self._fatal_warnings_provenance = {} # A lookup table for where fatal warnings came from.
|
|
128 |
+ |
|
124 | 129 |
self._shell_command = [] # The default interactive shell command
|
125 | 130 |
self._shell_environment = {} # Statically set environment vars
|
126 | 131 |
self._shell_host_files = [] # A list of HostMount objects
|
... | ... | @@ -364,6 +369,18 @@ class Project(): |
364 | 369 |
# Reset the element loader state
|
365 | 370 |
Element._reset_load_state()
|
366 | 371 |
|
372 |
+ # fail_on_overlap
|
|
373 |
+ #
|
|
374 |
+ # Property added to continue support of Project.fail_on_overlap after
|
|
375 |
+ # introduction of fatal-warnings configuration item.
|
|
376 |
+ #
|
|
377 |
+ # Returns:
|
|
378 |
+ # (bool): True if the configuration specifies that overlaps should
|
|
379 |
+ # cause errors instead of warnings.
|
|
380 |
+ @property
|
|
381 |
+ def fail_on_overlap(self):
|
|
382 |
+ return self._fail_on_overlap or self._warning_is_fatal(CoreWarnings.OVERLAPS)
|
|
383 |
+ |
|
367 | 384 |
# _load():
|
368 | 385 |
#
|
369 | 386 |
# Loads the project configuration file in the project
|
... | ... | @@ -457,7 +474,7 @@ class Project(): |
457 | 474 |
'split-rules', 'elements', 'plugins',
|
458 | 475 |
'aliases', 'name',
|
459 | 476 |
'artifacts', 'options',
|
460 |
- 'fail-on-overlap', 'shell',
|
|
477 |
+ 'fail-on-overlap', 'shell', 'fatal-warnings',
|
|
461 | 478 |
'ref-storage', 'sandbox', 'mirrors'
|
462 | 479 |
])
|
463 | 480 |
|
... | ... | @@ -480,7 +497,35 @@ class Project(): |
480 | 497 |
self._splits = _yaml.node_get(config, Mapping, 'split-rules')
|
481 | 498 |
|
482 | 499 |
# Fail on overlap
|
483 |
- self.fail_on_overlap = _yaml.node_get(config, bool, 'fail-on-overlap')
|
|
500 |
+ self._fail_on_overlap = _yaml.node_get(config, bool, 'fail-on-overlap', default_value=None)
|
|
501 |
+ |
|
502 |
+ # Deprecation check now that message handler is initialized
|
|
503 |
+ if self._fail_on_overlap is not None:
|
|
504 |
+ self._context.message(
|
|
505 |
+ Message(
|
|
506 |
+ None,
|
|
507 |
+ MessageType.WARN,
|
|
508 |
+ "Use of fail-on-overlap within project.conf " +
|
|
509 |
+ "is deprecated. Please use fatal-warnings instead."
|
|
510 |
+ )
|
|
511 |
+ )
|
|
512 |
+ |
|
513 |
+ # Fatal warnings
|
|
514 |
+ p = _yaml.node_get_provenance(config, 'fatal-warnings')
|
|
515 |
+ try: # Check for bool type
|
|
516 |
+ fatal_warnings = _yaml.node_get(config, bool, 'fatal-warnings', default_value=False)
|
|
517 |
+ except (ValueError, LoadError) as e:
|
|
518 |
+ try: # Check for list type
|
|
519 |
+ fatal_warnings = _yaml.node_get(config, list, 'fatal-warnings', default_value=[])
|
|
520 |
+ except (ValueError, LoadError):
|
|
521 |
+ raise LoadError(LoadErrorReason.INVALID_DATA,
|
|
522 |
+ "{}: Invalid value specified for 'fatal-warnings', ".format(p) +
|
|
523 |
+ "must be list or bool.")
|
|
524 |
+ |
|
525 |
+ |
|
526 |
+ |
|
527 |
+ # Validate and set fatal warnings
|
|
528 |
+ self._set_fatal_warnings(fatal_warnings, p)
|
|
484 | 529 |
|
485 | 530 |
# Load project.refs if it exists, this may be ignored.
|
486 | 531 |
if self.ref_storage == ProjectRefStorage.PROJECT_REFS:
|
... | ... | @@ -710,3 +755,60 @@ class Project(): |
710 | 755 |
# paths are passed in relative to the project, but must be absolute
|
711 | 756 |
origin_dict['path'] = os.path.join(self.directory, path)
|
712 | 757 |
destination.append(origin_dict)
|
758 |
+ |
|
759 |
+ # _warning_is_fatal():
|
|
760 |
+ #
|
|
761 |
+ # Returns true if the warning in question should be considered fatal based on
|
|
762 |
+ # the project configuration.
|
|
763 |
+ #
|
|
764 |
+ # Args:
|
|
765 |
+ # warning_str (str): The warning configuration string to check against
|
|
766 |
+ #
|
|
767 |
+ # Returns:
|
|
768 |
+ # (bool): True if the warning should be considered fatal and cause an error.
|
|
769 |
+ #
|
|
770 |
+ def _warning_is_fatal(self, warning_str):
|
|
771 |
+ return warning_str in self._fatal_warnings
|
|
772 |
+ |
|
773 |
+ # _set_fatal_warnings():
|
|
774 |
+ #
|
|
775 |
+ # Sets self._fatal_warnings appropriately
|
|
776 |
+ #
|
|
777 |
+ # Args:
|
|
778 |
+ # warnings (list|bool): The warnings to set self._fatal_warnings to.
|
|
779 |
+ # If True, plugin.ALL_WARNINGS is used. If False, [] is used.
|
|
780 |
+ # provenance (str): The provenance assosciated with the warnings parameter.
|
|
781 |
+ #
|
|
782 |
+ def _set_fatal_warnings(self, warnings, provenance):
|
|
783 |
+ if warnings is None:
|
|
784 |
+ return
|
|
785 |
+ elif isinstance(warnings, bool):
|
|
786 |
+ # This can make self._fatal_warnings a reference to all_warnings if warnings is true.
|
|
787 |
+ # We can't copy because plugins have not been loaded and their warnings aren't in all_warnings.
|
|
788 |
+ self._fatal_warnings = all_warnings if warnings else []
|
|
789 |
+ else:
|
|
790 |
+ self._fatal_warnings = warnings
|
|
791 |
+ |
|
792 |
+ # Record the provenance for this configuration for use within _assert_fatal_warnings
|
|
793 |
+ self._fatal_warnings_provenance = {warning: provenance for warning in self._fatal_warnings}
|
|
794 |
+ |
|
795 |
+ # _assert_fatal_warnings():
|
|
796 |
+ #
|
|
797 |
+ # Checks that the configured fatal-warnings are valid with the currently loaded plugins.
|
|
798 |
+ #
|
|
799 |
+ # Raises:
|
|
800 |
+ # LoadError: When self._fatal_warnings contains warnings not within plugin.all_warnings
|
|
801 |
+ def _assert_fatal_warnings(self):
|
|
802 |
+ # Check for unknown warnings.
|
|
803 |
+ unknown_warnings = list(filter(lambda x: x not in all_warnings, self._fatal_warnings))
|
|
804 |
+ if unknown_warnings: # Restrict 'fatal-warnings' to known warnings
|
|
805 |
+ provenance = self._fatal_warnings_provenance.get(unknown_warnings[0])
|
|
806 |
+ quoted_unknown_warnings = ["'{}'".format(warning) for warning in unknown_warnings]
|
|
807 |
+ quoted_all_warnings = ["'{}'".format(warning) for warning in all_warnings]
|
|
808 |
+ raise LoadError(LoadErrorReason.INVALID_DATA,
|
|
809 |
+ ("{}: Invalid {} provided to fatal-warnings ({})\n" +
|
|
810 |
+ "Valid options are: ({})")
|
|
811 |
+ .format(provenance,
|
|
812 |
+ "warning" if len(unknown_warnings) == 1 else "warnings",
|
|
813 |
+ ", ".join(quoted_unknown_warnings),
|
|
814 |
+ ", ".join(quoted_all_warnings)))
|
... | ... | @@ -860,6 +860,9 @@ class Stream(): |
860 | 860 |
rewritable=rewritable,
|
861 | 861 |
fetch_subprojects=fetch_subprojects)
|
862 | 862 |
|
863 |
+ # Ensure configured warnings are available within loaded plugins
|
|
864 |
+ self._project._assert_fatal_warnings()
|
|
865 |
+ |
|
863 | 866 |
# Hold on to the targets
|
864 | 867 |
self.targets = elements
|
865 | 868 |
|
... | ... | @@ -23,7 +23,7 @@ |
23 | 23 |
# This version is bumped whenever enhancements are made
|
24 | 24 |
# to the `project.conf` format or the core element format.
|
25 | 25 |
#
|
26 |
-BST_FORMAT_VERSION = 13
|
|
26 |
+BST_FORMAT_VERSION = 14
|
|
27 | 27 |
|
28 | 28 |
|
29 | 29 |
# The base BuildStream artifact version
|
... | ... | @@ -14,7 +14,15 @@ element-path: . |
14 | 14 |
ref-storage: inline
|
15 | 15 |
|
16 | 16 |
# Overlaps are just warnings
|
17 |
-fail-on-overlap: False
|
|
17 |
+# This has been DEPRECATED in favour of fatal-warnings
|
|
18 |
+#fail-on-overlap: False
|
|
19 |
+ |
|
20 |
+# Allows a collection of warnings to be configured to be raised as errors.
|
|
21 |
+# Setting this value to true will enable all possible fatal-warnings
|
|
22 |
+# fatal-warnings: True
|
|
23 |
+ |
|
24 |
+# fatal-warnings:
|
|
25 |
+# - overlaps
|
|
18 | 26 |
|
19 | 27 |
|
20 | 28 |
# Variable Configuration
|
... | ... | @@ -47,6 +47,24 @@ it is mandatory to implement the following abstract methods: |
47 | 47 |
Once all configuration has been loaded and preflight checks have passed,
|
48 | 48 |
this method is used to inform the core of a plugin's unique configuration.
|
49 | 49 |
|
50 |
+Configurable Warnings
|
|
51 |
+---------------------
|
|
52 |
+For plugins which wish to provide configurable warnings, it is necessary to override
|
|
53 |
+:func:`Plugin.get_warnings() <buildstream.plugin.Plugin.get_warnings>` to get them registered
|
|
54 |
+with buildstream.
|
|
55 |
+ |
|
56 |
+These warnings are used when calling :func:`Plugin.warn() <buildstream.plugin.Plugin.warn>` as an optional
|
|
57 |
+parameter ``warning_token``, this will raise a :class:`PluginError` if the warning is configured as fatal.
|
|
58 |
+ |
|
59 |
+Configurable warnings will be prefixed with :func:`Plugin.get_kind() <buildstream.plugin.Plugin.get_kind>`
|
|
60 |
+within buildstream and must be prefixed as such in project configurations. For more detail on project configuration
|
|
61 |
+see :ref:`Configurable Warnings <configurable_warnings>`.
|
|
62 |
+ |
|
63 |
+Example
|
|
64 |
+~~~~~~~
|
|
65 |
+If the ``git.py`` plugin made the warning ``"inconsistent-submodule"`` available through
|
|
66 |
+:func:`Plugin.get_warnings() <buildstream.plugin.Plugin.get_warnings>` then it could be referenced in project
|
|
67 |
+configuration as ``"git:inconsistent-submodule"``
|
|
50 | 68 |
|
51 | 69 |
Plugin Structure
|
52 | 70 |
----------------
|
... | ... | @@ -102,6 +120,20 @@ from . import utils |
102 | 120 |
from ._exceptions import PluginError, ImplError
|
103 | 121 |
from ._message import Message, MessageType
|
104 | 122 |
|
123 |
+# Core Warnings must be prefixed with core:
|
|
124 |
+CORE_WARNING_PREFIX = "core:"
|
|
125 |
+class CoreWarnings():
|
|
126 |
+ OVERLAPS = CORE_WARNING_PREFIX + "overlaps"
|
|
127 |
+ REF_NOT_IN_TRACK = CORE_WARNING_PREFIX + "ref-not-in-track"
|
|
128 |
+ |
|
129 |
+CORE_WARNINGS = [
|
|
130 |
+ warning_label
|
|
131 |
+ for var, warning_label in CoreWarnings.__dict__.items()
|
|
132 |
+ if not var.startswith("__")
|
|
133 |
+]
|
|
134 |
+ |
|
135 |
+all_warnings = CORE_WARNINGS + []
|
|
136 |
+ |
|
105 | 137 |
|
106 | 138 |
class Plugin():
|
107 | 139 |
"""Plugin()
|
... | ... | @@ -166,7 +198,7 @@ class Plugin(): |
166 | 198 |
# Infer the kind identifier
|
167 | 199 |
modulename = type(self).__module__
|
168 | 200 |
self.__kind = modulename.split('.')[-1]
|
169 |
- |
|
201 |
+ _register_warnings(self, self.get_warnings())
|
|
170 | 202 |
self.debug("Created: {}".format(self))
|
171 | 203 |
|
172 | 204 |
def __del__(self):
|
... | ... | @@ -473,13 +505,21 @@ class Plugin(): |
473 | 505 |
"""
|
474 | 506 |
self.__message(MessageType.INFO, brief, detail=detail)
|
475 | 507 |
|
476 |
- def warn(self, brief, *, detail=None):
|
|
477 |
- """Print a warning message
|
|
508 |
+ def warn(self, brief, *, detail=None, warning_token=None):
|
|
509 |
+ """Print a warning message, checks warning_token against project configuration
|
|
478 | 510 |
|
479 | 511 |
Args:
|
480 | 512 |
brief (str): The brief message
|
481 | 513 |
detail (str): An optional detailed message, can be multiline output
|
514 |
+ warning_token (str): An optional configurable warning assosciated with this warning,
|
|
515 |
+ this will cause PluginError to be raised if this warning is configured as fatal.
|
|
516 |
+ (*Since 1.4*)
|
|
517 |
+ |
|
518 |
+ Raises:
|
|
519 |
+ (:class:`.PluginError`): When warning_token is considered fatal by the project configuration
|
|
482 | 520 |
"""
|
521 |
+ if warning_token and self.__warning_is_fatal(_prefix_warning(self, warning_token)):
|
|
522 |
+ raise PluginError(message="{}\n{}".format(brief, detail))
|
|
483 | 523 |
self.__message(MessageType.WARN, brief, detail=detail)
|
484 | 524 |
|
485 | 525 |
def log(self, brief, *, detail=None):
|
... | ... | @@ -606,6 +646,21 @@ class Plugin(): |
606 | 646 |
"""
|
607 | 647 |
return self.__call(*popenargs, collect_stdout=True, fail=fail, fail_temporarily=fail_temporarily, **kwargs)
|
608 | 648 |
|
649 |
+ def get_warnings(self):
|
|
650 |
+ """Return a collection of configurable warnings
|
|
651 |
+ |
|
652 |
+ Returns:
|
|
653 |
+ (list of str): A list of strings which will extend the configurable warnings collection.
|
|
654 |
+ |
|
655 |
+ Warnings can be configured as fatal in a project configuration file, any warnings provided here
|
|
656 |
+ will be added to the collection used by buildstream.
|
|
657 |
+ |
|
658 |
+ **Since 1.4**
|
|
659 |
+ |
|
660 |
+ Plugin implementors should override this method to add their own configurable warnings.
|
|
661 |
+ """
|
|
662 |
+ return []
|
|
663 |
+ |
|
609 | 664 |
#############################################################
|
610 | 665 |
# Private Methods used in BuildStream #
|
611 | 666 |
#############################################################
|
... | ... | @@ -708,6 +763,9 @@ class Plugin(): |
708 | 763 |
else:
|
709 | 764 |
return self.name
|
710 | 765 |
|
766 |
+ def __warning_is_fatal(self, warning):
|
|
767 |
+ return self._get_project()._warning_is_fatal(warning)
|
|
768 |
+ |
|
711 | 769 |
|
712 | 770 |
# Hold on to a lookup table by counter of all instantiated plugins.
|
713 | 771 |
# We use this to send the id back from child processes so we can lookup
|
... | ... | @@ -739,6 +797,28 @@ def _plugin_lookup(unique_id): |
739 | 797 |
return __PLUGINS_TABLE[unique_id]
|
740 | 798 |
|
741 | 799 |
|
800 |
+def _prefix_warning(plugin, warning):
|
|
801 |
+ if warning.startswith(CORE_WARNING_PREFIX):
|
|
802 |
+ return warning
|
|
803 |
+ return "{}:{}".format(plugin.get_kind(), warning)
|
|
804 |
+ |
|
805 |
+ |
|
806 |
+# _register_warnings():
|
|
807 |
+#
|
|
808 |
+# Registers a collection of warnings from a plugin into all_warnings
|
|
809 |
+#
|
|
810 |
+# Args:
|
|
811 |
+# plugin (Plugin): The plugin assosciated with the warnings.
|
|
812 |
+# warnings (list of str): The collection of warnings to prefix and register.
|
|
813 |
+#
|
|
814 |
+def _register_warnings(plugin, warnings):
|
|
815 |
+ prefixed_warnings = [
|
|
816 |
+ _prefix_warning(plugin, warning)
|
|
817 |
+ for warning in warnings
|
|
818 |
+ ]
|
|
819 |
+ all_warnings.extend(prefixed_warnings)
|
|
820 |
+ |
|
821 |
+ |
|
742 | 822 |
# No need for unregister, WeakValueDictionary() will remove entries
|
743 | 823 |
# in itself when the referenced plugins are garbage collected.
|
744 | 824 |
def _plugin_register(plugin):
|
... | ... | @@ -68,6 +68,12 @@ git - stage files from a git repository |
68 | 68 |
url: upstream:baz.git
|
69 | 69 |
checkout: False
|
70 | 70 |
|
71 |
+**Configurable Warnings:**
|
|
72 |
+ |
|
73 |
+This plugin provides the following configurable warnings:
|
|
74 |
+ |
|
75 |
+- 'git:inconsistent-submodule' - A submodule was found to be missing from the underlying git repository.
|
|
76 |
+ |
|
71 | 77 |
"""
|
72 | 78 |
|
73 | 79 |
import os
|
... | ... | @@ -84,6 +90,9 @@ from buildstream import utils |
84 | 90 |
|
85 | 91 |
GIT_MODULES = '.gitmodules'
|
86 | 92 |
|
93 |
+# Warnings
|
|
94 |
+INCONSISTENT_SUBMODULE = "inconsistent-submodules"
|
|
95 |
+ |
|
87 | 96 |
|
88 | 97 |
# Because of handling of submodules, we maintain a GitMirror
|
89 | 98 |
# for the primary git source and also for each submodule it
|
... | ... | @@ -283,7 +292,7 @@ class GitMirror(SourceFetcher): |
283 | 292 |
"underlying git repository with `git submodule add`."
|
284 | 293 |
|
285 | 294 |
self.source.warn("{}: Ignoring inconsistent submodule '{}'"
|
286 |
- .format(self.source, submodule), detail=detail)
|
|
295 |
+ .format(self.source, submodule), detail=detail, warning_token=INCONSISTENT_SUBMODULE)
|
|
287 | 296 |
|
288 | 297 |
return None
|
289 | 298 |
|
... | ... | @@ -350,6 +359,9 @@ class GitSource(Source): |
350 | 359 |
return Consistency.RESOLVED
|
351 | 360 |
return Consistency.INCONSISTENT
|
352 | 361 |
|
362 |
+ def get_warnings(self):
|
|
363 |
+ return [INCONSISTENT_SUBMODULE]
|
|
364 |
+ |
|
353 | 365 |
def load_ref(self, node):
|
354 | 366 |
self.mirror.ref = self.node_get_member(node, str, 'ref', None)
|
355 | 367 |
|
... | ... | @@ -126,23 +126,72 @@ following to your ``project.conf``: |
126 | 126 |
The ``ref-storage`` configuration is available since :ref:`format version 8 <project_format_version>`
|
127 | 127 |
|
128 | 128 |
|
129 |
+.. _configurable_warnings:
|
|
130 |
+ |
|
131 |
+Configurable Warnings
|
|
132 |
+~~~~~~~~~~~~~~~~~~~~~
|
|
133 |
+Warnings can be configured as fatal using the ``fatal-warnings`` configuration item.
|
|
134 |
+When a warning is configured as fatal, where a warning would usually be thrown instead an error will be thrown
|
|
135 |
+causing the build to fail.
|
|
136 |
+ |
|
137 |
+When ``fatal-warnings`` is True, all configurable fatal warnings will be set as fatal. Individual warnings
|
|
138 |
+can also be set by setting ``fatal-warnings`` to a list of warnings.
|
|
139 |
+ |
|
140 |
+.. code::
|
|
141 |
+ |
|
142 |
+ fatal-warnings:
|
|
143 |
+ - core:overlaps
|
|
144 |
+ - core:ref-not-in-track
|
|
145 |
+ - <plugin>:<warning>
|
|
146 |
+ |
|
147 |
+Core Configurable warnings include:
|
|
148 |
+ |
|
149 |
+- :ref:`core:overlaps <fail_on_overlaps>`
|
|
150 |
+- :ref:`core:ref-not-in-track <ref_not_in_track>`
|
|
151 |
+ |
|
152 |
+.. note::
|
|
153 |
+ |
|
154 |
+ The ``ref-storage`` configuration is available since :ref:`format version 12 <project_format_version>`
|
|
155 |
+ |
|
156 |
+.. note::
|
|
157 |
+ |
|
158 |
+ Other configurable warnings are plugin specific and should be noted within their individual documentation.
|
|
159 |
+ |
|
160 |
+.. _fail_on_overlaps:
|
|
161 |
+ |
|
129 | 162 |
Fail on overlaps
|
130 | 163 |
~~~~~~~~~~~~~~~~
|
131 | 164 |
When multiple elements are staged, there's a possibility that different
|
132 | 165 |
elements will try and stage different versions of the same file.
|
133 | 166 |
|
134 |
-When ``fail-on-overlap`` is true, if an overlap is detected
|
|
135 |
-that hasn't been allowed by the element's
|
|
136 |
-:ref:`overlap whitelist<public_overlap_whitelist>`,
|
|
137 |
-then an error will be raised and the build will fail.
|
|
167 |
+.. deprecated:: 1.4
|
|
168 |
+ |
|
138 | 169 |
|
139 |
-otherwise, a warning will be raised indicating which files had overlaps,
|
|
140 |
-and the order that the elements were overlapped.
|
|
170 |
+ When ``fail-on-overlap`` is true, if an overlap is detected
|
|
171 |
+ that hasn't been allowed by the element's
|
|
172 |
+ :ref:`overlap whitelist<public_overlap_whitelist>`,
|
|
173 |
+ then an error will be raised and the build will fail.
|
|
174 |
+ |
|
175 |
+ Otherwise, a warning will be raised indicating which files had overlaps,
|
|
176 |
+ and the order that the elements were overlapped.
|
|
141 | 177 |
|
142 | 178 |
.. code:: yaml
|
143 | 179 |
|
180 |
+ # Deprecated
|
|
144 | 181 |
fail-on-overlap: true
|
145 | 182 |
|
183 |
+.. note::
|
|
184 |
+ |
|
185 |
+ Since deprecation in :ref:`format version 12 <project_format_version>` the recommended
|
|
186 |
+ solution to this is :ref:`Configurable Warnings <configurable_warnings>`
|
|
187 |
+ |
|
188 |
+ |
|
189 |
+.. _ref_not_in_track:
|
|
190 |
+ |
|
191 |
+Ref not in track
|
|
192 |
+~~~~~~~~~~~~~~~~
|
|
193 |
+The configured ref is not valid for the configured track.
|
|
194 |
+ |
|
146 | 195 |
|
147 | 196 |
.. _project_source_aliases:
|
148 | 197 |
|
1 |
+import pytest
|
|
2 |
+import os
|
|
3 |
+ |
|
4 |
+from buildstream.plugin import CoreWarnings
|
|
5 |
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
|
|
6 |
+from buildstream import _yaml
|
|
7 |
+from tests.testutils.runcli import cli
|
|
8 |
+ |
|
9 |
+TOP_DIR = os.path.join(
|
|
10 |
+ os.path.dirname(os.path.realpath(__file__)),
|
|
11 |
+ "configuredwarning"
|
|
12 |
+)
|
|
13 |
+ |
|
14 |
+ |
|
15 |
+def get_project(fatal_warnings):
|
|
16 |
+ return {
|
|
17 |
+ "name": "test",
|
|
18 |
+ "element-path": "elements",
|
|
19 |
+ "plugins": [
|
|
20 |
+ {
|
|
21 |
+ "origin": "local",
|
|
22 |
+ "path": "plugins",
|
|
23 |
+ "elements": {
|
|
24 |
+ "warninga": 0,
|
|
25 |
+ "warningb": 0,
|
|
26 |
+ "corewarn": 0,
|
|
27 |
+ }
|
|
28 |
+ }
|
|
29 |
+ ],
|
|
30 |
+ "fatal-warnings": fatal_warnings
|
|
31 |
+ }
|
|
32 |
+ |
|
33 |
+ |
|
34 |
+def build_project(datafiles, fatal_warnings):
|
|
35 |
+ project_path = os.path.join(datafiles.dirname, datafiles.basename)
|
|
36 |
+ |
|
37 |
+ project = get_project(fatal_warnings)
|
|
38 |
+ |
|
39 |
+ _yaml.dump(project, os.path.join(project_path, "project.conf"))
|
|
40 |
+ |
|
41 |
+ return project_path
|
|
42 |
+ |
|
43 |
+ |
|
44 |
+@pytest.mark.datafiles(TOP_DIR)
|
|
45 |
+@pytest.mark.parametrize("element_name, fatal_warnings, expect_fatal, error_domain", [
|
|
46 |
+ ("corewarn.bst", [CoreWarnings.OVERLAPS], True, ErrorDomain.STREAM),
|
|
47 |
+ ("warninga.bst", ["warninga:warning-a"], True, ErrorDomain.STREAM),
|
|
48 |
+ ("warningb.bst", ["warningb:warning-b"], True, ErrorDomain.STREAM),
|
|
49 |
+ ("corewarn.bst", [], False, None),
|
|
50 |
+ ("warninga.bst", [], False, None),
|
|
51 |
+ ("warningb.bst", [], False, None),
|
|
52 |
+ ("corewarn.bst", "true", True, ErrorDomain.STREAM),
|
|
53 |
+ ("warninga.bst", "true", True, ErrorDomain.STREAM),
|
|
54 |
+ ("warningb.bst", "true", True, ErrorDomain.STREAM),
|
|
55 |
+ ("warninga.bst", [CoreWarnings.OVERLAPS], False, None),
|
|
56 |
+ ("warningb.bst", [CoreWarnings.OVERLAPS], False, None),
|
|
57 |
+])
|
|
58 |
+def test_fatal_warnings(cli, datafiles, element_name,
|
|
59 |
+ fatal_warnings, expect_fatal, error_domain):
|
|
60 |
+ project_path = build_project(datafiles, fatal_warnings)
|
|
61 |
+ |
|
62 |
+ result = cli.run(project=project_path, args=["build", element_name])
|
|
63 |
+ if expect_fatal:
|
|
64 |
+ result.assert_main_error(error_domain, None, "Expected fatal execution")
|
|
65 |
+ else:
|
|
66 |
+ result.assert_success("Unexpected fatal execution")
|
|
67 |
+ |
|
68 |
+ |
|
69 |
+@pytest.mark.datafiles(TOP_DIR)
|
|
70 |
+def test_invalid_warning(cli, datafiles):
|
|
71 |
+ project_path = build_project(datafiles, ["non-existant-warning"])
|
|
72 |
+ |
|
73 |
+ result = cli.run(project=project_path, args=["build", "corewarn.bst"])
|
|
74 |
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
|
1 |
+kind: corewarn
|
|
\ No newline at end of file |
1 |
+kind: warninga
|
1 |
+kind: warningb
|
1 |
+from buildstream import Element
|
|
2 |
+from buildstream.plugin import CoreWarnings
|
|
3 |
+ |
|
4 |
+ |
|
5 |
+class CoreWarn(Element):
|
|
6 |
+ def configure(self, node):
|
|
7 |
+ pass
|
|
8 |
+ |
|
9 |
+ def preflight(self):
|
|
10 |
+ pass
|
|
11 |
+ |
|
12 |
+ def get_unique_key(self):
|
|
13 |
+ pass
|
|
14 |
+ |
|
15 |
+ def get_warnings(self):
|
|
16 |
+ return [] # CoreWarnings should be included regardless of plugins.
|
|
17 |
+ |
|
18 |
+ def configure_sandbox(self, sandbox):
|
|
19 |
+ pass
|
|
20 |
+ |
|
21 |
+ def stage(self, sandbox):
|
|
22 |
+ pass
|
|
23 |
+ |
|
24 |
+ def assemble(self, sandbox):
|
|
25 |
+ self.warn("Testing: CoreWarning produced during assemble",
|
|
26 |
+ warning_token=CoreWarnings.OVERLAPS)
|
|
27 |
+ |
|
28 |
+ |
|
29 |
+def setup():
|
|
30 |
+ return CoreWarn
|
1 |
+from buildstream import Element
|
|
2 |
+ |
|
3 |
+WARNING_A = "warning-a"
|
|
4 |
+ |
|
5 |
+ |
|
6 |
+class WarningA(Element):
|
|
7 |
+ def configure(self, node):
|
|
8 |
+ pass
|
|
9 |
+ |
|
10 |
+ def preflight(self):
|
|
11 |
+ pass
|
|
12 |
+ |
|
13 |
+ def get_unique_key(self):
|
|
14 |
+ pass
|
|
15 |
+ |
|
16 |
+ def get_warnings(self):
|
|
17 |
+ return [WARNING_A]
|
|
18 |
+ |
|
19 |
+ def configure_sandbox(self, sandbox):
|
|
20 |
+ pass
|
|
21 |
+ |
|
22 |
+ def stage(self, sandbox):
|
|
23 |
+ pass
|
|
24 |
+ |
|
25 |
+ def assemble(self, sandbox):
|
|
26 |
+ self.warn("Testing: warning-a produced during assemble", warning_token=WARNING_A)
|
|
27 |
+ |
|
28 |
+ |
|
29 |
+def setup():
|
|
30 |
+ return WarningA
|
1 |
+from buildstream import Element
|
|
2 |
+ |
|
3 |
+WARNING_B = "warning-b"
|
|
4 |
+ |
|
5 |
+ |
|
6 |
+class WarningB(Element):
|
|
7 |
+ def configure(self, node):
|
|
8 |
+ pass
|
|
9 |
+ |
|
10 |
+ def preflight(self):
|
|
11 |
+ pass
|
|
12 |
+ |
|
13 |
+ def get_unique_key(self):
|
|
14 |
+ pass
|
|
15 |
+ |
|
16 |
+ def get_warnings(self):
|
|
17 |
+ return [WARNING_B]
|
|
18 |
+ |
|
19 |
+ def configure_sandbox(self, sandbox):
|
|
20 |
+ pass
|
|
21 |
+ |
|
22 |
+ def stage(self, sandbox):
|
|
23 |
+ pass
|
|
24 |
+ |
|
25 |
+ def assemble(self, sandbox):
|
|
26 |
+ self.warn("Testing: warning-b produced during assemble", warning_token=WARNING_B)
|
|
27 |
+ |
|
28 |
+ |
|
29 |
+def setup():
|
|
30 |
+ return WarningB
|
1 |
+name: test
|
|
2 |
+element-path: elements
|
|
3 |
+plugins:
|
|
4 |
+- origin: local
|
|
5 |
+ path: element_plugins
|
|
6 |
+ elements:
|
|
7 |
+ warninga: 0
|
|
8 |
+ warningb: 0
|
... | ... | @@ -3,6 +3,7 @@ import pytest |
3 | 3 |
from tests.testutils.runcli import cli
|
4 | 4 |
from buildstream._exceptions import ErrorDomain
|
5 | 5 |
from buildstream import _yaml
|
6 |
+from buildstream.plugin import CoreWarnings
|
|
6 | 7 |
|
7 | 8 |
# Project directory
|
8 | 9 |
DATA_DIR = os.path.join(
|
... | ... | @@ -16,26 +17,31 @@ project_template = { |
16 | 17 |
}
|
17 | 18 |
|
18 | 19 |
|
19 |
-def gen_project(project_dir, fail_on_overlap):
|
|
20 |
+def gen_project(project_dir, fail_on_overlap, use_fatal_warnings=True):
|
|
20 | 21 |
template = dict(project_template)
|
21 |
- template["fail-on-overlap"] = fail_on_overlap
|
|
22 |
+ if use_fatal_warnings:
|
|
23 |
+ template["fatal-warnings"] = [CoreWarnings.OVERLAPS] if fail_on_overlap else []
|
|
24 |
+ else:
|
|
25 |
+ template["fail-on-overlap"] = fail_on_overlap
|
|
22 | 26 |
projectfile = os.path.join(project_dir, "project.conf")
|
23 | 27 |
_yaml.dump(template, projectfile)
|
24 | 28 |
|
25 | 29 |
|
26 | 30 |
@pytest.mark.datafiles(DATA_DIR)
|
27 |
-def test_overlaps(cli, datafiles):
|
|
31 |
+@pytest.mark.parametrize("use_fatal_warnings", [True, False])
|
|
32 |
+def test_overlaps(cli, datafiles, use_fatal_warnings):
|
|
28 | 33 |
project_dir = str(datafiles)
|
29 |
- gen_project(project_dir, False)
|
|
34 |
+ gen_project(project_dir, False, use_fatal_warnings)
|
|
30 | 35 |
result = cli.run(project=project_dir, silent=True, args=[
|
31 | 36 |
'build', 'collect.bst'])
|
32 | 37 |
result.assert_success()
|
33 | 38 |
|
34 | 39 |
|
35 | 40 |
@pytest.mark.datafiles(DATA_DIR)
|
36 |
-def test_overlaps_error(cli, datafiles):
|
|
41 |
+@pytest.mark.parametrize("use_fatal_warnings", [True, False])
|
|
42 |
+def test_overlaps_error(cli, datafiles, use_fatal_warnings):
|
|
37 | 43 |
project_dir = str(datafiles)
|
38 |
- gen_project(project_dir, True)
|
|
44 |
+ gen_project(project_dir, True, use_fatal_warnings)
|
|
39 | 45 |
result = cli.run(project=project_dir, silent=True, args=[
|
40 | 46 |
'build', 'collect.bst'])
|
41 | 47 |
result.assert_main_error(ErrorDomain.STREAM, None)
|
... | ... | @@ -74,11 +80,12 @@ def test_overlaps_whitelist_on_overlapper(cli, datafiles): |
74 | 80 |
|
75 | 81 |
|
76 | 82 |
@pytest.mark.datafiles(DATA_DIR)
|
77 |
-def test_overlaps_script(cli, datafiles):
|
|
83 |
+@pytest.mark.parametrize("use_fatal_warnings", [True, False])
|
|
84 |
+def test_overlaps_script(cli, datafiles, use_fatal_warnings):
|
|
78 | 85 |
# Test overlaps with script element to test
|
79 | 86 |
# Element.stage_dependency_artifacts() with Scope.RUN
|
80 | 87 |
project_dir = str(datafiles)
|
81 |
- gen_project(project_dir, False)
|
|
88 |
+ gen_project(project_dir, False, use_fatal_warnings)
|
|
82 | 89 |
result = cli.run(project=project_dir, silent=True, args=[
|
83 | 90 |
'build', 'script.bst'])
|
84 | 91 |
result.assert_success()
|