Qinusty pushed to branch Qinusty/526-fail-on-warnings at BuildStream / buildstream
Commits:
-
c699371b
by Josh Smith at 2018-08-10T13:46:43Z
-
d0baa46c
by Josh Smith at 2018-08-10T13:46:51Z
-
547f784e
by Josh Smith at 2018-08-10T13:46:51Z
-
d0efaeeb
by Josh Smith at 2018-08-10T13:46:51Z
16 changed files:
- buildstream/_project.py
- buildstream/_versions.py
- buildstream/data/projectconfig.yaml
- buildstream/element.py
- 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:
| ... | ... | @@ -31,6 +31,7 @@ from ._options import OptionPool |
| 31 | 31 |
from ._artifactcache import ArtifactCache
|
| 32 | 32 |
from ._elementfactory import ElementFactory
|
| 33 | 33 |
from ._sourcefactory import SourceFactory
|
| 34 |
+from .plugin import CoreWarnings
|
|
| 34 | 35 |
from ._projectrefs import ProjectRefs, ProjectRefStorage
|
| 35 | 36 |
from ._versions import BST_FORMAT_VERSION
|
| 36 | 37 |
from ._loader import Loader
|
| ... | ... | @@ -105,7 +106,7 @@ class Project(): |
| 105 | 106 |
self.first_pass_config = ProjectConfig()
|
| 106 | 107 |
|
| 107 | 108 |
self.junction = junction # The junction Element object, if this is a subproject
|
| 108 |
- self.fail_on_overlap = False # Whether overlaps are treated as errors
|
|
| 109 |
+ |
|
| 109 | 110 |
self.ref_storage = None # ProjectRefStorage setting
|
| 110 | 111 |
self.base_environment = {} # The base set of environment variables
|
| 111 | 112 |
self.base_env_nocache = None # The base nocache mask (list) for the environment
|
| ... | ... | @@ -120,6 +121,9 @@ class Project(): |
| 120 | 121 |
self._cli_options = cli_options
|
| 121 | 122 |
self._cache_key = None
|
| 122 | 123 |
|
| 124 |
+ self._fatal_warnings = [] # A list of warnings which should trigger an error
|
|
| 125 |
+ self._all_warnings_are_fatal = False # A flag set to true if all warnings should be considered fatal
|
|
| 126 |
+ |
|
| 123 | 127 |
self._shell_command = [] # The default interactive shell command
|
| 124 | 128 |
self._shell_environment = {} # Statically set environment vars
|
| 125 | 129 |
self._shell_host_files = [] # A list of HostMount objects
|
| ... | ... | @@ -456,7 +460,7 @@ class Project(): |
| 456 | 460 |
'split-rules', 'elements', 'plugins',
|
| 457 | 461 |
'aliases', 'name',
|
| 458 | 462 |
'artifacts', 'options',
|
| 459 |
- 'fail-on-overlap', 'shell',
|
|
| 463 |
+ 'fail-on-overlap', 'shell', 'fatal-warnings',
|
|
| 460 | 464 |
'ref-storage', 'sandbox', 'mirrors'
|
| 461 | 465 |
])
|
| 462 | 466 |
|
| ... | ... | @@ -478,8 +482,38 @@ class Project(): |
| 478 | 482 |
# Load project split rules
|
| 479 | 483 |
self._splits = _yaml.node_get(config, Mapping, 'split-rules')
|
| 480 | 484 |
|
| 481 |
- # Fail on overlap
|
|
| 482 |
- self.fail_on_overlap = _yaml.node_get(config, bool, 'fail-on-overlap')
|
|
| 485 |
+ # Fatal warnings
|
|
| 486 |
+ p = _yaml.node_get_provenance(config, 'fatal-warnings')
|
|
| 487 |
+ try: # Check for bool type
|
|
| 488 |
+ fatal_warnings = _yaml.node_get(config, bool, 'fatal-warnings', default_value=False)
|
|
| 489 |
+ except LoadError:
|
|
| 490 |
+ try: # Check for list type
|
|
| 491 |
+ fatal_warnings = _yaml.node_get(config, list, 'fatal-warnings', default_value=[])
|
|
| 492 |
+ except LoadError:
|
|
| 493 |
+ raise LoadError(LoadErrorReason.INVALID_DATA,
|
|
| 494 |
+ "{}: Invalid value specified for 'fatal-warnings', ".format(p) +
|
|
| 495 |
+ "must be list or bool.")
|
|
| 496 |
+ |
|
| 497 |
+ # Set fatal warnings
|
|
| 498 |
+ self._set_fatal_warnings(fatal_warnings)
|
|
| 499 |
+ |
|
| 500 |
+ # Support backwards compatibility for fail-on-overlap
|
|
| 501 |
+ |
|
| 502 |
+ fail_on_overlap = _yaml.node_get(config, bool, 'fail-on-overlap', default_value=None)
|
|
| 503 |
+ |
|
| 504 |
+ if CoreWarnings.OVERLAPS not in self._fatal_warnings and fail_on_overlap:
|
|
| 505 |
+ self._fatal_warnings.append(CoreWarnings.OVERLAPS)
|
|
| 506 |
+ |
|
| 507 |
+ # Deprecation check
|
|
| 508 |
+ if fail_on_overlap is not None:
|
|
| 509 |
+ self._context.message(
|
|
| 510 |
+ Message(
|
|
| 511 |
+ None,
|
|
| 512 |
+ MessageType.WARN,
|
|
| 513 |
+ "Use of fail-on-overlap within project.conf " +
|
|
| 514 |
+ "is deprecated. Consider using fatal-warnings instead."
|
|
| 515 |
+ )
|
|
| 516 |
+ )
|
|
| 483 | 517 |
|
| 484 | 518 |
# Load project.refs if it exists, this may be ignored.
|
| 485 | 519 |
if self.ref_storage == ProjectRefStorage.PROJECT_REFS:
|
| ... | ... | @@ -712,3 +746,36 @@ class Project(): |
| 712 | 746 |
# paths are passed in relative to the project, but must be absolute
|
| 713 | 747 |
origin_dict['path'] = os.path.join(self.directory, path)
|
| 714 | 748 |
destination.append(origin_dict)
|
| 749 |
+ |
|
| 750 |
+ # _warning_is_fatal():
|
|
| 751 |
+ #
|
|
| 752 |
+ # Returns true if the warning in question should be considered fatal based on
|
|
| 753 |
+ # the project configuration.
|
|
| 754 |
+ #
|
|
| 755 |
+ # Args:
|
|
| 756 |
+ # warning_str (str): The warning configuration string to check against
|
|
| 757 |
+ #
|
|
| 758 |
+ # Returns:
|
|
| 759 |
+ # (bool): True if the warning should be considered fatal and cause an error.
|
|
| 760 |
+ #
|
|
| 761 |
+ def _warning_is_fatal(self, warning_str):
|
|
| 762 |
+ return self._all_warnings_are_fatal or (warning_str in self._fatal_warnings)
|
|
| 763 |
+ |
|
| 764 |
+ # _set_fatal_warnings():
|
|
| 765 |
+ #
|
|
| 766 |
+ # Sets self._fatal_warnings appropriately. If warnings is of type bool self._all_warnings_are_fatal
|
|
| 767 |
+ # wil be set to its value.
|
|
| 768 |
+ #
|
|
| 769 |
+ # Args:
|
|
| 770 |
+ # warnings (list|bool): The warnings to set self._fatal_warnings to.
|
|
| 771 |
+ # If bool, self._all_warnings_are_fatal is set to the boolean value.
|
|
| 772 |
+ # provenance (str): The provenance assosciated with the warnings parameter.
|
|
| 773 |
+ #
|
|
| 774 |
+ def _set_fatal_warnings(self, warnings):
|
|
| 775 |
+ if warnings is None:
|
|
| 776 |
+ return
|
|
| 777 |
+ elif isinstance(warnings, bool):
|
|
| 778 |
+ self._fatal_warnings = []
|
|
| 779 |
+ self._all_warnings_are_fatal = warnings
|
|
| 780 |
+ else:
|
|
| 781 |
+ self._fatal_warnings = warnings
|
| ... | ... | @@ -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
|
| ... | ... | @@ -94,6 +94,7 @@ from . import _cachekey |
| 94 | 94 |
from . import _signals
|
| 95 | 95 |
from . import _site
|
| 96 | 96 |
from ._platform import Platform
|
| 97 |
+from .plugin import CoreWarnings
|
|
| 97 | 98 |
from .sandbox._config import SandboxConfig
|
| 98 | 99 |
|
| 99 | 100 |
from .storage.directory import Directory
|
| ... | ... | @@ -746,32 +747,23 @@ class Element(Plugin): |
| 746 | 747 |
ignored[dep.name] = result.ignored
|
| 747 | 748 |
|
| 748 | 749 |
if overlaps:
|
| 749 |
- overlap_error = overlap_warning = False
|
|
| 750 |
- error_detail = warning_detail = "Staged files overwrite existing files in staging area:\n"
|
|
| 750 |
+ overlap_warning = False
|
|
| 751 |
+ warning_detail = "Staged files overwrite existing files in staging area:\n"
|
|
| 751 | 752 |
for f, elements in overlaps.items():
|
| 752 |
- overlap_error_elements = []
|
|
| 753 | 753 |
overlap_warning_elements = []
|
| 754 | 754 |
# The bottom item overlaps nothing
|
| 755 | 755 |
overlapping_elements = elements[1:]
|
| 756 | 756 |
for elm in overlapping_elements:
|
| 757 | 757 |
element = self.search(scope, elm)
|
| 758 |
- element_project = element._get_project()
|
|
| 759 | 758 |
if not element.__file_is_whitelisted(f):
|
| 760 |
- if element_project.fail_on_overlap:
|
|
| 761 |
- overlap_error_elements.append(elm)
|
|
| 762 |
- overlap_error = True
|
|
| 763 |
- else:
|
|
| 764 |
- overlap_warning_elements.append(elm)
|
|
| 765 |
- overlap_warning = True
|
|
| 759 |
+ overlap_warning_elements.append(elm)
|
|
| 760 |
+ overlap_warning = True
|
|
| 766 | 761 |
|
| 767 | 762 |
warning_detail += _overlap_error_detail(f, overlap_warning_elements, elements)
|
| 768 |
- error_detail += _overlap_error_detail(f, overlap_error_elements, elements)
|
|
| 769 | 763 |
|
| 770 | 764 |
if overlap_warning:
|
| 771 |
- self.warn("Non-whitelisted overlaps detected", detail=warning_detail)
|
|
| 772 |
- if overlap_error:
|
|
| 773 |
- raise ElementError("Non-whitelisted overlaps detected and fail-on-overlaps is set",
|
|
| 774 |
- detail=error_detail, reason="overlap-error")
|
|
| 765 |
+ self.warn("Non-whitelisted overlaps detected", detail=warning_detail,
|
|
| 766 |
+ warning_token=CoreWarnings.OVERLAPS)
|
|
| 775 | 767 |
|
| 776 | 768 |
if ignored:
|
| 777 | 769 |
detail = "Not staging files which would replace non-empty directories:\n"
|
| ... | ... | @@ -2055,7 +2047,7 @@ class Element(Plugin): |
| 2055 | 2047 |
}
|
| 2056 | 2048 |
|
| 2057 | 2049 |
# fail-on-overlap setting cannot affect elements without dependencies
|
| 2058 |
- if project.fail_on_overlap and dependencies:
|
|
| 2050 |
+ if project._warning_is_fatal(CoreWarnings.OVERLAPS) and dependencies:
|
|
| 2059 | 2051 |
self.__cache_key_dict['fail-on-overlap'] = True
|
| 2060 | 2052 |
|
| 2061 | 2053 |
cache_key_dict = self.__cache_key_dict.copy()
|
| ... | ... | @@ -47,6 +47,23 @@ 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 |
+Warnings raised through calling :func:`Plugin.warn() <buildstream.plugin.Plugin.warn>` can provide an optional
|
|
| 53 |
+parameter ``warning_token``, this will raise a :class:`PluginError` if the warning is configured as fatal within
|
|
| 54 |
+the project configuration.
|
|
| 55 |
+ |
|
| 56 |
+Configurable warnings will be prefixed with :func:`Plugin.get_kind() <buildstream.plugin.Plugin.get_kind>`
|
|
| 57 |
+within buildstream and must be prefixed as such in project configurations. For more detail on project configuration
|
|
| 58 |
+see :ref:`Configurable Warnings <configurable_warnings>`.
|
|
| 59 |
+ |
|
| 60 |
+It is important to document these warnings in your plugin documentation to allow users to make full use of them
|
|
| 61 |
+while configuring their projects.
|
|
| 62 |
+ |
|
| 63 |
+Example
|
|
| 64 |
+~~~~~~~
|
|
| 65 |
+If the ``git.py`` plugin uses the warning ``"inconsistent-submodule"`` then it could be referenced in project
|
|
| 66 |
+configuration as ``"git:inconsistent-submodule"``.
|
|
| 50 | 67 |
|
| 51 | 68 |
Plugin Structure
|
| 52 | 69 |
----------------
|
| ... | ... | @@ -103,6 +120,18 @@ from ._exceptions import PluginError, ImplError |
| 103 | 120 |
from ._message import Message, MessageType
|
| 104 | 121 |
|
| 105 | 122 |
|
| 123 |
+class CoreWarnings():
|
|
| 124 |
+ OVERLAPS = "overlaps"
|
|
| 125 |
+ REF_NOT_IN_TRACK = "ref-not-in-track"
|
|
| 126 |
+ |
|
| 127 |
+ |
|
| 128 |
+CORE_WARNINGS = [
|
|
| 129 |
+ value
|
|
| 130 |
+ for name, value in CoreWarnings.__dict__.items()
|
|
| 131 |
+ if not name.startswith("__")
|
|
| 132 |
+]
|
|
| 133 |
+ |
|
| 134 |
+ |
|
| 106 | 135 |
class Plugin():
|
| 107 | 136 |
"""Plugin()
|
| 108 | 137 |
|
| ... | ... | @@ -166,7 +195,6 @@ class Plugin(): |
| 166 | 195 |
# Infer the kind identifier
|
| 167 | 196 |
modulename = type(self).__module__
|
| 168 | 197 |
self.__kind = modulename.split('.')[-1]
|
| 169 |
- |
|
| 170 | 198 |
self.debug("Created: {}".format(self))
|
| 171 | 199 |
|
| 172 | 200 |
def __del__(self):
|
| ... | ... | @@ -473,14 +501,27 @@ class Plugin(): |
| 473 | 501 |
"""
|
| 474 | 502 |
self.__message(MessageType.INFO, brief, detail=detail)
|
| 475 | 503 |
|
| 476 |
- def warn(self, brief, *, detail=None):
|
|
| 477 |
- """Print a warning message
|
|
| 504 |
+ def warn(self, brief, *, detail=None, warning_token=None):
|
|
| 505 |
+ """Print a warning message, checks warning_token against project configuration
|
|
| 478 | 506 |
|
| 479 | 507 |
Args:
|
| 480 | 508 |
brief (str): The brief message
|
| 481 | 509 |
detail (str): An optional detailed message, can be multiline output
|
| 510 |
+ warning_token (str): An optional configurable warning assosciated with this warning,
|
|
| 511 |
+ this will cause PluginError to be raised if this warning is configured as fatal.
|
|
| 512 |
+ (*Since 1.4*)
|
|
| 513 |
+ |
|
| 514 |
+ Raises:
|
|
| 515 |
+ (:class:`.PluginError`): When warning_token is considered fatal by the project configuration
|
|
| 482 | 516 |
"""
|
| 483 |
- self.__message(MessageType.WARN, brief, detail=detail)
|
|
| 517 |
+ if warning_token:
|
|
| 518 |
+ warning_token = _prefix_warning(self, warning_token)
|
|
| 519 |
+ brief = "[{}]: {}".format(warning_token, brief)
|
|
| 520 |
+ |
|
| 521 |
+ if self.__warning_is_fatal(warning_token):
|
|
| 522 |
+ raise PluginError(message="{}\n{}".format(brief, detail), reason=warning_token)
|
|
| 523 |
+ |
|
| 524 |
+ self.__message(MessageType.WARN, brief=brief, detail=detail)
|
|
| 484 | 525 |
|
| 485 | 526 |
def log(self, brief, *, detail=None):
|
| 486 | 527 |
"""Log a message into the plugin's log file
|
| ... | ... | @@ -708,6 +749,9 @@ class Plugin(): |
| 708 | 749 |
else:
|
| 709 | 750 |
return self.name
|
| 710 | 751 |
|
| 752 |
+ def __warning_is_fatal(self, warning):
|
|
| 753 |
+ return self._get_project()._warning_is_fatal(warning)
|
|
| 754 |
+ |
|
| 711 | 755 |
|
| 712 | 756 |
# Hold on to a lookup table by counter of all instantiated plugins.
|
| 713 | 757 |
# We use this to send the id back from child processes so we can lookup
|
| ... | ... | @@ -739,6 +783,23 @@ def _plugin_lookup(unique_id): |
| 739 | 783 |
return __PLUGINS_TABLE[unique_id]
|
| 740 | 784 |
|
| 741 | 785 |
|
| 786 |
+# _prefix_warning():
|
|
| 787 |
+#
|
|
| 788 |
+# Prefix a warning with the plugin kind. CoreWarnings are not prefixed.
|
|
| 789 |
+#
|
|
| 790 |
+# Args:
|
|
| 791 |
+# plugin (Plugin): The plugin which raised the warning
|
|
| 792 |
+# warning (str): The warning to prefix
|
|
| 793 |
+#
|
|
| 794 |
+# Returns:
|
|
| 795 |
+# (str): A prefixed warning
|
|
| 796 |
+#
|
|
| 797 |
+def _prefix_warning(plugin, warning):
|
|
| 798 |
+ if any([warning is core_warning for core_warning in CORE_WARNINGS]):
|
|
| 799 |
+ return warning
|
|
| 800 |
+ return "{}:{}".format(plugin.get_kind(), warning)
|
|
| 801 |
+ |
|
| 802 |
+ |
|
| 742 | 803 |
# No need for unregister, WeakValueDictionary() will remove entries
|
| 743 | 804 |
# in itself when the referenced plugins are garbage collected.
|
| 744 | 805 |
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,74 @@ 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 |
+ When used in combination with ``fatal-warnings``, setting ``fail-on-overlap: False`` can be overriden by ``fatal-warnings``.
|
|
| 189 |
+ |
|
| 190 |
+ |
|
| 191 |
+.. _ref_not_in_track:
|
|
| 192 |
+ |
|
| 193 |
+Ref not in track
|
|
| 194 |
+~~~~~~~~~~~~~~~~
|
|
| 195 |
+The configured ref is not valid for the configured track.
|
|
| 196 |
+ |
|
| 146 | 197 |
|
| 147 | 198 |
.. _project_source_aliases:
|
| 148 | 199 |
|
| 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")
|
| 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 configure_sandbox(self, sandbox):
|
|
| 17 |
+ pass
|
|
| 18 |
+ |
|
| 19 |
+ def stage(self, sandbox):
|
|
| 20 |
+ pass
|
|
| 21 |
+ |
|
| 22 |
+ def assemble(self, sandbox):
|
|
| 23 |
+ self.warn("Testing: warning-a produced during assemble", warning_token=WARNING_A)
|
|
| 24 |
+ |
|
| 25 |
+ |
|
| 26 |
+def setup():
|
|
| 27 |
+ 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 configure_sandbox(self, sandbox):
|
|
| 17 |
+ pass
|
|
| 18 |
+ |
|
| 19 |
+ def stage(self, sandbox):
|
|
| 20 |
+ pass
|
|
| 21 |
+ |
|
| 22 |
+ def assemble(self, sandbox):
|
|
| 23 |
+ self.warn("Testing: warning-b produced during assemble", warning_token=WARNING_B)
|
|
| 24 |
+ |
|
| 25 |
+ |
|
| 26 |
+def setup():
|
|
| 27 |
+ 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,30 +17,35 @@ 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)
|
| 42 |
- result.assert_task_error(ErrorDomain.ELEMENT, "overlap-error")
|
|
| 48 |
+ result.assert_task_error(ErrorDomain.PLUGIN, CoreWarnings.OVERLAPS)
|
|
| 43 | 49 |
|
| 44 | 50 |
|
| 45 | 51 |
@pytest.mark.datafiles(DATA_DIR)
|
| ... | ... | @@ -70,15 +76,16 @@ def test_overlaps_whitelist_on_overlapper(cli, datafiles): |
| 70 | 76 |
result = cli.run(project=project_dir, silent=True, args=[
|
| 71 | 77 |
'build', 'collect-partially-whitelisted.bst'])
|
| 72 | 78 |
result.assert_main_error(ErrorDomain.STREAM, None)
|
| 73 |
- result.assert_task_error(ErrorDomain.ELEMENT, "overlap-error")
|
|
| 79 |
+ result.assert_task_error(ErrorDomain.PLUGIN, CoreWarnings.OVERLAPS)
|
|
| 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()
|
