Tristan Van Berkom pushed to branch master at BuildStream / buildstream
Commits:
-
4688b2c9
by Tristan Van Berkom at 2018-12-06T07:35:59Z
-
03028c7f
by Tristan Van Berkom at 2018-12-06T07:35:59Z
-
3b7f8df8
by Tristan Van Berkom at 2018-12-06T07:35:59Z
-
e5c0f067
by Tristan Van Berkom at 2018-12-06T07:35:59Z
-
205c27d8
by Tristan Van Berkom at 2018-12-06T07:35:59Z
-
bea4d4f5
by Tristan Van Berkom at 2018-12-06T09:37:50Z
10 changed files:
- buildstream/__init__.py
- buildstream/_loader/loader.py
- buildstream/_project.py
- buildstream/element.py
- buildstream/plugin.py
- buildstream/plugins/sources/git.py
- buildstream/source.py
- buildstream/types.py
- doc/source/format_project.rst
- tests/sources/git.py
Changes:
... | ... | @@ -28,7 +28,7 @@ if "_BST_COMPLETION" not in os.environ: |
28 | 28 |
|
29 | 29 |
from .utils import UtilError, ProgramNotFoundError
|
30 | 30 |
from .sandbox import Sandbox, SandboxFlags, SandboxCommandError
|
31 |
- from .types import Scope, Consistency
|
|
31 |
+ from .types import Scope, Consistency, CoreWarnings
|
|
32 | 32 |
from .plugin import Plugin
|
33 | 33 |
from .source import Source, SourceError, SourceFetcher
|
34 | 34 |
from .element import Element, ElementError
|
... | ... | @@ -36,7 +36,7 @@ from .types import Symbol, Dependency |
36 | 36 |
from .loadelement import LoadElement
|
37 | 37 |
from . import MetaElement
|
38 | 38 |
from . import MetaSource
|
39 |
-from ..plugin import CoreWarnings
|
|
39 |
+from ..types import CoreWarnings
|
|
40 | 40 |
from .._message import Message, MessageType
|
41 | 41 |
|
42 | 42 |
|
... | ... | @@ -33,7 +33,7 @@ from ._artifactcache import ArtifactCache |
33 | 33 |
from .sandbox import SandboxRemote
|
34 | 34 |
from ._elementfactory import ElementFactory
|
35 | 35 |
from ._sourcefactory import SourceFactory
|
36 |
-from .plugin import CoreWarnings
|
|
36 |
+from .types import CoreWarnings
|
|
37 | 37 |
from ._projectrefs import ProjectRefs, ProjectRefStorage
|
38 | 38 |
from ._versions import BST_FORMAT_VERSION
|
39 | 39 |
from ._loader import Loader
|
... | ... | @@ -96,10 +96,9 @@ from . import _cachekey |
96 | 96 |
from . import _signals
|
97 | 97 |
from . import _site
|
98 | 98 |
from ._platform import Platform
|
99 |
-from .plugin import CoreWarnings
|
|
100 | 99 |
from .sandbox._config import SandboxConfig
|
101 | 100 |
from .sandbox._sandboxremote import SandboxRemote
|
102 |
-from .types import _KeyStrength
|
|
101 |
+from .types import _KeyStrength, CoreWarnings
|
|
103 | 102 |
|
104 | 103 |
from .storage.directory import Directory
|
105 | 104 |
from .storage._filebaseddirectory import FileBasedDirectory
|
... | ... | @@ -119,6 +119,7 @@ from . import _yaml |
119 | 119 |
from . import utils
|
120 | 120 |
from ._exceptions import PluginError, ImplError
|
121 | 121 |
from ._message import Message, MessageType
|
122 |
+from .types import CoreWarnings
|
|
122 | 123 |
|
123 | 124 |
|
124 | 125 |
class Plugin():
|
... | ... | @@ -766,38 +767,6 @@ class Plugin(): |
766 | 767 |
return self.name
|
767 | 768 |
|
768 | 769 |
|
769 |
-class CoreWarnings():
|
|
770 |
- """CoreWarnings()
|
|
771 |
- |
|
772 |
- Some common warnings which are raised by core functionalities within BuildStream are found in this class.
|
|
773 |
- """
|
|
774 |
- |
|
775 |
- OVERLAPS = "overlaps"
|
|
776 |
- """
|
|
777 |
- This warning will be produced when buildstream detects an overlap on an element
|
|
778 |
- which is not whitelisted. See :ref:`Overlap Whitelist <public_overlap_whitelist>`
|
|
779 |
- """
|
|
780 |
- |
|
781 |
- REF_NOT_IN_TRACK = "ref-not-in-track"
|
|
782 |
- """
|
|
783 |
- This warning will be produced when a source is configured with a reference
|
|
784 |
- which is found to be invalid based on the configured track
|
|
785 |
- """
|
|
786 |
- |
|
787 |
- BAD_ELEMENT_SUFFIX = "bad-element-suffix"
|
|
788 |
- """
|
|
789 |
- This warning will be produced when an element whose name does not end in .bst
|
|
790 |
- is referenced either on the command line or by another element
|
|
791 |
- """
|
|
792 |
- |
|
793 |
- |
|
794 |
-__CORE_WARNINGS = [
|
|
795 |
- value
|
|
796 |
- for name, value in CoreWarnings.__dict__.items()
|
|
797 |
- if not name.startswith("__")
|
|
798 |
-]
|
|
799 |
- |
|
800 |
- |
|
801 | 770 |
# Hold on to a lookup table by counter of all instantiated plugins.
|
802 | 771 |
# We use this to send the id back from child processes so we can lookup
|
803 | 772 |
# corresponding element/source in the master process.
|
... | ... | @@ -828,6 +797,24 @@ def _plugin_lookup(unique_id): |
828 | 797 |
return __PLUGINS_TABLE[unique_id]
|
829 | 798 |
|
830 | 799 |
|
800 |
+# No need for unregister, WeakValueDictionary() will remove entries
|
|
801 |
+# in itself when the referenced plugins are garbage collected.
|
|
802 |
+def _plugin_register(plugin):
|
|
803 |
+ global __PLUGINS_UNIQUE_ID # pylint: disable=global-statement
|
|
804 |
+ __PLUGINS_UNIQUE_ID += 1
|
|
805 |
+ __PLUGINS_TABLE[__PLUGINS_UNIQUE_ID] = plugin
|
|
806 |
+ return __PLUGINS_UNIQUE_ID
|
|
807 |
+ |
|
808 |
+ |
|
809 |
+# A local table for _prefix_warning()
|
|
810 |
+#
|
|
811 |
+__CORE_WARNINGS = [
|
|
812 |
+ value
|
|
813 |
+ for name, value in CoreWarnings.__dict__.items()
|
|
814 |
+ if not name.startswith("__")
|
|
815 |
+]
|
|
816 |
+ |
|
817 |
+ |
|
831 | 818 |
# _prefix_warning():
|
832 | 819 |
#
|
833 | 820 |
# Prefix a warning with the plugin kind. CoreWarnings are not prefixed.
|
... | ... | @@ -843,12 +830,3 @@ def _prefix_warning(plugin, warning): |
843 | 830 |
if any((warning is core_warning for core_warning in __CORE_WARNINGS)):
|
844 | 831 |
return warning
|
845 | 832 |
return "{}:{}".format(plugin.get_kind(), warning)
|
846 |
- |
|
847 |
- |
|
848 |
-# No need for unregister, WeakValueDictionary() will remove entries
|
|
849 |
-# in itself when the referenced plugins are garbage collected.
|
|
850 |
-def _plugin_register(plugin):
|
|
851 |
- global __PLUGINS_UNIQUE_ID # pylint: disable=global-statement
|
|
852 |
- __PLUGINS_UNIQUE_ID += 1
|
|
853 |
- __PLUGINS_TABLE[__PLUGINS_UNIQUE_ID] = plugin
|
|
854 |
- return __PLUGINS_UNIQUE_ID
|
... | ... | @@ -131,13 +131,14 @@ details on common configuration options for sources. |
131 | 131 |
|
132 | 132 |
**Configurable Warnings:**
|
133 | 133 |
|
134 |
-This plugin provides the following configurable warnings:
|
|
134 |
+This plugin provides the following :ref:`configurable warnings <configurable_warnings>`:
|
|
135 | 135 |
|
136 |
-- 'git:inconsistent-submodule' - A submodule was found to be missing from the underlying git repository.
|
|
136 |
+- ``git:inconsistent-submodule`` - A submodule was found to be missing from the underlying git repository.
|
|
137 | 137 |
|
138 |
-This plugin also utilises the following configurable core plugin warnings:
|
|
138 |
+This plugin also utilises the following configurable :class:`core warnings <buildstream.types.CoreWarnings>`:
|
|
139 | 139 |
|
140 |
-- 'ref-not-in-track' - The provided ref was not found in the provided track in the element's git repository.
|
|
140 |
+- :attr:`ref-not-in-track <buildstream.types.CoreWarnings.REF_NOT_IN_TRACK>` - The provided ref was not
|
|
141 |
+ found in the provided track in the element's git repository.
|
|
141 | 142 |
"""
|
142 | 143 |
|
143 | 144 |
import os
|
... | ... | @@ -149,15 +150,14 @@ from tempfile import TemporaryFile |
149 | 150 |
|
150 | 151 |
from configparser import RawConfigParser
|
151 | 152 |
|
152 |
-from buildstream import Source, SourceError, Consistency, SourceFetcher
|
|
153 |
+from buildstream import Source, SourceError, Consistency, SourceFetcher, CoreWarnings
|
|
153 | 154 |
from buildstream import utils
|
154 |
-from buildstream.plugin import CoreWarnings
|
|
155 | 155 |
from buildstream.utils import move_atomic, DirectoryExistsError
|
156 | 156 |
|
157 | 157 |
GIT_MODULES = '.gitmodules'
|
158 | 158 |
|
159 | 159 |
# Warnings
|
160 |
-INCONSISTENT_SUBMODULE = "inconsistent-submodules"
|
|
160 |
+WARN_INCONSISTENT_SUBMODULE = "inconsistent-submodule"
|
|
161 | 161 |
|
162 | 162 |
|
163 | 163 |
# Because of handling of submodules, we maintain a GitMirror
|
... | ... | @@ -408,7 +408,8 @@ class GitMirror(SourceFetcher): |
408 | 408 |
"underlying git repository with `git submodule add`."
|
409 | 409 |
|
410 | 410 |
self.source.warn("{}: Ignoring inconsistent submodule '{}'"
|
411 |
- .format(self.source, submodule), detail=detail, warning_token=INCONSISTENT_SUBMODULE)
|
|
411 |
+ .format(self.source, submodule), detail=detail,
|
|
412 |
+ warning_token=WARN_INCONSISTENT_SUBMODULE)
|
|
412 | 413 |
|
413 | 414 |
return None
|
414 | 415 |
|
... | ... | @@ -391,7 +391,8 @@ class Source(Plugin): |
391 | 391 |
|
392 | 392 |
If the backend in question supports resolving references from
|
393 | 393 |
a symbolic tracking branch or tag, then this should be implemented
|
394 |
- to perform this task on behalf of ``build-stream track`` commands.
|
|
394 |
+ to perform this task on behalf of :ref:`bst track <invoking_track>`
|
|
395 |
+ commands.
|
|
395 | 396 |
|
396 | 397 |
This usually requires fetching new content from a remote origin
|
397 | 398 |
to see if a new ref has appeared for your branch or tag. If the
|
... | ... | @@ -81,6 +81,31 @@ class Consistency(): |
81 | 81 |
"""
|
82 | 82 |
|
83 | 83 |
|
84 |
+class CoreWarnings():
|
|
85 |
+ """CoreWarnings()
|
|
86 |
+ |
|
87 |
+ Some common warnings which are raised by core functionalities within BuildStream are found in this class.
|
|
88 |
+ """
|
|
89 |
+ |
|
90 |
+ OVERLAPS = "overlaps"
|
|
91 |
+ """
|
|
92 |
+ This warning will be produced when buildstream detects an overlap on an element
|
|
93 |
+ which is not whitelisted. See :ref:`Overlap Whitelist <public_overlap_whitelist>`
|
|
94 |
+ """
|
|
95 |
+ |
|
96 |
+ REF_NOT_IN_TRACK = "ref-not-in-track"
|
|
97 |
+ """
|
|
98 |
+ This warning will be produced when a source is configured with a reference
|
|
99 |
+ which is found to be invalid based on the configured track
|
|
100 |
+ """
|
|
101 |
+ |
|
102 |
+ BAD_ELEMENT_SUFFIX = "bad-element-suffix"
|
|
103 |
+ """
|
|
104 |
+ This warning will be produced when an element whose name does not end in .bst
|
|
105 |
+ is referenced either on the command line or by another element
|
|
106 |
+ """
|
|
107 |
+ |
|
108 |
+ |
|
84 | 109 |
# _KeyStrength():
|
85 | 110 |
#
|
86 | 111 |
# Strength of cache key
|
... | ... | @@ -143,7 +143,7 @@ Individual warnings can be configured as fatal by setting ``fatal-warnings`` to |
143 | 143 |
- ref-not-in-track
|
144 | 144 |
- <plugin>:<warning>
|
145 | 145 |
|
146 |
-BuildStream provides a collection of :class:`Core Warnings <buildstream.plugin.CoreWarnings>` which may be raised
|
|
146 |
+BuildStream provides a collection of :class:`Core Warnings <buildstream.types.CoreWarnings>` which may be raised
|
|
147 | 147 |
by a variety of plugins. Other configurable warnings are plugin specific and should be noted within their individual documentation.
|
148 | 148 |
|
149 | 149 |
.. note::
|
... | ... | @@ -414,45 +414,17 @@ def test_submodule_track_no_ref_or_track(cli, tmpdir, datafiles): |
414 | 414 |
|
415 | 415 |
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
|
416 | 416 |
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
|
417 |
-def test_ref_not_in_track_warn(cli, tmpdir, datafiles):
|
|
417 |
+@pytest.mark.parametrize("fail", ['warn', 'error'])
|
|
418 |
+def test_ref_not_in_track(cli, tmpdir, datafiles, fail):
|
|
418 | 419 |
project = os.path.join(datafiles.dirname, datafiles.basename)
|
419 | 420 |
|
420 |
- # Create the repo from 'repofiles', create a branch without latest commit
|
|
421 |
- repo = create_repo('git', str(tmpdir))
|
|
422 |
- ref = repo.create(os.path.join(project, 'repofiles'))
|
|
423 |
- |
|
424 |
- gitsource = repo.source_config(ref=ref)
|
|
425 |
- |
|
426 |
- # Overwrite the track value to the added branch
|
|
427 |
- gitsource['track'] = 'foo'
|
|
428 |
- |
|
429 |
- # Write out our test target
|
|
430 |
- element = {
|
|
431 |
- 'kind': 'import',
|
|
432 |
- 'sources': [
|
|
433 |
- gitsource
|
|
434 |
- ]
|
|
435 |
- }
|
|
436 |
- _yaml.dump(element, os.path.join(project, 'target.bst'))
|
|
437 |
- |
|
438 |
- # Assert the warning is raised as ref is not in branch foo.
|
|
439 |
- # Assert warning not error to the user, when not set as fatal.
|
|
440 |
- result = cli.run(project=project, args=['build', 'target.bst'])
|
|
441 |
- assert "The ref provided for the element does not exist locally" in result.stderr
|
|
442 |
- |
|
443 |
- |
|
444 |
-@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
|
|
445 |
-@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
|
|
446 |
-def test_ref_not_in_track_warn_error(cli, tmpdir, datafiles):
|
|
447 |
- project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
448 |
- |
|
449 |
- # Add fatal-warnings ref-not-in-track to project.conf
|
|
450 |
- project_template = {
|
|
451 |
- "name": "foo",
|
|
452 |
- "fatal-warnings": [CoreWarnings.REF_NOT_IN_TRACK]
|
|
453 |
- }
|
|
454 |
- |
|
455 |
- _yaml.dump(project_template, os.path.join(project, 'project.conf'))
|
|
421 |
+ # Make the warning an error if we're testing errors
|
|
422 |
+ if fail == 'error':
|
|
423 |
+ project_template = {
|
|
424 |
+ "name": "foo",
|
|
425 |
+ "fatal-warnings": [CoreWarnings.REF_NOT_IN_TRACK]
|
|
426 |
+ }
|
|
427 |
+ _yaml.dump(project_template, os.path.join(project, 'project.conf'))
|
|
456 | 428 |
|
457 | 429 |
# Create the repo from 'repofiles', create a branch without latest commit
|
458 | 430 |
repo = create_repo('git', str(tmpdir))
|
... | ... | @@ -472,11 +444,15 @@ def test_ref_not_in_track_warn_error(cli, tmpdir, datafiles): |
472 | 444 |
}
|
473 | 445 |
_yaml.dump(element, os.path.join(project, 'target.bst'))
|
474 | 446 |
|
475 |
- # Assert that build raises a warning here that is captured
|
|
476 |
- # as plugin error, due to the fatal warning being set
|
|
477 | 447 |
result = cli.run(project=project, args=['build', 'target.bst'])
|
478 |
- result.assert_main_error(ErrorDomain.STREAM, None)
|
|
479 |
- result.assert_task_error(ErrorDomain.PLUGIN, CoreWarnings.REF_NOT_IN_TRACK)
|
|
448 |
+ |
|
449 |
+ # Assert a warning or an error depending on what we're checking
|
|
450 |
+ if fail == 'error':
|
|
451 |
+ result.assert_main_error(ErrorDomain.STREAM, None)
|
|
452 |
+ result.assert_task_error(ErrorDomain.PLUGIN, CoreWarnings.REF_NOT_IN_TRACK)
|
|
453 |
+ else:
|
|
454 |
+ result.assert_success()
|
|
455 |
+ assert "ref-not-in-track" in result.stderr
|
|
480 | 456 |
|
481 | 457 |
|
482 | 458 |
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
|