Jonathan Maw pushed to branch jonathan/workspace-fragment-create 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
 - 
b1d2f001
by Tristan Van Berkom at 2018-12-06T14:18:31Z
 - 
ee7fc47f
by Tristan Van Berkom at 2018-12-06T14:18:31Z
 - 
5fc9a1da
by Tristan Van Berkom at 2018-12-06T14:18:31Z
 - 
50cb2706
by Tristan Van Berkom at 2018-12-06T14:18:31Z
 - 
f139ca8f
by Tristan Van Berkom at 2018-12-06T14:18:31Z
 - 
afe1aa9f
by Tristan Van Berkom at 2018-12-06T14:18:31Z
 - 
57300201
by Tristan Van Berkom at 2018-12-06T14:18:31Z
 - 
a0297625
by Tristan Van Berkom at 2018-12-06T14:18:31Z
 - 
60e96781
by Tristan Van Berkom at 2018-12-06T15:14:37Z
 - 
e00d6eb4
by Jonathan Maw at 2018-12-06T16:31:24Z
 - 
c582a44f
by Jonathan Maw at 2018-12-06T16:31:24Z
 - 
f4162ae4
by Jonathan Maw at 2018-12-06T16:31:24Z
 - 
3aa28cd9
by Jonathan Maw at 2018-12-06T16:31:24Z
 - 
c65db01e
by Jonathan Maw at 2018-12-06T16:31:24Z
 - 
96e7f36d
by Jonathan Maw at 2018-12-06T16:31:24Z
 - 
57d738fe
by Jonathan Maw at 2018-12-06T16:31:24Z
 - 
6fd97acd
by Jonathan Maw at 2018-12-06T16:31:24Z
 - 
6aba014d
by Jonathan Maw at 2018-12-06T16:31:24Z
 - 
2fa75309
by Jonathan Maw at 2018-12-06T16:31:24Z
 - 
9d0acbbe
by Jonathan Maw at 2018-12-06T16:31:24Z
 
21 changed files:
- NEWS
 - buildstream/__init__.py
 - buildstream/_context.py
 - buildstream/_frontend/cli.py
 - buildstream/_loader/loader.py
 - buildstream/_project.py
 - buildstream/_stream.py
 - buildstream/_versions.py
 - buildstream/_workspaces.py
 - buildstream/data/userconfig.yaml
 - buildstream/element.py
 - buildstream/plugin.py
 - buildstream/plugins/sources/git.py
 - buildstream/source.py
 - buildstream/types.py
 - buildstream/utils.py
 - doc/source/format_project.rst
 - tests/frontend/workspace.py
 - tests/integration/shell.py
 - tests/sources/git.py
 - tests/testutils/repo/git.py
 
Changes:
| ... | ... | @@ -79,6 +79,10 @@ buildstream 1.3.1 | 
| 79 | 79 | 
     plugin has now a tag tracking feature instead. This can be enabled
 | 
| 80 | 80 | 
     by setting 'track-tags'.
 | 
| 81 | 81 | 
 | 
| 82 | 
+  o Opening a workspace now creates a .bstproject.yaml file that allows buildstream
 | 
|
| 83 | 
+    commands to be run from a workspace that is not inside a project.
 | 
|
| 84 | 
+  | 
|
| 85 | 
+  | 
|
| 82 | 86 | 
 =================
 | 
| 83 | 87 | 
 buildstream 1.1.5
 | 
| 84 | 88 | 
 =================
 | 
| ... | ... | @@ -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
 | 
| ... | ... | @@ -32,7 +32,7 @@ from ._message import Message, MessageType | 
| 32 | 32 | 
 from ._profile import Topics, profile_start, profile_end
 | 
| 33 | 33 | 
 from ._artifactcache import ArtifactCache
 | 
| 34 | 34 | 
 from ._artifactcache.cascache import CASCache
 | 
| 35 | 
-from ._workspaces import Workspaces
 | 
|
| 35 | 
+from ._workspaces import Workspaces, WorkspaceProjectCache
 | 
|
| 36 | 36 | 
 from .plugin import _plugin_lookup
 | 
| 37 | 37 | 
 | 
| 38 | 38 | 
 | 
| ... | ... | @@ -122,6 +122,10 @@ class Context(): | 
| 122 | 122 | 
         # remove a workspace directory.
 | 
| 123 | 123 | 
         self.prompt_workspace_close_remove_dir = None
 | 
| 124 | 124 | 
 | 
| 125 | 
+        # Boolean, whether we double-check with the user that they meant to
 | 
|
| 126 | 
+        # close the workspace when they're using it to access the project.
 | 
|
| 127 | 
+        self.prompt_workspace_close_project_inaccessible = None
 | 
|
| 128 | 
+  | 
|
| 125 | 129 | 
         # Boolean, whether we double-check with the user that they meant to do
 | 
| 126 | 130 | 
         # a hard reset of a workspace, potentially losing changes.
 | 
| 127 | 131 | 
         self.prompt_workspace_reset_hard = None
 | 
| ... | ... | @@ -140,6 +144,7 @@ class Context(): | 
| 140 | 144 | 
         self._projects = []
 | 
| 141 | 145 | 
         self._project_overrides = {}
 | 
| 142 | 146 | 
         self._workspaces = None
 | 
| 147 | 
+        self._workspace_project_cache = WorkspaceProjectCache()
 | 
|
| 143 | 148 | 
         self._log_handle = None
 | 
| 144 | 149 | 
         self._log_filename = None
 | 
| 145 | 150 | 
         self._cascache = None
 | 
| ... | ... | @@ -250,12 +255,15 @@ class Context(): | 
| 250 | 255 | 
             defaults, Mapping, 'prompt')
 | 
| 251 | 256 | 
         _yaml.node_validate(prompt, [
 | 
| 252 | 257 | 
             'auto-init', 'really-workspace-close-remove-dir',
 | 
| 258 | 
+            'really-workspace-close-project-inaccessible',
 | 
|
| 253 | 259 | 
             'really-workspace-reset-hard',
 | 
| 254 | 260 | 
         ])
 | 
| 255 | 261 | 
         self.prompt_auto_init = _node_get_option_str(
 | 
| 256 | 262 | 
             prompt, 'auto-init', ['ask', 'no']) == 'ask'
 | 
| 257 | 263 | 
         self.prompt_workspace_close_remove_dir = _node_get_option_str(
 | 
| 258 | 264 | 
             prompt, 'really-workspace-close-remove-dir', ['ask', 'yes']) == 'ask'
 | 
| 265 | 
+        self.prompt_workspace_close_project_inaccessible = _node_get_option_str(
 | 
|
| 266 | 
+            prompt, 'really-workspace-close-project-inaccessible', ['ask', 'yes']) == 'ask'
 | 
|
| 259 | 267 | 
         self.prompt_workspace_reset_hard = _node_get_option_str(
 | 
| 260 | 268 | 
             prompt, 'really-workspace-reset-hard', ['ask', 'yes']) == 'ask'
 | 
| 261 | 269 | 
 | 
| ... | ... | @@ -285,7 +293,7 @@ class Context(): | 
| 285 | 293 | 
     #
 | 
| 286 | 294 | 
     def add_project(self, project):
 | 
| 287 | 295 | 
         if not self._projects:
 | 
| 288 | 
-            self._workspaces = Workspaces(project)
 | 
|
| 296 | 
+            self._workspaces = Workspaces(project, self._workspace_project_cache)
 | 
|
| 289 | 297 | 
         self._projects.append(project)
 | 
| 290 | 298 | 
 | 
| 291 | 299 | 
     # get_projects():
 | 
| ... | ... | @@ -312,6 +320,16 @@ class Context(): | 
| 312 | 320 | 
     def get_workspaces(self):
 | 
| 313 | 321 | 
         return self._workspaces
 | 
| 314 | 322 | 
 | 
| 323 | 
+    # get_workspace_project_cache():
 | 
|
| 324 | 
+    #
 | 
|
| 325 | 
+    # Return the WorkspaceProjectCache object used for this BuildStream invocation
 | 
|
| 326 | 
+    #
 | 
|
| 327 | 
+    # Returns:
 | 
|
| 328 | 
+    #    (WorkspaceProjectCache): The WorkspaceProjectCache object
 | 
|
| 329 | 
+    #
 | 
|
| 330 | 
+    def get_workspace_project_cache(self):
 | 
|
| 331 | 
+        return self._workspace_project_cache
 | 
|
| 332 | 
+  | 
|
| 315 | 333 | 
     # get_overrides():
 | 
| 316 | 334 | 
     #
 | 
| 317 | 335 | 
     # Fetch the override dictionary for the active project. This returns
 | 
| ... | ... | @@ -59,18 +59,9 @@ def complete_target(args, incomplete): | 
| 59 | 59 | 
     :return: all the possible user-specified completions for the param
 | 
| 60 | 60 | 
     """
 | 
| 61 | 61 | 
 | 
| 62 | 
+    from .. import utils
 | 
|
| 62 | 63 | 
     project_conf = 'project.conf'
 | 
| 63 | 64 | 
 | 
| 64 | 
-    def ensure_project_dir(directory):
 | 
|
| 65 | 
-        directory = os.path.abspath(directory)
 | 
|
| 66 | 
-        while not os.path.isfile(os.path.join(directory, project_conf)):
 | 
|
| 67 | 
-            parent_dir = os.path.dirname(directory)
 | 
|
| 68 | 
-            if directory == parent_dir:
 | 
|
| 69 | 
-                break
 | 
|
| 70 | 
-            directory = parent_dir
 | 
|
| 71 | 
-  | 
|
| 72 | 
-        return directory
 | 
|
| 73 | 
-  | 
|
| 74 | 65 | 
     # First resolve the directory, in case there is an
 | 
| 75 | 66 | 
     # active --directory/-C option
 | 
| 76 | 67 | 
     #
 | 
| ... | ... | @@ -89,7 +80,7 @@ def complete_target(args, incomplete): | 
| 89 | 80 | 
     else:
 | 
| 90 | 81 | 
         # Check if this directory or any of its parent directories
 | 
| 91 | 82 | 
         # contain a project config file
 | 
| 92 | 
-        base_directory = ensure_project_dir(base_directory)
 | 
|
| 83 | 
+        base_directory = utils._search_upward_for_file(base_directory, project_conf)
 | 
|
| 93 | 84 | 
 | 
| 94 | 85 | 
     # Now parse the project.conf just to find the element path,
 | 
| 95 | 86 | 
     # this is unfortunately a bit heavy.
 | 
| ... | ... | @@ -772,11 +763,18 @@ def workspace_close(app, remove_dir, all_, elements): | 
| 772 | 763 | 
 | 
| 773 | 764 | 
         elements = app.stream.redirect_element_names(elements)
 | 
| 774 | 765 | 
 | 
| 775 | 
-        # Check that the workspaces in question exist
 | 
|
| 766 | 
+        # Check that the workspaces in question exist, and that it's safe to
 | 
|
| 767 | 
+        # remove them.
 | 
|
| 776 | 768 | 
         nonexisting = []
 | 
| 777 | 769 | 
         for element_name in elements:
 | 
| 778 | 770 | 
             if not app.stream.workspace_exists(element_name):
 | 
| 779 | 771 | 
                 nonexisting.append(element_name)
 | 
| 772 | 
+            if (app.stream.workspace_is_required(element_name) and app.interactive and
 | 
|
| 773 | 
+                    app.context.prompt_workspace_close_project_inaccessible):
 | 
|
| 774 | 
+                click.echo("Removing '{}' will prevent you from running buildstream commands".format(element_name))
 | 
|
| 775 | 
+                if not click.confirm('Are you sure you want to close this workspace?'):
 | 
|
| 776 | 
+                    click.echo('Aborting', err=True)
 | 
|
| 777 | 
+                    sys.exit(-1)
 | 
|
| 780 | 778 | 
         if nonexisting:
 | 
| 781 | 779 | 
             raise AppError("Workspace does not exist", detail="\n".join(nonexisting))
 | 
| 782 | 780 | 
 | 
| ... | ... | @@ -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
 | 
| ... | ... | @@ -95,8 +95,10 @@ class Project(): | 
| 95 | 95 | 
         # The project name
 | 
| 96 | 96 | 
         self.name = None
 | 
| 97 | 97 | 
 | 
| 98 | 
-        # The project directory
 | 
|
| 99 | 
-        self.directory = self._ensure_project_dir(directory)
 | 
|
| 98 | 
+        self._context = context  # The invocation Context, a private member
 | 
|
| 99 | 
+  | 
|
| 100 | 
+        # The project directory, and whether the project was found from an external workspace
 | 
|
| 101 | 
+        self.directory, self._required_workspace_element = self._find_project_dir(directory)
 | 
|
| 100 | 102 | 
 | 
| 101 | 103 | 
         # Absolute path to where elements are loaded from within the project
 | 
| 102 | 104 | 
         self.element_path = None
 | 
| ... | ... | @@ -117,7 +119,6 @@ class Project(): | 
| 117 | 119 | 
         #
 | 
| 118 | 120 | 
         # Private Members
 | 
| 119 | 121 | 
         #
 | 
| 120 | 
-        self._context = context  # The invocation Context
 | 
|
| 121 | 122 | 
 | 
| 122 | 123 | 
         self._default_mirror = default_mirror    # The name of the preferred mirror.
 | 
| 123 | 124 | 
 | 
| ... | ... | @@ -371,6 +372,14 @@ class Project(): | 
| 371 | 372 | 
 | 
| 372 | 373 | 
         self._load_second_pass()
 | 
| 373 | 374 | 
 | 
| 375 | 
+    # required_workspace_element()
 | 
|
| 376 | 
+    #
 | 
|
| 377 | 
+    # Returns the element whose workspace is required to load this project,
 | 
|
| 378 | 
+    # if any.
 | 
|
| 379 | 
+    #
 | 
|
| 380 | 
+    def required_workspace_element(self):
 | 
|
| 381 | 
+        return self._required_workspace_element
 | 
|
| 382 | 
+  | 
|
| 374 | 383 | 
     # cleanup()
 | 
| 375 | 384 | 
     #
 | 
| 376 | 385 | 
     # Cleans up resources used loading elements
 | 
| ... | ... | @@ -650,7 +659,7 @@ class Project(): | 
| 650 | 659 | 
         # Source url aliases
 | 
| 651 | 660 | 
         output._aliases = _yaml.node_get(config, Mapping, 'aliases', default_value={})
 | 
| 652 | 661 | 
 | 
| 653 | 
-    # _ensure_project_dir()
 | 
|
| 662 | 
+    # _find_project_dir()
 | 
|
| 654 | 663 | 
     #
 | 
| 655 | 664 | 
     # Returns path of the project directory, if a configuration file is found
 | 
| 656 | 665 | 
     # in given directory or any of its parent directories.
 | 
| ... | ... | @@ -661,18 +670,26 @@ class Project(): | 
| 661 | 670 | 
     # Raises:
 | 
| 662 | 671 | 
     #    LoadError if project.conf is not found
 | 
| 663 | 672 | 
     #
 | 
| 664 | 
-    def _ensure_project_dir(self, directory):
 | 
|
| 665 | 
-        directory = os.path.abspath(directory)
 | 
|
| 666 | 
-        while not os.path.isfile(os.path.join(directory, _PROJECT_CONF_FILE)):
 | 
|
| 667 | 
-            parent_dir = os.path.dirname(directory)
 | 
|
| 668 | 
-            if directory == parent_dir:
 | 
|
| 673 | 
+    # Returns:
 | 
|
| 674 | 
+    #    (str) - the directory that contains the project, and
 | 
|
| 675 | 
+    #    (str) - the name of the element required to find the project, or an empty string
 | 
|
| 676 | 
+    #
 | 
|
| 677 | 
+    def _find_project_dir(self, directory):
 | 
|
| 678 | 
+        workspace_element = ""
 | 
|
| 679 | 
+        project_directory = utils._search_upward_for_file(directory, _PROJECT_CONF_FILE)
 | 
|
| 680 | 
+        if not project_directory:
 | 
|
| 681 | 
+            workspace_project_cache = self._context.get_workspace_project_cache()
 | 
|
| 682 | 
+            workspace_project = workspace_project_cache.get(directory)
 | 
|
| 683 | 
+            if workspace_project:
 | 
|
| 684 | 
+                project_directory = workspace_project.get_default_project_path()
 | 
|
| 685 | 
+                workspace_element = workspace_project.get_default_element()
 | 
|
| 686 | 
+            else:
 | 
|
| 669 | 687 | 
                 raise LoadError(
 | 
| 670 | 688 | 
                     LoadErrorReason.MISSING_PROJECT_CONF,
 | 
| 671 | 689 | 
                     '{} not found in current directory or any of its parent directories'
 | 
| 672 | 690 | 
                     .format(_PROJECT_CONF_FILE))
 | 
| 673 | 
-            directory = parent_dir
 | 
|
| 674 | 691 | 
 | 
| 675 | 
-        return directory
 | 
|
| 692 | 
+        return project_directory, workspace_element
 | 
|
| 676 | 693 | 
 | 
| 677 | 694 | 
     def _load_plugin_factories(self, config, output):
 | 
| 678 | 695 | 
         plugin_source_origins = []   # Origins of custom sources
 | 
| ... | ... | @@ -581,15 +581,7 @@ class Stream(): | 
| 581 | 581 | 
                     todo_elements = "\nDid not try to create workspaces for " + todo_elements
 | 
| 582 | 582 | 
                 raise StreamError("Failed to create workspace directory: {}".format(e) + todo_elements) from e
 | 
| 583 | 583 | 
 | 
| 584 | 
-            workspaces.create_workspace(target._get_full_name(), directory)
 | 
|
| 585 | 
-  | 
|
| 586 | 
-            if not no_checkout:
 | 
|
| 587 | 
-                with target.timed_activity("Staging sources to {}".format(directory)):
 | 
|
| 588 | 
-                    target._open_workspace()
 | 
|
| 589 | 
-  | 
|
| 590 | 
-            # Saving the workspace once it is set up means that if the next workspace fails to be created before
 | 
|
| 591 | 
-            # the configuration gets saved. The successfully created workspace still gets saved.
 | 
|
| 592 | 
-            workspaces.save_config()
 | 
|
| 584 | 
+            workspaces.create_workspace(target, directory, not no_checkout)
 | 
|
| 593 | 585 | 
             self._message(MessageType.INFO, "Created a workspace for element: {}"
 | 
| 594 | 586 | 
                           .format(target._get_full_name()))
 | 
| 595 | 587 | 
 | 
| ... | ... | @@ -672,10 +664,7 @@ class Stream(): | 
| 672 | 664 | 
                                       .format(workspace_path, e)) from e
 | 
| 673 | 665 | 
 | 
| 674 | 666 | 
             workspaces.delete_workspace(element._get_full_name())
 | 
| 675 | 
-            workspaces.create_workspace(element._get_full_name(), workspace_path)
 | 
|
| 676 | 
-  | 
|
| 677 | 
-            with element.timed_activity("Staging sources to {}".format(workspace_path)):
 | 
|
| 678 | 
-                element._open_workspace()
 | 
|
| 667 | 
+            workspaces.create_workspace(element, workspace_path, True)
 | 
|
| 679 | 668 | 
 | 
| 680 | 669 | 
             self._message(MessageType.INFO,
 | 
| 681 | 670 | 
                           "Reset workspace for {} at: {}".format(element.name,
 | 
| ... | ... | @@ -707,6 +696,20 @@ class Stream(): | 
| 707 | 696 | 
 | 
| 708 | 697 | 
         return False
 | 
| 709 | 698 | 
 | 
| 699 | 
+    # workspace_is_required()
 | 
|
| 700 | 
+    #
 | 
|
| 701 | 
+    # Checks whether the workspace belonging to element_name is required to
 | 
|
| 702 | 
+    # load the project
 | 
|
| 703 | 
+    #
 | 
|
| 704 | 
+    # Args:
 | 
|
| 705 | 
+    #    element_name (str): The element whose workspace may be required
 | 
|
| 706 | 
+    #
 | 
|
| 707 | 
+    # Returns:
 | 
|
| 708 | 
+    #    (bool): True if the workspace is required
 | 
|
| 709 | 
+    def workspace_is_required(self, element_name):
 | 
|
| 710 | 
+        required_elm = self._project.required_workspace_element()
 | 
|
| 711 | 
+        return required_elm == element_name
 | 
|
| 712 | 
+  | 
|
| 710 | 713 | 
     # workspace_list
 | 
| 711 | 714 | 
     #
 | 
| 712 | 715 | 
     # Serializes the workspaces and dumps them in YAML to stdout.
 | 
| ... | ... | @@ -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 = 19
 | 
|
| 26 | 
+BST_FORMAT_VERSION = 20
 | 
|
| 27 | 27 | 
 | 
| 28 | 28 | 
 | 
| 29 | 29 | 
 # The base BuildStream artifact version
 | 
| ... | ... | @@ -25,6 +25,219 @@ from ._exceptions import LoadError, LoadErrorReason | 
| 25 | 25 | 
 | 
| 26 | 26 | 
 | 
| 27 | 27 | 
 BST_WORKSPACE_FORMAT_VERSION = 3
 | 
| 28 | 
+BST_WORKSPACE_PROJECT_FORMAT_VERSION = 1
 | 
|
| 29 | 
+WORKSPACE_PROJECT_FILE = ".bstproject.yaml"
 | 
|
| 30 | 
+  | 
|
| 31 | 
+  | 
|
| 32 | 
+# WorkspaceProject()
 | 
|
| 33 | 
+#
 | 
|
| 34 | 
+# An object to contain various helper functions and data required for
 | 
|
| 35 | 
+# referring from a workspace back to buildstream.
 | 
|
| 36 | 
+#
 | 
|
| 37 | 
+# Args:
 | 
|
| 38 | 
+#    directory (str): The directory that the workspace exists in.
 | 
|
| 39 | 
+#
 | 
|
| 40 | 
+class WorkspaceProject():
 | 
|
| 41 | 
+    def __init__(self, directory):
 | 
|
| 42 | 
+        self._projects = []
 | 
|
| 43 | 
+        self._directory = directory
 | 
|
| 44 | 
+  | 
|
| 45 | 
+    # get_default_project_path()
 | 
|
| 46 | 
+    #
 | 
|
| 47 | 
+    # Retrieves the default path to a project.
 | 
|
| 48 | 
+    #
 | 
|
| 49 | 
+    # Returns:
 | 
|
| 50 | 
+    #    (str): The path to a project
 | 
|
| 51 | 
+    #
 | 
|
| 52 | 
+    def get_default_project_path(self):
 | 
|
| 53 | 
+        return self._projects[0]['project-path']
 | 
|
| 54 | 
+  | 
|
| 55 | 
+    # get_default_element()
 | 
|
| 56 | 
+    #
 | 
|
| 57 | 
+    # Retrieves the name of the element that owns this workspace.
 | 
|
| 58 | 
+    #
 | 
|
| 59 | 
+    # Returns:
 | 
|
| 60 | 
+    #    (str): The name of an element
 | 
|
| 61 | 
+    #
 | 
|
| 62 | 
+    def get_default_element(self):
 | 
|
| 63 | 
+        return self._projects[0]['element-name']
 | 
|
| 64 | 
+  | 
|
| 65 | 
+    # to_dict()
 | 
|
| 66 | 
+    #
 | 
|
| 67 | 
+    # Turn the members data into a dict for serialization purposes
 | 
|
| 68 | 
+    #
 | 
|
| 69 | 
+    # Returns:
 | 
|
| 70 | 
+    #    (dict): A dict representation of the WorkspaceProject
 | 
|
| 71 | 
+    #
 | 
|
| 72 | 
+    def to_dict(self):
 | 
|
| 73 | 
+        ret = {
 | 
|
| 74 | 
+            'projects': self._projects,
 | 
|
| 75 | 
+            'format-version': BST_WORKSPACE_PROJECT_FORMAT_VERSION,
 | 
|
| 76 | 
+        }
 | 
|
| 77 | 
+        return ret
 | 
|
| 78 | 
+  | 
|
| 79 | 
+    # from_dict()
 | 
|
| 80 | 
+    #
 | 
|
| 81 | 
+    # Loads a new WorkspaceProject from a simple dictionary
 | 
|
| 82 | 
+    #
 | 
|
| 83 | 
+    # Args:
 | 
|
| 84 | 
+    #    directory (str): The directory that the workspace exists in
 | 
|
| 85 | 
+    #    dictionary (dict): The dict to generate a WorkspaceProject from
 | 
|
| 86 | 
+    #
 | 
|
| 87 | 
+    # Returns:
 | 
|
| 88 | 
+    #   (WorkspaceProject): A newly instantiated WorkspaceProject
 | 
|
| 89 | 
+    #
 | 
|
| 90 | 
+    @classmethod
 | 
|
| 91 | 
+    def from_dict(cls, directory, dictionary):
 | 
|
| 92 | 
+        # Only know how to handle one format-version at the moment.
 | 
|
| 93 | 
+        format_version = int(dictionary['format-version'])
 | 
|
| 94 | 
+        assert format_version == BST_WORKSPACE_PROJECT_FORMAT_VERSION, \
 | 
|
| 95 | 
+            "Format version {} not found in {}".format(BST_WORKSPACE_PROJECT_FORMAT_VERSION, dictionary)
 | 
|
| 96 | 
+  | 
|
| 97 | 
+        workspace_project = cls(directory)
 | 
|
| 98 | 
+        for item in dictionary['projects']:
 | 
|
| 99 | 
+            workspace_project.add_project(item['project-path'], item['element-name'])
 | 
|
| 100 | 
+  | 
|
| 101 | 
+        return workspace_project
 | 
|
| 102 | 
+  | 
|
| 103 | 
+    # load()
 | 
|
| 104 | 
+    #
 | 
|
| 105 | 
+    # Loads the WorkspaceProject for a given directory. This directory may be a
 | 
|
| 106 | 
+    # subdirectory of the workspace's directory.
 | 
|
| 107 | 
+    #
 | 
|
| 108 | 
+    # Args:
 | 
|
| 109 | 
+    #    directory (str): The directory
 | 
|
| 110 | 
+    # Returns:
 | 
|
| 111 | 
+    #    (WorkspaceProject): The created WorkspaceProject, if in a workspace, or
 | 
|
| 112 | 
+    #    (NoneType): None, if the directory is not inside a workspace.
 | 
|
| 113 | 
+    #
 | 
|
| 114 | 
+    @classmethod
 | 
|
| 115 | 
+    def load(cls, directory):
 | 
|
| 116 | 
+        project_dir = cls.search_for_dir(directory)
 | 
|
| 117 | 
+        if project_dir:
 | 
|
| 118 | 
+            workspace_file = os.path.join(project_dir, WORKSPACE_PROJECT_FILE)
 | 
|
| 119 | 
+            data_dict = _yaml.load(workspace_file)
 | 
|
| 120 | 
+            return cls.from_dict(project_dir, data_dict)
 | 
|
| 121 | 
+        else:
 | 
|
| 122 | 
+            return None
 | 
|
| 123 | 
+  | 
|
| 124 | 
+    # write()
 | 
|
| 125 | 
+    #
 | 
|
| 126 | 
+    # Writes the WorkspaceProject to disk
 | 
|
| 127 | 
+    #
 | 
|
| 128 | 
+    def write(self):
 | 
|
| 129 | 
+        os.makedirs(self._directory, exist_ok=True)
 | 
|
| 130 | 
+        _yaml.dump(self.to_dict(), self.get_filename())
 | 
|
| 131 | 
+  | 
|
| 132 | 
+    # search_for_dir()
 | 
|
| 133 | 
+    #
 | 
|
| 134 | 
+    # Returns the directory that contains the workspace local project file,
 | 
|
| 135 | 
+    # searching upwards from search_dir.
 | 
|
| 136 | 
+    #
 | 
|
| 137 | 
+    @staticmethod
 | 
|
| 138 | 
+    def search_for_dir(search_dir):
 | 
|
| 139 | 
+        return utils._search_upward_for_file(search_dir, WORKSPACE_PROJECT_FILE)
 | 
|
| 140 | 
+  | 
|
| 141 | 
+    # get_filename()
 | 
|
| 142 | 
+    #
 | 
|
| 143 | 
+    # Returns the full path to the workspace local project file
 | 
|
| 144 | 
+    #
 | 
|
| 145 | 
+    def get_filename(self):
 | 
|
| 146 | 
+        return os.path.join(self._directory, WORKSPACE_PROJECT_FILE)
 | 
|
| 147 | 
+  | 
|
| 148 | 
+    # add_project()
 | 
|
| 149 | 
+    #
 | 
|
| 150 | 
+    # Adds an entry containing the project's path and element's name.
 | 
|
| 151 | 
+    #
 | 
|
| 152 | 
+    # Args:
 | 
|
| 153 | 
+    #    project_path (str): The path to the project that opened the workspace.
 | 
|
| 154 | 
+    #    element_name (str): The name of the element that the workspace belongs to.
 | 
|
| 155 | 
+    #
 | 
|
| 156 | 
+    def add_project(self, project_path, element_name):
 | 
|
| 157 | 
+        assert (project_path and element_name)
 | 
|
| 158 | 
+        self._projects.append({'project-path': project_path, 'element-name': element_name})
 | 
|
| 159 | 
+  | 
|
| 160 | 
+  | 
|
| 161 | 
+# WorkspaceProjectCache()
 | 
|
| 162 | 
+#
 | 
|
| 163 | 
+# A class to manage workspace project data for multiple workspaces.
 | 
|
| 164 | 
+#
 | 
|
| 165 | 
+class WorkspaceProjectCache():
 | 
|
| 166 | 
+    def __init__(self):
 | 
|
| 167 | 
+        self._projects = {}  # Mapping of a workspace directory to its WorkspaceProject
 | 
|
| 168 | 
+  | 
|
| 169 | 
+    # get()
 | 
|
| 170 | 
+    #
 | 
|
| 171 | 
+    # Returns a WorkspaceProject for a given directory, retrieving from the cache if
 | 
|
| 172 | 
+    # present, and searching the filesystem for the file and loading it if not.
 | 
|
| 173 | 
+    #
 | 
|
| 174 | 
+    # Args:
 | 
|
| 175 | 
+    #    directory (str): The directory to search for a WorkspaceProject.
 | 
|
| 176 | 
+    #
 | 
|
| 177 | 
+    # Returns:
 | 
|
| 178 | 
+    #    (WorkspaceProject): The WorkspaceProject that was found for that directory.
 | 
|
| 179 | 
+    #    or      (NoneType): None, if no WorkspaceProject can be found.
 | 
|
| 180 | 
+    #
 | 
|
| 181 | 
+    def get(self, directory):
 | 
|
| 182 | 
+        try:
 | 
|
| 183 | 
+            workspace_project = self._projects[directory]
 | 
|
| 184 | 
+        except KeyError:
 | 
|
| 185 | 
+            found_dir = WorkspaceProject.search_for_dir(directory)
 | 
|
| 186 | 
+            if found_dir:
 | 
|
| 187 | 
+                try:
 | 
|
| 188 | 
+                    workspace_project = self._projects[found_dir]
 | 
|
| 189 | 
+                except KeyError:
 | 
|
| 190 | 
+                    workspace_project = WorkspaceProject.load(found_dir)
 | 
|
| 191 | 
+                    self._projects[found_dir] = workspace_project
 | 
|
| 192 | 
+            else:
 | 
|
| 193 | 
+                workspace_project = None
 | 
|
| 194 | 
+  | 
|
| 195 | 
+        return workspace_project
 | 
|
| 196 | 
+  | 
|
| 197 | 
+    # add()
 | 
|
| 198 | 
+    #
 | 
|
| 199 | 
+    # Adds the project path and element name to the WorkspaceProject that exists
 | 
|
| 200 | 
+    # for that directory
 | 
|
| 201 | 
+    #
 | 
|
| 202 | 
+    # Args:
 | 
|
| 203 | 
+    #    directory (str): The directory to search for a WorkspaceProject.
 | 
|
| 204 | 
+    #    project_path (str): The path to the project that refers to this workspace
 | 
|
| 205 | 
+    #    element_name (str): The element in the project that was refers to this workspace
 | 
|
| 206 | 
+    #
 | 
|
| 207 | 
+    # Returns:
 | 
|
| 208 | 
+    #    (WorkspaceProject): The WorkspaceProject that was found for that directory.
 | 
|
| 209 | 
+    #
 | 
|
| 210 | 
+    def add(self, directory, project_path, element_name):
 | 
|
| 211 | 
+        workspace_project = self.get(directory)
 | 
|
| 212 | 
+        if not workspace_project:
 | 
|
| 213 | 
+            workspace_project = WorkspaceProject(directory)
 | 
|
| 214 | 
+            self._projects[directory] = workspace_project
 | 
|
| 215 | 
+  | 
|
| 216 | 
+        workspace_project.add_project(project_path, element_name)
 | 
|
| 217 | 
+        return workspace_project
 | 
|
| 218 | 
+  | 
|
| 219 | 
+    # remove()
 | 
|
| 220 | 
+    #
 | 
|
| 221 | 
+    # Removes the project path and element name from the WorkspaceProject that exists
 | 
|
| 222 | 
+    # for that directory.
 | 
|
| 223 | 
+    #
 | 
|
| 224 | 
+    # NOTE: This currently just deletes the file, but with support for multiple
 | 
|
| 225 | 
+    # projects opening the same workspace, this will involve decreasing the count
 | 
|
| 226 | 
+    # and deleting the file if there are no more projects.
 | 
|
| 227 | 
+    #
 | 
|
| 228 | 
+    # Args:
 | 
|
| 229 | 
+    #    directory (str): The directory to search for a WorkspaceProject.
 | 
|
| 230 | 
+    #
 | 
|
| 231 | 
+    def remove(self, directory):
 | 
|
| 232 | 
+        workspace_project = self.get(directory)
 | 
|
| 233 | 
+        if not workspace_project:
 | 
|
| 234 | 
+            raise LoadError(LoadErrorReason.MISSING_FILE,
 | 
|
| 235 | 
+                            "Failed to find a {} file to remove".format(WORKSPACE_PROJECT_FILE))
 | 
|
| 236 | 
+        path = workspace_project.get_filename()
 | 
|
| 237 | 
+        try:
 | 
|
| 238 | 
+            os.unlink(path)
 | 
|
| 239 | 
+        except FileNotFoundError:
 | 
|
| 240 | 
+            pass
 | 
|
| 28 | 241 | 
 | 
| 29 | 242 | 
 | 
| 30 | 243 | 
 # Workspace()
 | 
| ... | ... | @@ -174,10 +387,15 @@ class Workspace(): | 
| 174 | 387 | 
         if recalculate or self._key is None:
 | 
| 175 | 388 | 
             fullpath = self.get_absolute_path()
 | 
| 176 | 389 | 
 | 
| 390 | 
+            excluded_files = (WORKSPACE_PROJECT_FILE,)
 | 
|
| 391 | 
+  | 
|
| 177 | 392 | 
             # Get a list of tuples of the the project relative paths and fullpaths
 | 
| 178 | 393 | 
             if os.path.isdir(fullpath):
 | 
| 179 | 394 | 
                 filelist = utils.list_relative_paths(fullpath)
 | 
| 180 | 
-                filelist = [(relpath, os.path.join(fullpath, relpath)) for relpath in filelist]
 | 
|
| 395 | 
+                filelist = [
 | 
|
| 396 | 
+                    (relpath, os.path.join(fullpath, relpath)) for relpath in filelist
 | 
|
| 397 | 
+                    if relpath not in excluded_files
 | 
|
| 398 | 
+                ]
 | 
|
| 181 | 399 | 
             else:
 | 
| 182 | 400 | 
                 filelist = [(self.get_absolute_path(), fullpath)]
 | 
| 183 | 401 | 
 | 
| ... | ... | @@ -199,12 +417,14 @@ class Workspace(): | 
| 199 | 417 | 
 #
 | 
| 200 | 418 | 
 # Args:
 | 
| 201 | 419 | 
 #    toplevel_project (Project): Top project used to resolve paths.
 | 
| 420 | 
+#    workspace_project_cache (WorkspaceProjectCache): The cache of WorkspaceProjects
 | 
|
| 202 | 421 | 
 #
 | 
| 203 | 422 | 
 class Workspaces():
 | 
| 204 | 
-    def __init__(self, toplevel_project):
 | 
|
| 423 | 
+    def __init__(self, toplevel_project, workspace_project_cache):
 | 
|
| 205 | 424 | 
         self._toplevel_project = toplevel_project
 | 
| 206 | 425 | 
         self._bst_directory = os.path.join(toplevel_project.directory, ".bst")
 | 
| 207 | 426 | 
         self._workspaces = self._load_config()
 | 
| 427 | 
+        self._workspace_project_cache = workspace_project_cache
 | 
|
| 208 | 428 | 
 | 
| 209 | 429 | 
     # list()
 | 
| 210 | 430 | 
     #
 | 
| ... | ... | @@ -219,19 +439,36 @@ class Workspaces(): | 
| 219 | 439 | 
 | 
| 220 | 440 | 
     # create_workspace()
 | 
| 221 | 441 | 
     #
 | 
| 222 | 
-    # Create a workspace in the given path for the given element.
 | 
|
| 442 | 
+    # Create a workspace in the given path for the given element, and potentially
 | 
|
| 443 | 
+    # checks-out the target into it.
 | 
|
| 223 | 444 | 
     #
 | 
| 224 | 445 | 
     # Args:
 | 
| 225 | 
-    #    element_name (str) - The element name to create a workspace for
 | 
|
| 446 | 
+    #    target (Element) - The element to create a workspace for
 | 
|
| 226 | 447 | 
     #    path (str) - The path in which the workspace should be kept
 | 
| 448 | 
+    #    checkout (bool): Whether to check-out the element's sources into the directory
 | 
|
| 227 | 449 | 
     #
 | 
| 228 | 
-    def create_workspace(self, element_name, path):
 | 
|
| 229 | 
-        if path.startswith(self._toplevel_project.directory):
 | 
|
| 230 | 
-            path = os.path.relpath(path, self._toplevel_project.directory)
 | 
|
| 450 | 
+    def create_workspace(self, target, path, checkout):
 | 
|
| 451 | 
+        element_name = target._get_full_name()
 | 
|
| 452 | 
+        project_dir = self._toplevel_project.directory
 | 
|
| 453 | 
+        if path.startswith(project_dir):
 | 
|
| 454 | 
+            workspace_path = os.path.relpath(path, project_dir)
 | 
|
| 455 | 
+        else:
 | 
|
| 456 | 
+            workspace_path = path
 | 
|
| 231 | 457 | 
 | 
| 232 | 
-        self._workspaces[element_name] = Workspace(self._toplevel_project, path=path)
 | 
|
| 458 | 
+        self._workspaces[element_name] = Workspace(self._toplevel_project, path=workspace_path)
 | 
|
| 233 | 459 | 
 | 
| 234 | 
-        return self._workspaces[element_name]
 | 
|
| 460 | 
+        if checkout:
 | 
|
| 461 | 
+            with target.timed_activity("Staging sources to {}".format(path)):
 | 
|
| 462 | 
+                target._open_workspace()
 | 
|
| 463 | 
+  | 
|
| 464 | 
+        workspace_project = self._workspace_project_cache.add(path, project_dir, element_name)
 | 
|
| 465 | 
+        project_file_path = workspace_project.get_filename()
 | 
|
| 466 | 
+  | 
|
| 467 | 
+        if os.path.exists(project_file_path):
 | 
|
| 468 | 
+            target.warn("{} was staged from this element's sources".format(WORKSPACE_PROJECT_FILE))
 | 
|
| 469 | 
+        workspace_project.write()
 | 
|
| 470 | 
+  | 
|
| 471 | 
+        self.save_config()
 | 
|
| 235 | 472 | 
 | 
| 236 | 473 | 
     # get_workspace()
 | 
| 237 | 474 | 
     #
 | 
| ... | ... | @@ -280,8 +517,19 @@ class Workspaces(): | 
| 280 | 517 | 
     #    element_name (str) - The element name whose workspace to delete
 | 
| 281 | 518 | 
     #
 | 
| 282 | 519 | 
     def delete_workspace(self, element_name):
 | 
| 520 | 
+        workspace = self.get_workspace(element_name)
 | 
|
| 283 | 521 | 
         del self._workspaces[element_name]
 | 
| 284 | 522 | 
 | 
| 523 | 
+        # Remove from the cache if it exists
 | 
|
| 524 | 
+        try:
 | 
|
| 525 | 
+            self._workspace_project_cache.remove(workspace.get_absolute_path())
 | 
|
| 526 | 
+        except LoadError as e:
 | 
|
| 527 | 
+            # We might be closing a workspace with a deleted directory
 | 
|
| 528 | 
+            if e.reason == LoadErrorReason.MISSING_FILE:
 | 
|
| 529 | 
+                pass
 | 
|
| 530 | 
+            else:
 | 
|
| 531 | 
+                raise
 | 
|
| 532 | 
+  | 
|
| 285 | 533 | 
     # save_config()
 | 
| 286 | 534 | 
     #
 | 
| 287 | 535 | 
     # Dump the current workspace element to the project configuration
 | 
| ... | ... | @@ -128,6 +128,14 @@ prompt: | 
| 128 | 128 | 
   #
 | 
| 129 | 129 | 
   really-workspace-close-remove-dir: ask
 | 
| 130 | 130 | 
 | 
| 131 | 
+  # Whether to really proceed with 'bst workspace close' when doing so would
 | 
|
| 132 | 
+  # stop them from running bst commands in this workspace.
 | 
|
| 133 | 
+  #
 | 
|
| 134 | 
+  #  ask - Ask the user if they are sure.
 | 
|
| 135 | 
+  #  yes - Always close, without asking.
 | 
|
| 136 | 
+  #
 | 
|
| 137 | 
+  really-workspace-close-project-inaccessible: ask
 | 
|
| 138 | 
+  | 
|
| 131 | 139 | 
   # Whether to really proceed with 'bst workspace reset' doing a hard reset of
 | 
| 132 | 140 | 
   # a workspace, potentially losing changes.
 | 
| 133 | 141 | 
   #
 | 
| ... | ... | @@ -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,29 @@ 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 present in the git repository's .gitmodules was never
 | 
|
| 137 | 
+  added with `git submodule add`.
 | 
|
| 137 | 138 | 
 | 
| 138 | 
-This plugin also utilises the following configurable core plugin warnings:
 | 
|
| 139 | 
+- ``git:unlisted-submodule`` - A submodule is present in the git repository but was not specified in
 | 
|
| 140 | 
+  the source configuration and was not disabled for checkout.
 | 
|
| 139 | 141 | 
 | 
| 140 | 
-- 'ref-not-in-track' - The provided ref was not found in the provided track in the element's git repository.
 | 
|
| 142 | 
+  .. note::
 | 
|
| 143 | 
+  | 
|
| 144 | 
+     The ``git:unlisted-submodule`` warning is available since :ref:`format version 20 <project_format_version>`
 | 
|
| 145 | 
+  | 
|
| 146 | 
+- ``git:invalid-submodule`` - A submodule is specified in the source configuration but does not exist
 | 
|
| 147 | 
+  in the repository.
 | 
|
| 148 | 
+  | 
|
| 149 | 
+  .. note::
 | 
|
| 150 | 
+  | 
|
| 151 | 
+     The ``git:invalid-submodule`` warning is available since :ref:`format version 20 <project_format_version>`
 | 
|
| 152 | 
+  | 
|
| 153 | 
+This plugin also utilises the following configurable :class:`core warnings <buildstream.types.CoreWarnings>`:
 | 
|
| 154 | 
+  | 
|
| 155 | 
+- :attr:`ref-not-in-track <buildstream.types.CoreWarnings.REF_NOT_IN_TRACK>` - The provided ref was not
 | 
|
| 156 | 
+  found in the provided track in the element's git repository.
 | 
|
| 141 | 157 | 
 """
 | 
| 142 | 158 | 
 | 
| 143 | 159 | 
 import os
 | 
| ... | ... | @@ -149,15 +165,16 @@ from tempfile import TemporaryFile | 
| 149 | 165 | 
 | 
| 150 | 166 | 
 from configparser import RawConfigParser
 | 
| 151 | 167 | 
 | 
| 152 | 
-from buildstream import Source, SourceError, Consistency, SourceFetcher
 | 
|
| 168 | 
+from buildstream import Source, SourceError, Consistency, SourceFetcher, CoreWarnings
 | 
|
| 153 | 169 | 
 from buildstream import utils
 | 
| 154 | 
-from buildstream.plugin import CoreWarnings
 | 
|
| 155 | 170 | 
 from buildstream.utils import move_atomic, DirectoryExistsError
 | 
| 156 | 171 | 
 | 
| 157 | 172 | 
 GIT_MODULES = '.gitmodules'
 | 
| 158 | 173 | 
 | 
| 159 | 174 | 
 # Warnings
 | 
| 160 | 
-INCONSISTENT_SUBMODULE = "inconsistent-submodules"
 | 
|
| 175 | 
+WARN_INCONSISTENT_SUBMODULE = "inconsistent-submodule"
 | 
|
| 176 | 
+WARN_UNLISTED_SUBMODULE = "unlisted-submodule"
 | 
|
| 177 | 
+WARN_INVALID_SUBMODULE = "invalid-submodule"
 | 
|
| 161 | 178 | 
 | 
| 162 | 179 | 
 | 
| 163 | 180 | 
 # Because of handling of submodules, we maintain a GitMirror
 | 
| ... | ... | @@ -305,7 +322,7 @@ class GitMirror(SourceFetcher): | 
| 305 | 322 | 
 | 
| 306 | 323 | 
         return ref, list(tags)
 | 
| 307 | 324 | 
 | 
| 308 | 
-    def stage(self, directory, track=None):
 | 
|
| 325 | 
+    def stage(self, directory):
 | 
|
| 309 | 326 | 
         fullpath = os.path.join(directory, self.path)
 | 
| 310 | 327 | 
 | 
| 311 | 328 | 
         # Using --shared here avoids copying the objects into the checkout, in any
 | 
| ... | ... | @@ -324,11 +341,7 @@ class GitMirror(SourceFetcher): | 
| 324 | 341 | 
 | 
| 325 | 342 | 
         self._rebuild_git(fullpath)
 | 
| 326 | 343 | 
 | 
| 327 | 
-        # Check that the user specified ref exists in the track if provided & not already tracked
 | 
|
| 328 | 
-        if track:
 | 
|
| 329 | 
-            self.assert_ref_in_track(fullpath, track)
 | 
|
| 330 | 
-  | 
|
| 331 | 
-    def init_workspace(self, directory, track=None):
 | 
|
| 344 | 
+    def init_workspace(self, directory):
 | 
|
| 332 | 345 | 
         fullpath = os.path.join(directory, self.path)
 | 
| 333 | 346 | 
         url = self.source.translate_url(self.url)
 | 
| 334 | 347 | 
 | 
| ... | ... | @@ -344,10 +357,6 @@ class GitMirror(SourceFetcher): | 
| 344 | 357 | 
                          fail="Failed to checkout git ref {}".format(self.ref),
 | 
| 345 | 358 | 
                          cwd=fullpath)
 | 
| 346 | 359 | 
 | 
| 347 | 
-        # Check that the user specified ref exists in the track if provided & not already tracked
 | 
|
| 348 | 
-        if track:
 | 
|
| 349 | 
-            self.assert_ref_in_track(fullpath, track)
 | 
|
| 350 | 
-  | 
|
| 351 | 360 | 
     # List the submodules (path/url tuples) present at the given ref of this repo
 | 
| 352 | 361 | 
     def submodule_list(self):
 | 
| 353 | 362 | 
         modules = "{}:{}".format(self.ref, GIT_MODULES)
 | 
| ... | ... | @@ -408,32 +417,11 @@ class GitMirror(SourceFetcher): | 
| 408 | 417 | 
                      "underlying git repository with `git submodule add`."
 | 
| 409 | 418 | 
 | 
| 410 | 419 | 
             self.source.warn("{}: Ignoring inconsistent submodule '{}'"
 | 
| 411 | 
-                             .format(self.source, submodule), detail=detail, warning_token=INCONSISTENT_SUBMODULE)
 | 
|
| 420 | 
+                             .format(self.source, submodule), detail=detail,
 | 
|
| 421 | 
+                             warning_token=WARN_INCONSISTENT_SUBMODULE)
 | 
|
| 412 | 422 | 
 | 
| 413 | 423 | 
             return None
 | 
| 414 | 424 | 
 | 
| 415 | 
-    # Assert that ref exists in track, if track has been specified.
 | 
|
| 416 | 
-    def assert_ref_in_track(self, fullpath, track):
 | 
|
| 417 | 
-        _, branch = self.source.check_output([self.source.host_git, 'branch', '--list', track,
 | 
|
| 418 | 
-                                              '--contains', self.ref],
 | 
|
| 419 | 
-                                             cwd=fullpath,)
 | 
|
| 420 | 
-        if branch:
 | 
|
| 421 | 
-            return
 | 
|
| 422 | 
-        else:
 | 
|
| 423 | 
-            _, tag = self.source.check_output([self.source.host_git, 'tag', '--list', track,
 | 
|
| 424 | 
-                                               '--contains', self.ref],
 | 
|
| 425 | 
-                                              cwd=fullpath,)
 | 
|
| 426 | 
-            if tag:
 | 
|
| 427 | 
-                return
 | 
|
| 428 | 
-  | 
|
| 429 | 
-        detail = "The ref provided for the element does not exist locally in the provided track branch / tag " + \
 | 
|
| 430 | 
-                 "'{}'.\nYou may wish to track the element to update the ref from '{}' ".format(track, track) + \
 | 
|
| 431 | 
-                 "with `bst track`,\nor examine the upstream at '{}' for the specific ref.".format(self.url)
 | 
|
| 432 | 
-  | 
|
| 433 | 
-        self.source.warn("{}: expected ref '{}' was not found in given track '{}' for staged repository: '{}'\n"
 | 
|
| 434 | 
-                         .format(self.source, self.ref, track, self.url),
 | 
|
| 435 | 
-                         detail=detail, warning_token=CoreWarnings.REF_NOT_IN_TRACK)
 | 
|
| 436 | 
-  | 
|
| 437 | 425 | 
     def _rebuild_git(self, fullpath):
 | 
| 438 | 426 | 
         if not self.tags:
 | 
| 439 | 427 | 
             return
 | 
| ... | ... | @@ -562,7 +550,6 @@ class GitSource(Source): | 
| 562 | 550 | 
                 self.submodule_checkout_overrides[path] = checkout
 | 
| 563 | 551 | 
 | 
| 564 | 552 | 
         self.mark_download_url(self.original_url)
 | 
| 565 | 
-        self.tracked = False
 | 
|
| 566 | 553 | 
 | 
| 567 | 554 | 
     def preflight(self):
 | 
| 568 | 555 | 
         # Check if git is installed, get the binary at the same time
 | 
| ... | ... | @@ -652,8 +639,6 @@ class GitSource(Source): | 
| 652 | 639 | 
             # Update self.mirror.ref and node.ref from the self.tracking branch
 | 
| 653 | 640 | 
             ret = self.mirror.latest_commit_with_tags(self.tracking, self.track_tags)
 | 
| 654 | 641 | 
 | 
| 655 | 
-        # Set tracked attribute, parameter for if self.mirror.assert_ref_in_track is needed
 | 
|
| 656 | 
-        self.tracked = True
 | 
|
| 657 | 642 | 
         return ret
 | 
| 658 | 643 | 
 | 
| 659 | 644 | 
     def init_workspace(self, directory):
 | 
| ... | ... | @@ -661,7 +646,7 @@ class GitSource(Source): | 
| 661 | 646 | 
         self.refresh_submodules()
 | 
| 662 | 647 | 
 | 
| 663 | 648 | 
         with self.timed_activity('Setting up workspace "{}"'.format(directory), silent_nested=True):
 | 
| 664 | 
-            self.mirror.init_workspace(directory, track=(self.tracking if not self.tracked else None))
 | 
|
| 649 | 
+            self.mirror.init_workspace(directory)
 | 
|
| 665 | 650 | 
             for mirror in self.submodules:
 | 
| 666 | 651 | 
                 mirror.init_workspace(directory)
 | 
| 667 | 652 | 
 | 
| ... | ... | @@ -677,15 +662,9 @@ class GitSource(Source): | 
| 677 | 662 | 
         # Stage the main repo in the specified directory
 | 
| 678 | 663 | 
         #
 | 
| 679 | 664 | 
         with self.timed_activity("Staging {}".format(self.mirror.url), silent_nested=True):
 | 
| 680 | 
-            self.mirror.stage(directory, track=(self.tracking if not self.tracked else None))
 | 
|
| 665 | 
+            self.mirror.stage(directory)
 | 
|
| 681 | 666 | 
             for mirror in self.submodules:
 | 
| 682 | 
-                if mirror.path in self.submodule_checkout_overrides:
 | 
|
| 683 | 
-                    checkout = self.submodule_checkout_overrides[mirror.path]
 | 
|
| 684 | 
-                else:
 | 
|
| 685 | 
-                    checkout = self.checkout_submodules
 | 
|
| 686 | 
-  | 
|
| 687 | 
-                if checkout:
 | 
|
| 688 | 
-                    mirror.stage(directory)
 | 
|
| 667 | 
+                mirror.stage(directory)
 | 
|
| 689 | 668 | 
 | 
| 690 | 669 | 
     def get_source_fetchers(self):
 | 
| 691 | 670 | 
         yield self.mirror
 | 
| ... | ... | @@ -693,6 +672,74 @@ class GitSource(Source): | 
| 693 | 672 | 
         for submodule in self.submodules:
 | 
| 694 | 673 | 
             yield submodule
 | 
| 695 | 674 | 
 | 
| 675 | 
+    def validate_cache(self):
 | 
|
| 676 | 
+        discovered_submodules = {}
 | 
|
| 677 | 
+        unlisted_submodules = []
 | 
|
| 678 | 
+        invalid_submodules = []
 | 
|
| 679 | 
+  | 
|
| 680 | 
+        for path, url in self.mirror.submodule_list():
 | 
|
| 681 | 
+            discovered_submodules[path] = url
 | 
|
| 682 | 
+            if self.ignore_submodule(path):
 | 
|
| 683 | 
+                continue
 | 
|
| 684 | 
+  | 
|
| 685 | 
+            override_url = self.submodule_overrides.get(path)
 | 
|
| 686 | 
+            if not override_url:
 | 
|
| 687 | 
+                unlisted_submodules.append((path, url))
 | 
|
| 688 | 
+  | 
|
| 689 | 
+        # Warn about submodules which are explicitly configured but do not exist
 | 
|
| 690 | 
+        for path, url in self.submodule_overrides.items():
 | 
|
| 691 | 
+            if path not in discovered_submodules:
 | 
|
| 692 | 
+                invalid_submodules.append((path, url))
 | 
|
| 693 | 
+  | 
|
| 694 | 
+        if invalid_submodules:
 | 
|
| 695 | 
+            detail = []
 | 
|
| 696 | 
+            for path, url in invalid_submodules:
 | 
|
| 697 | 
+                detail.append("  Submodule URL '{}' at path '{}'".format(url, path))
 | 
|
| 698 | 
+  | 
|
| 699 | 
+            self.warn("{}: Invalid submodules specified".format(self),
 | 
|
| 700 | 
+                      warning_token=WARN_INVALID_SUBMODULE,
 | 
|
| 701 | 
+                      detail="The following submodules are specified in the source "
 | 
|
| 702 | 
+                      "description but do not exist according to the repository\n\n" +
 | 
|
| 703 | 
+                      "\n".join(detail))
 | 
|
| 704 | 
+  | 
|
| 705 | 
+        # Warn about submodules which exist but have not been explicitly configured
 | 
|
| 706 | 
+        if unlisted_submodules:
 | 
|
| 707 | 
+            detail = []
 | 
|
| 708 | 
+            for path, url in unlisted_submodules:
 | 
|
| 709 | 
+                detail.append("  Submodule URL '{}' at path '{}'".format(url, path))
 | 
|
| 710 | 
+  | 
|
| 711 | 
+            self.warn("{}: Unlisted submodules exist".format(self),
 | 
|
| 712 | 
+                      warning_token=WARN_UNLISTED_SUBMODULE,
 | 
|
| 713 | 
+                      detail="The following submodules exist but are not specified " +
 | 
|
| 714 | 
+                      "in the source description\n\n" +
 | 
|
| 715 | 
+                      "\n".join(detail))
 | 
|
| 716 | 
+  | 
|
| 717 | 
+        # Assert that the ref exists in the track tag/branch, if track has been specified.
 | 
|
| 718 | 
+        ref_in_track = False
 | 
|
| 719 | 
+        if self.tracking:
 | 
|
| 720 | 
+            _, branch = self.check_output([self.host_git, 'branch', '--list', self.tracking,
 | 
|
| 721 | 
+                                           '--contains', self.mirror.ref],
 | 
|
| 722 | 
+                                          cwd=self.mirror.mirror)
 | 
|
| 723 | 
+            if branch:
 | 
|
| 724 | 
+                ref_in_track = True
 | 
|
| 725 | 
+            else:
 | 
|
| 726 | 
+                _, tag = self.check_output([self.host_git, 'tag', '--list', self.tracking,
 | 
|
| 727 | 
+                                            '--contains', self.mirror.ref],
 | 
|
| 728 | 
+                                           cwd=self.mirror.mirror)
 | 
|
| 729 | 
+                if tag:
 | 
|
| 730 | 
+                    ref_in_track = True
 | 
|
| 731 | 
+  | 
|
| 732 | 
+            if not ref_in_track:
 | 
|
| 733 | 
+                detail = "The ref provided for the element does not exist locally " + \
 | 
|
| 734 | 
+                         "in the provided track branch / tag '{}'.\n".format(self.tracking) + \
 | 
|
| 735 | 
+                         "You may wish to track the element to update the ref from '{}' ".format(self.tracking) + \
 | 
|
| 736 | 
+                         "with `bst track`,\n" + \
 | 
|
| 737 | 
+                         "or examine the upstream at '{}' for the specific ref.".format(self.mirror.url)
 | 
|
| 738 | 
+  | 
|
| 739 | 
+                self.warn("{}: expected ref '{}' was not found in given track '{}' for staged repository: '{}'\n"
 | 
|
| 740 | 
+                          .format(self, self.mirror.ref, self.tracking, self.mirror.url),
 | 
|
| 741 | 
+                          detail=detail, warning_token=CoreWarnings.REF_NOT_IN_TRACK)
 | 
|
| 742 | 
+  | 
|
| 696 | 743 | 
     ###########################################################
 | 
| 697 | 744 | 
     #                     Local Functions                     #
 | 
| 698 | 745 | 
     ###########################################################
 | 
| ... | ... | @@ -717,12 +764,12 @@ class GitSource(Source): | 
| 717 | 764 | 
         self.mirror.ensure()
 | 
| 718 | 765 | 
         submodules = []
 | 
| 719 | 766 | 
 | 
| 720 | 
-        # XXX Here we should issue a warning if either:
 | 
|
| 721 | 
-        #   A.) A submodule exists but is not defined in the element configuration
 | 
|
| 722 | 
-        #   B.) The element configuration configures submodules which dont exist at the current ref
 | 
|
| 723 | 
-        #
 | 
|
| 724 | 767 | 
         for path, url in self.mirror.submodule_list():
 | 
| 725 | 768 | 
 | 
| 769 | 
+            # Completely ignore submodules which are disabled for checkout
 | 
|
| 770 | 
+            if self.ignore_submodule(path):
 | 
|
| 771 | 
+                continue
 | 
|
| 772 | 
+  | 
|
| 726 | 773 | 
             # Allow configuration to override the upstream
 | 
| 727 | 774 | 
             # location of the submodules.
 | 
| 728 | 775 | 
             override_url = self.submodule_overrides.get(path)
 | 
| ... | ... | @@ -746,6 +793,16 @@ class GitSource(Source): | 
| 746 | 793 | 
             tags.append((tag, commit_ref, annotated))
 | 
| 747 | 794 | 
         return tags
 | 
| 748 | 795 | 
 | 
| 796 | 
+    # Checks whether the plugin configuration has explicitly
 | 
|
| 797 | 
+    # configured this submodule to be ignored
 | 
|
| 798 | 
+    def ignore_submodule(self, path):
 | 
|
| 799 | 
+        try:
 | 
|
| 800 | 
+            checkout = self.submodule_checkout_overrides[path]
 | 
|
| 801 | 
+        except KeyError:
 | 
|
| 802 | 
+            checkout = self.checkout_submodules
 | 
|
| 803 | 
+  | 
|
| 804 | 
+        return not checkout
 | 
|
| 805 | 
+  | 
|
| 749 | 806 | 
 | 
| 750 | 807 | 
 # Plugin entry point
 | 
| 751 | 808 | 
 def setup():
 | 
| ... | ... | @@ -102,6 +102,11 @@ these methods are mandatory to implement. | 
| 102 | 102 | 
   submodules). For details on how to define a SourceFetcher, see
 | 
| 103 | 103 | 
   :ref:`SourceFetcher <core_source_fetcher>`.
 | 
| 104 | 104 | 
 | 
| 105 | 
+* :func:`Source.validate_cache() <buildstream.source.Source.validate_cache>`
 | 
|
| 106 | 
+  | 
|
| 107 | 
+  Perform any validations which require the sources to be cached.
 | 
|
| 108 | 
+  | 
|
| 109 | 
+  **Optional**: This is completely optional and will do nothing if left unimplemented.
 | 
|
| 105 | 110 | 
 | 
| 106 | 111 | 
 Accessing previous sources
 | 
| 107 | 112 | 
 --------------------------
 | 
| ... | ... | @@ -391,7 +396,8 @@ class Source(Plugin): | 
| 391 | 396 | 
 | 
| 392 | 397 | 
         If the backend in question supports resolving references from
 | 
| 393 | 398 | 
         a symbolic tracking branch or tag, then this should be implemented
 | 
| 394 | 
-        to perform this task on behalf of ``build-stream track`` commands.
 | 
|
| 399 | 
+        to perform this task on behalf of :ref:`bst track <invoking_track>`
 | 
|
| 400 | 
+        commands.
 | 
|
| 395 | 401 | 
 | 
| 396 | 402 | 
         This usually requires fetching new content from a remote origin
 | 
| 397 | 403 | 
         to see if a new ref has appeared for your branch or tag. If the
 | 
| ... | ... | @@ -479,9 +485,22 @@ class Source(Plugin): | 
| 479 | 485 | 
 | 
| 480 | 486 | 
         *Since: 1.2*
 | 
| 481 | 487 | 
         """
 | 
| 482 | 
-  | 
|
| 483 | 488 | 
         return []
 | 
| 484 | 489 | 
 | 
| 490 | 
+    def validate_cache(self):
 | 
|
| 491 | 
+        """Implement any validations once we know the sources are cached
 | 
|
| 492 | 
+  | 
|
| 493 | 
+        This is guaranteed to be called only once for a given session
 | 
|
| 494 | 
+        once the sources are known to be
 | 
|
| 495 | 
+        :attr:`Consistency.CACHED <buildstream.types.Consistency.CACHED>`,
 | 
|
| 496 | 
+        if source tracking is enabled in the session for this source,
 | 
|
| 497 | 
+        then this will only be called if the sources become cached after
 | 
|
| 498 | 
+        tracking completes.
 | 
|
| 499 | 
+  | 
|
| 500 | 
+        *Since: 1.4*
 | 
|
| 501 | 
+        """
 | 
|
| 502 | 
+        pass
 | 
|
| 503 | 
+  | 
|
| 485 | 504 | 
     #############################################################
 | 
| 486 | 505 | 
     #                       Public Methods                      #
 | 
| 487 | 506 | 
     #############################################################
 | 
| ... | ... | @@ -658,6 +677,11 @@ class Source(Plugin): | 
| 658 | 677 | 
             with context.silence():
 | 
| 659 | 678 | 
                 self.__consistency = self.get_consistency()  # pylint: disable=assignment-from-no-return
 | 
| 660 | 679 | 
 | 
| 680 | 
+                # Give the Source an opportunity to validate the cached
 | 
|
| 681 | 
+                # sources as soon as the Source becomes Consistency.CACHED.
 | 
|
| 682 | 
+                if self.__consistency == Consistency.CACHED:
 | 
|
| 683 | 
+                    self.validate_cache()
 | 
|
| 684 | 
+  | 
|
| 661 | 685 | 
     # Return cached consistency
 | 
| 662 | 686 | 
     #
 | 
| 663 | 687 | 
     def _get_consistency(self):
 | 
| ... | ... | @@ -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
 | 
| ... | ... | @@ -1259,3 +1259,16 @@ def _message_digest(message_buffer): | 
| 1259 | 1259 | 
     digest.hash = sha.hexdigest()
 | 
| 1260 | 1260 | 
     digest.size_bytes = len(message_buffer)
 | 
| 1261 | 1261 | 
     return digest
 | 
| 1262 | 
+  | 
|
| 1263 | 
+# Returns the first directory to contain filename, or an empty string if
 | 
|
| 1264 | 
+# none found
 | 
|
| 1265 | 
+#
 | 
|
| 1266 | 
+def _search_upward_for_file(directory, filename):
 | 
|
| 1267 | 
+    directory = os.path.abspath(directory)
 | 
|
| 1268 | 
+    while not os.path.isfile(os.path.join(directory, filename)):
 | 
|
| 1269 | 
+        parent_dir = os.path.dirname(directory)
 | 
|
| 1270 | 
+        if directory == parent_dir:
 | 
|
| 1271 | 
+            return ""
 | 
|
| 1272 | 
+        directory = parent_dir
 | 
|
| 1273 | 
+  | 
|
| 1274 | 
+    return directory
 | 
| ... | ... | @@ -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::
 | 
| ... | ... | @@ -31,6 +31,7 @@ import shutil | 
| 31 | 31 | 
 import subprocess
 | 
| 32 | 32 | 
 from ruamel.yaml.comments import CommentedSet
 | 
| 33 | 33 | 
 from tests.testutils import cli, create_repo, ALL_REPO_KINDS, wait_for_cache_granularity
 | 
| 34 | 
+from tests.testutils import create_artifact_share
 | 
|
| 34 | 35 | 
 | 
| 35 | 36 | 
 from buildstream import _yaml
 | 
| 36 | 37 | 
 from buildstream._exceptions import ErrorDomain, LoadError, LoadErrorReason
 | 
| ... | ... | @@ -615,9 +616,12 @@ def test_list(cli, tmpdir, datafiles): | 
| 615 | 616 | 
 @pytest.mark.datafiles(DATA_DIR)
 | 
| 616 | 617 | 
 @pytest.mark.parametrize("kind", repo_kinds)
 | 
| 617 | 618 | 
 @pytest.mark.parametrize("strict", [("strict"), ("non-strict")])
 | 
| 618 | 
-def test_build(cli, tmpdir, datafiles, kind, strict):
 | 
|
| 619 | 
+@pytest.mark.parametrize("call_from", [("project"), ("workspace")])
 | 
|
| 620 | 
+def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from):
 | 
|
| 621 | 
+    tmpdir = tmpdir_factory.mktemp('')
 | 
|
| 619 | 622 | 
     element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False)
 | 
| 620 | 623 | 
     checkout = os.path.join(str(tmpdir), 'checkout')
 | 
| 624 | 
+    args_pre = ['-C', workspace] if call_from == "workspace" else []
 | 
|
| 621 | 625 | 
 | 
| 622 | 626 | 
     # Modify workspace
 | 
| 623 | 627 | 
     shutil.rmtree(os.path.join(workspace, 'usr', 'bin'))
 | 
| ... | ... | @@ -640,15 +644,14 @@ def test_build(cli, tmpdir, datafiles, kind, strict): | 
| 640 | 644 | 
     # Build modified workspace
 | 
| 641 | 645 | 
     assert cli.get_element_state(project, element_name) == 'buildable'
 | 
| 642 | 646 | 
     assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
 | 
| 643 | 
-    result = cli.run(project=project, args=['build', element_name])
 | 
|
| 647 | 
+    result = cli.run(project=project, args=args_pre + ['build', element_name])
 | 
|
| 644 | 648 | 
     result.assert_success()
 | 
| 645 | 649 | 
     assert cli.get_element_state(project, element_name) == 'cached'
 | 
| 646 | 650 | 
     assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
 | 
| 647 | 651 | 
 | 
| 648 | 652 | 
     # Checkout the result
 | 
| 649 | 
-    result = cli.run(project=project, args=[
 | 
|
| 650 | 
-        'checkout', element_name, checkout
 | 
|
| 651 | 
-    ])
 | 
|
| 653 | 
+    result = cli.run(project=project,
 | 
|
| 654 | 
+                     args=args_pre + ['checkout', element_name, checkout])
 | 
|
| 652 | 655 | 
     result.assert_success()
 | 
| 653 | 656 | 
 | 
| 654 | 657 | 
     # Check that the pony.conf from the modified workspace exists
 | 
| ... | ... | @@ -1055,3 +1058,131 @@ def test_multiple_failed_builds(cli, tmpdir, datafiles): | 
| 1055 | 1058 | 
         result = cli.run(project=project, args=["build", element_name])
 | 
| 1056 | 1059 | 
         assert "BUG" not in result.stderr
 | 
| 1057 | 1060 | 
         assert cli.get_element_state(project, element_name) != "cached"
 | 
| 1061 | 
+  | 
|
| 1062 | 
+  | 
|
| 1063 | 
+@pytest.mark.datafiles(DATA_DIR)
 | 
|
| 1064 | 
+def test_external_fetch(cli, datafiles, tmpdir_factory):
 | 
|
| 1065 | 
+    # Fetching from a workspace outside a project doesn't fail horribly
 | 
|
| 1066 | 
+    tmpdir = tmpdir_factory.mktemp('')
 | 
|
| 1067 | 
+    element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
 | 
|
| 1068 | 
+  | 
|
| 1069 | 
+    result = cli.run(project=project, args=['-C', workspace, 'fetch', element_name])
 | 
|
| 1070 | 
+    result.assert_success()
 | 
|
| 1071 | 
+  | 
|
| 1072 | 
+    # We already fetched it by opening the workspace, but we're also checking
 | 
|
| 1073 | 
+    # `bst show` works here
 | 
|
| 1074 | 
+    assert cli.get_element_state(project, element_name) == 'buildable'
 | 
|
| 1075 | 
+  | 
|
| 1076 | 
+  | 
|
| 1077 | 
+@pytest.mark.datafiles(DATA_DIR)
 | 
|
| 1078 | 
+def test_external_push_pull(cli, datafiles, tmpdir_factory):
 | 
|
| 1079 | 
+    # Pushing and pulling to/from an artifact cache works from an external workspace
 | 
|
| 1080 | 
+    tmpdir = tmpdir_factory.mktemp('')
 | 
|
| 1081 | 
+    element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
 | 
|
| 1082 | 
+  | 
|
| 1083 | 
+    with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
 | 
|
| 1084 | 
+        result = cli.run(project=project, args=['-C', workspace, 'build', element_name])
 | 
|
| 1085 | 
+        result.assert_success()
 | 
|
| 1086 | 
+  | 
|
| 1087 | 
+        cli.configure({
 | 
|
| 1088 | 
+            'artifacts': {'url': share.repo, 'push': True}
 | 
|
| 1089 | 
+        })
 | 
|
| 1090 | 
+  | 
|
| 1091 | 
+        result = cli.run(project=project, args=['-C', workspace, 'push', element_name])
 | 
|
| 1092 | 
+        result.assert_success()
 | 
|
| 1093 | 
+  | 
|
| 1094 | 
+        result = cli.run(project=project, args=['-C', workspace, 'pull', '--deps', 'all', element_name])
 | 
|
| 1095 | 
+        result.assert_success()
 | 
|
| 1096 | 
+  | 
|
| 1097 | 
+  | 
|
| 1098 | 
+@pytest.mark.datafiles(DATA_DIR)
 | 
|
| 1099 | 
+def test_external_track(cli, datafiles, tmpdir_factory):
 | 
|
| 1100 | 
+    # Tracking does not get horribly confused
 | 
|
| 1101 | 
+    tmpdir = tmpdir_factory.mktemp('')
 | 
|
| 1102 | 
+    element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", True)
 | 
|
| 1103 | 
+  | 
|
| 1104 | 
+    # The workspace is necessarily already tracked, so we only care that
 | 
|
| 1105 | 
+    # there's no weird errors.
 | 
|
| 1106 | 
+    result = cli.run(project=project, args=['-C', workspace, 'track', element_name])
 | 
|
| 1107 | 
+    result.assert_success()
 | 
|
| 1108 | 
+  | 
|
| 1109 | 
+  | 
|
| 1110 | 
+@pytest.mark.datafiles(DATA_DIR)
 | 
|
| 1111 | 
+def test_external_open_other(cli, datafiles, tmpdir_factory):
 | 
|
| 1112 | 
+    # >From inside an external workspace, open another workspace
 | 
|
| 1113 | 
+    tmpdir1 = tmpdir_factory.mktemp('')
 | 
|
| 1114 | 
+    tmpdir2 = tmpdir_factory.mktemp('')
 | 
|
| 1115 | 
+    # Making use of the assumption that it's the same project in both invocations of open_workspace
 | 
|
| 1116 | 
+    alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
 | 
|
| 1117 | 
+    beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
 | 
|
| 1118 | 
+  | 
|
| 1119 | 
+    # Closing the other element first, because I'm too lazy to create an
 | 
|
| 1120 | 
+    # element without opening it
 | 
|
| 1121 | 
+    result = cli.run(project=project, args=['workspace', 'close', beta_element])
 | 
|
| 1122 | 
+    result.assert_success()
 | 
|
| 1123 | 
+  | 
|
| 1124 | 
+    result = cli.run(project=project, args=[
 | 
|
| 1125 | 
+        '-C', alpha_workspace, 'workspace', 'open', '--force', '--directory', beta_workspace, beta_element
 | 
|
| 1126 | 
+    ])
 | 
|
| 1127 | 
+    result.assert_success()
 | 
|
| 1128 | 
+  | 
|
| 1129 | 
+  | 
|
| 1130 | 
+@pytest.mark.datafiles(DATA_DIR)
 | 
|
| 1131 | 
+def test_external_close_other(cli, datafiles, tmpdir_factory):
 | 
|
| 1132 | 
+    # >From inside an external workspace, close the other workspace
 | 
|
| 1133 | 
+    tmpdir1 = tmpdir_factory.mktemp('')
 | 
|
| 1134 | 
+    tmpdir2 = tmpdir_factory.mktemp('')
 | 
|
| 1135 | 
+    # Making use of the assumption that it's the same project in both invocations of open_workspace
 | 
|
| 1136 | 
+    alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
 | 
|
| 1137 | 
+    beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
 | 
|
| 1138 | 
+  | 
|
| 1139 | 
+    result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', beta_element])
 | 
|
| 1140 | 
+    result.assert_success()
 | 
|
| 1141 | 
+  | 
|
| 1142 | 
+  | 
|
| 1143 | 
+@pytest.mark.datafiles(DATA_DIR)
 | 
|
| 1144 | 
+def test_external_close_self(cli, datafiles, tmpdir_factory):
 | 
|
| 1145 | 
+    # >From inside an external workspace, close it
 | 
|
| 1146 | 
+    tmpdir1 = tmpdir_factory.mktemp('')
 | 
|
| 1147 | 
+    tmpdir2 = tmpdir_factory.mktemp('')
 | 
|
| 1148 | 
+    # Making use of the assumption that it's the same project in both invocations of open_workspace
 | 
|
| 1149 | 
+    alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
 | 
|
| 1150 | 
+    beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
 | 
|
| 1151 | 
+  | 
|
| 1152 | 
+    result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', alpha_element])
 | 
|
| 1153 | 
+    result.assert_success()
 | 
|
| 1154 | 
+  | 
|
| 1155 | 
+  | 
|
| 1156 | 
+@pytest.mark.datafiles(DATA_DIR)
 | 
|
| 1157 | 
+def test_external_reset_other(cli, datafiles, tmpdir_factory):
 | 
|
| 1158 | 
+    tmpdir1 = tmpdir_factory.mktemp('')
 | 
|
| 1159 | 
+    tmpdir2 = tmpdir_factory.mktemp('')
 | 
|
| 1160 | 
+    # Making use of the assumption that it's the same project in both invocations of open_workspace
 | 
|
| 1161 | 
+    alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
 | 
|
| 1162 | 
+    beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
 | 
|
| 1163 | 
+  | 
|
| 1164 | 
+    result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'reset', beta_element])
 | 
|
| 1165 | 
+    result.assert_success()
 | 
|
| 1166 | 
+  | 
|
| 1167 | 
+  | 
|
| 1168 | 
+@pytest.mark.datafiles(DATA_DIR)
 | 
|
| 1169 | 
+def test_external_reset_self(cli, datafiles, tmpdir):
 | 
|
| 1170 | 
+    element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
 | 
|
| 1171 | 
+  | 
|
| 1172 | 
+    # Command succeeds
 | 
|
| 1173 | 
+    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'reset', element])
 | 
|
| 1174 | 
+    result.assert_success()
 | 
|
| 1175 | 
+  | 
|
| 1176 | 
+    # Successive commands still work (i.e. .bstproject.yaml hasn't been deleted)
 | 
|
| 1177 | 
+    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'list'])
 | 
|
| 1178 | 
+    result.assert_success()
 | 
|
| 1179 | 
+  | 
|
| 1180 | 
+  | 
|
| 1181 | 
+@pytest.mark.datafiles(DATA_DIR)
 | 
|
| 1182 | 
+def test_external_list(cli, datafiles, tmpdir_factory):
 | 
|
| 1183 | 
+    tmpdir = tmpdir_factory.mktemp('')
 | 
|
| 1184 | 
+    # Making use of the assumption that it's the same project in both invocations of open_workspace
 | 
|
| 1185 | 
+    element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
 | 
|
| 1186 | 
+  | 
|
| 1187 | 
+    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'list'])
 | 
|
| 1188 | 
+    result.assert_success()
 | 
| ... | ... | @@ -353,3 +353,29 @@ def test_integration_devices(cli, tmpdir, datafiles): | 
| 353 | 353 | 
 | 
| 354 | 354 | 
     result = execute_shell(cli, project, ["true"], element=element_name)
 | 
| 355 | 355 | 
     assert result.exit_code == 0
 | 
| 356 | 
+  | 
|
| 357 | 
+  | 
|
| 358 | 
+# Test that a shell can be opened from an external workspace
 | 
|
| 359 | 
+@pytest.mark.datafiles(DATA_DIR)
 | 
|
| 360 | 
+@pytest.mark.parametrize("build_shell", [("build"), ("nobuild")])
 | 
|
| 361 | 
+@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
 | 
|
| 362 | 
+def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_shell):
 | 
|
| 363 | 
+    tmpdir = tmpdir_factory.mktemp("")
 | 
|
| 364 | 
+    project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
|
| 365 | 
+    element_name = 'autotools/amhello.bst'
 | 
|
| 366 | 
+    workspace_dir = os.path.join(str(tmpdir), 'workspace')
 | 
|
| 367 | 
+  | 
|
| 368 | 
+    result = cli.run(project=project, args=[
 | 
|
| 369 | 
+        'workspace', 'open', '--directory', workspace_dir, element_name
 | 
|
| 370 | 
+    ])
 | 
|
| 371 | 
+    result.assert_success()
 | 
|
| 372 | 
+  | 
|
| 373 | 
+    result = cli.run(project=project, args=['-C', workspace_dir, 'build', element_name])
 | 
|
| 374 | 
+    result.assert_success()
 | 
|
| 375 | 
+  | 
|
| 376 | 
+    command = ['shell']
 | 
|
| 377 | 
+    if build_shell == 'build':
 | 
|
| 378 | 
+        command.append('--build')
 | 
|
| 379 | 
+    command.extend([element_name, '--', 'true'])
 | 
|
| 380 | 
+    result = cli.run(project=project, cwd=workspace_dir, args=command)
 | 
|
| 381 | 
+    result.assert_success()
 | 
| ... | ... | @@ -414,9 +414,18 @@ 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 | 
 | 
| 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'))
 | 
|
| 428 | 
+  | 
|
| 420 | 429 | 
     # Create the repo from 'repofiles', create a branch without latest commit
 | 
| 421 | 430 | 
     repo = create_repo('git', str(tmpdir))
 | 
| 422 | 431 | 
     ref = repo.create(os.path.join(project, 'repofiles'))
 | 
| ... | ... | @@ -435,33 +444,184 @@ def test_ref_not_in_track_warn(cli, tmpdir, datafiles): | 
| 435 | 444 | 
     }
 | 
| 436 | 445 | 
     _yaml.dump(element, os.path.join(project, 'target.bst'))
 | 
| 437 | 446 | 
 | 
| 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 | 447 | 
     result = cli.run(project=project, args=['build', 'target.bst'])
 | 
| 441 | 
-    assert "The ref provided for the element does not exist locally" in result.stderr
 | 
|
| 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
 | 
|
| 442 | 456 | 
 | 
| 443 | 457 | 
 | 
| 444 | 458 | 
 @pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
 | 
| 445 | 459 | 
 @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
 | 
| 446 | 
-def test_ref_not_in_track_warn_error(cli, tmpdir, datafiles):
 | 
|
| 460 | 
+@pytest.mark.parametrize("fail", ['warn', 'error'])
 | 
|
| 461 | 
+def test_unlisted_submodule(cli, tmpdir, datafiles, fail):
 | 
|
| 447 | 462 | 
     project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 448 | 463 | 
 | 
| 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]
 | 
|
| 464 | 
+    # Make the warning an error if we're testing errors
 | 
|
| 465 | 
+    if fail == 'error':
 | 
|
| 466 | 
+        project_template = {
 | 
|
| 467 | 
+            "name": "foo",
 | 
|
| 468 | 
+            "fatal-warnings": ['git:unlisted-submodule']
 | 
|
| 469 | 
+        }
 | 
|
| 470 | 
+        _yaml.dump(project_template, os.path.join(project, 'project.conf'))
 | 
|
| 471 | 
+  | 
|
| 472 | 
+    # Create the submodule first from the 'subrepofiles' subdir
 | 
|
| 473 | 
+    subrepo = create_repo('git', str(tmpdir), 'subrepo')
 | 
|
| 474 | 
+    subrepo.create(os.path.join(project, 'subrepofiles'))
 | 
|
| 475 | 
+  | 
|
| 476 | 
+    # Create the repo from 'repofiles' subdir
 | 
|
| 477 | 
+    repo = create_repo('git', str(tmpdir))
 | 
|
| 478 | 
+    ref = repo.create(os.path.join(project, 'repofiles'))
 | 
|
| 479 | 
+  | 
|
| 480 | 
+    # Add a submodule pointing to the one we created
 | 
|
| 481 | 
+    ref = repo.add_submodule('subdir', 'file://' + subrepo.repo)
 | 
|
| 482 | 
+  | 
|
| 483 | 
+    # Create the source, and delete the explicit configuration
 | 
|
| 484 | 
+    # of the submodules.
 | 
|
| 485 | 
+    #
 | 
|
| 486 | 
+    # We expect this to cause an unlisted submodule warning
 | 
|
| 487 | 
+    # after the source has been fetched.
 | 
|
| 488 | 
+    #
 | 
|
| 489 | 
+    gitsource = repo.source_config(ref=ref)
 | 
|
| 490 | 
+    del gitsource['submodules']
 | 
|
| 491 | 
+  | 
|
| 492 | 
+    # Write out our test target
 | 
|
| 493 | 
+    element = {
 | 
|
| 494 | 
+        'kind': 'import',
 | 
|
| 495 | 
+        'sources': [
 | 
|
| 496 | 
+            gitsource
 | 
|
| 497 | 
+        ]
 | 
|
| 453 | 498 | 
     }
 | 
| 499 | 
+    _yaml.dump(element, os.path.join(project, 'target.bst'))
 | 
|
| 454 | 500 | 
 | 
| 455 | 
-    _yaml.dump(project_template, os.path.join(project, 'project.conf'))
 | 
|
| 501 | 
+    # We will not see the warning or error before the first fetch, because
 | 
|
| 502 | 
+    # we don't have the repository yet and so we have no knowledge of
 | 
|
| 503 | 
+    # the unlisted submodule.
 | 
|
| 504 | 
+    result = cli.run(project=project, args=['show', 'target.bst'])
 | 
|
| 505 | 
+    result.assert_success()
 | 
|
| 506 | 
+    assert "git:unlisted-submodule" not in result.stderr
 | 
|
| 456 | 507 | 
 | 
| 457 | 
-    # Create the repo from 'repofiles', create a branch without latest commit
 | 
|
| 508 | 
+    # We will notice this directly in fetch, as it will try to fetch
 | 
|
| 509 | 
+    # the submodules it discovers as a result of fetching the primary repo.
 | 
|
| 510 | 
+    result = cli.run(project=project, args=['fetch', 'target.bst'])
 | 
|
| 511 | 
+  | 
|
| 512 | 
+    # Assert a warning or an error depending on what we're checking
 | 
|
| 513 | 
+    if fail == 'error':
 | 
|
| 514 | 
+        result.assert_main_error(ErrorDomain.STREAM, None)
 | 
|
| 515 | 
+        result.assert_task_error(ErrorDomain.PLUGIN, 'git:unlisted-submodule')
 | 
|
| 516 | 
+    else:
 | 
|
| 517 | 
+        result.assert_success()
 | 
|
| 518 | 
+        assert "git:unlisted-submodule" in result.stderr
 | 
|
| 519 | 
+  | 
|
| 520 | 
+    # Now that we've fetched it, `bst show` will discover the unlisted submodule too
 | 
|
| 521 | 
+    result = cli.run(project=project, args=['show', 'target.bst'])
 | 
|
| 522 | 
+  | 
|
| 523 | 
+    # Assert a warning or an error depending on what we're checking
 | 
|
| 524 | 
+    if fail == 'error':
 | 
|
| 525 | 
+        result.assert_main_error(ErrorDomain.PLUGIN, 'git:unlisted-submodule')
 | 
|
| 526 | 
+    else:
 | 
|
| 527 | 
+        result.assert_success()
 | 
|
| 528 | 
+        assert "git:unlisted-submodule" in result.stderr
 | 
|
| 529 | 
+  | 
|
| 530 | 
+  | 
|
| 531 | 
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
 | 
|
| 532 | 
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
 | 
|
| 533 | 
+@pytest.mark.parametrize("fail", ['warn', 'error'])
 | 
|
| 534 | 
+def test_track_unlisted_submodule(cli, tmpdir, datafiles, fail):
 | 
|
| 535 | 
+    project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
|
| 536 | 
+  | 
|
| 537 | 
+    # Make the warning an error if we're testing errors
 | 
|
| 538 | 
+    if fail == 'error':
 | 
|
| 539 | 
+        project_template = {
 | 
|
| 540 | 
+            "name": "foo",
 | 
|
| 541 | 
+            "fatal-warnings": ['git:unlisted-submodule']
 | 
|
| 542 | 
+        }
 | 
|
| 543 | 
+        _yaml.dump(project_template, os.path.join(project, 'project.conf'))
 | 
|
| 544 | 
+  | 
|
| 545 | 
+    # Create the submodule first from the 'subrepofiles' subdir
 | 
|
| 546 | 
+    subrepo = create_repo('git', str(tmpdir), 'subrepo')
 | 
|
| 547 | 
+    subrepo.create(os.path.join(project, 'subrepofiles'))
 | 
|
| 548 | 
+  | 
|
| 549 | 
+    # Create the repo from 'repofiles' subdir
 | 
|
| 458 | 550 | 
     repo = create_repo('git', str(tmpdir))
 | 
| 459 | 551 | 
     ref = repo.create(os.path.join(project, 'repofiles'))
 | 
| 460 | 552 | 
 | 
| 553 | 
+    # Add a submodule pointing to the one we created, but use
 | 
|
| 554 | 
+    # the original ref, let the submodules appear after tracking
 | 
|
| 555 | 
+    repo.add_submodule('subdir', 'file://' + subrepo.repo)
 | 
|
| 556 | 
+  | 
|
| 557 | 
+    # Create the source, and delete the explicit configuration
 | 
|
| 558 | 
+    # of the submodules.
 | 
|
| 461 | 559 | 
     gitsource = repo.source_config(ref=ref)
 | 
| 560 | 
+    del gitsource['submodules']
 | 
|
| 462 | 561 | 
 | 
| 463 | 
-    # Overwrite the track value to the added branch
 | 
|
| 464 | 
-    gitsource['track'] = 'foo'
 | 
|
| 562 | 
+    # Write out our test target
 | 
|
| 563 | 
+    element = {
 | 
|
| 564 | 
+        'kind': 'import',
 | 
|
| 565 | 
+        'sources': [
 | 
|
| 566 | 
+            gitsource
 | 
|
| 567 | 
+        ]
 | 
|
| 568 | 
+    }
 | 
|
| 569 | 
+    _yaml.dump(element, os.path.join(project, 'target.bst'))
 | 
|
| 570 | 
+  | 
|
| 571 | 
+    # Fetch the repo, we will not see the warning because we
 | 
|
| 572 | 
+    # are still pointing to a ref which predates the submodules
 | 
|
| 573 | 
+    result = cli.run(project=project, args=['fetch', 'target.bst'])
 | 
|
| 574 | 
+    result.assert_success()
 | 
|
| 575 | 
+    assert "git:unlisted-submodule" not in result.stderr
 | 
|
| 576 | 
+  | 
|
| 577 | 
+    # We won't get a warning/error when tracking either, the source
 | 
|
| 578 | 
+    # has not become Consistency.CACHED so the opportunity to check
 | 
|
| 579 | 
+    # for the warning has not yet arisen.
 | 
|
| 580 | 
+    result = cli.run(project=project, args=['track', 'target.bst'])
 | 
|
| 581 | 
+    result.assert_success()
 | 
|
| 582 | 
+    assert "git:unlisted-submodule" not in result.stderr
 | 
|
| 583 | 
+  | 
|
| 584 | 
+    # Fetching the repo at the new ref will finally reveal the warning
 | 
|
| 585 | 
+    result = cli.run(project=project, args=['fetch', 'target.bst'])
 | 
|
| 586 | 
+    if fail == 'error':
 | 
|
| 587 | 
+        result.assert_main_error(ErrorDomain.STREAM, None)
 | 
|
| 588 | 
+        result.assert_task_error(ErrorDomain.PLUGIN, 'git:unlisted-submodule')
 | 
|
| 589 | 
+    else:
 | 
|
| 590 | 
+        result.assert_success()
 | 
|
| 591 | 
+        assert "git:unlisted-submodule" in result.stderr
 | 
|
| 592 | 
+  | 
|
| 593 | 
+  | 
|
| 594 | 
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
 | 
|
| 595 | 
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
 | 
|
| 596 | 
+@pytest.mark.parametrize("fail", ['warn', 'error'])
 | 
|
| 597 | 
+def test_invalid_submodule(cli, tmpdir, datafiles, fail):
 | 
|
| 598 | 
+    project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
|
| 599 | 
+  | 
|
| 600 | 
+    # Make the warning an error if we're testing errors
 | 
|
| 601 | 
+    if fail == 'error':
 | 
|
| 602 | 
+        project_template = {
 | 
|
| 603 | 
+            "name": "foo",
 | 
|
| 604 | 
+            "fatal-warnings": ['git:invalid-submodule']
 | 
|
| 605 | 
+        }
 | 
|
| 606 | 
+        _yaml.dump(project_template, os.path.join(project, 'project.conf'))
 | 
|
| 607 | 
+  | 
|
| 608 | 
+    # Create the repo from 'repofiles' subdir
 | 
|
| 609 | 
+    repo = create_repo('git', str(tmpdir))
 | 
|
| 610 | 
+    ref = repo.create(os.path.join(project, 'repofiles'))
 | 
|
| 611 | 
+  | 
|
| 612 | 
+    # Create the source without any submodules, and add
 | 
|
| 613 | 
+    # an invalid submodule configuration to it.
 | 
|
| 614 | 
+    #
 | 
|
| 615 | 
+    # We expect this to cause an invalid submodule warning
 | 
|
| 616 | 
+    # after the source has been fetched and we know what
 | 
|
| 617 | 
+    # the real submodules actually are.
 | 
|
| 618 | 
+    #
 | 
|
| 619 | 
+    gitsource = repo.source_config(ref=ref)
 | 
|
| 620 | 
+    gitsource['submodules'] = {
 | 
|
| 621 | 
+        'subdir': {
 | 
|
| 622 | 
+            'url': 'https://pony.org/repo.git'
 | 
|
| 623 | 
+        }
 | 
|
| 624 | 
+    }
 | 
|
| 465 | 625 | 
 | 
| 466 | 626 | 
     # Write out our test target
 | 
| 467 | 627 | 
     element = {
 | 
| ... | ... | @@ -472,11 +632,95 @@ def test_ref_not_in_track_warn_error(cli, tmpdir, datafiles): | 
| 472 | 632 | 
     }
 | 
| 473 | 633 | 
     _yaml.dump(element, os.path.join(project, 'target.bst'))
 | 
| 474 | 634 | 
 | 
| 475 | 
-    # Assert that build raises a warning here that is captured
 | 
|
| 476 | 
-    # as plugin error, due to the fatal warning being set
 | 
|
| 477 | 
-    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)
 | 
|
| 635 | 
+    # We will not see the warning or error before the first fetch, because
 | 
|
| 636 | 
+    # we don't have the repository yet and so we have no knowledge of
 | 
|
| 637 | 
+    # the unlisted submodule.
 | 
|
| 638 | 
+    result = cli.run(project=project, args=['show', 'target.bst'])
 | 
|
| 639 | 
+    result.assert_success()
 | 
|
| 640 | 
+    assert "git:invalid-submodule" not in result.stderr
 | 
|
| 641 | 
+  | 
|
| 642 | 
+    # We will notice this directly in fetch, as it will try to fetch
 | 
|
| 643 | 
+    # the submodules it discovers as a result of fetching the primary repo.
 | 
|
| 644 | 
+    result = cli.run(project=project, args=['fetch', 'target.bst'])
 | 
|
| 645 | 
+  | 
|
| 646 | 
+    # Assert a warning or an error depending on what we're checking
 | 
|
| 647 | 
+    if fail == 'error':
 | 
|
| 648 | 
+        result.assert_main_error(ErrorDomain.STREAM, None)
 | 
|
| 649 | 
+        result.assert_task_error(ErrorDomain.PLUGIN, 'git:invalid-submodule')
 | 
|
| 650 | 
+    else:
 | 
|
| 651 | 
+        result.assert_success()
 | 
|
| 652 | 
+        assert "git:invalid-submodule" in result.stderr
 | 
|
| 653 | 
+  | 
|
| 654 | 
+    # Now that we've fetched it, `bst show` will discover the unlisted submodule too
 | 
|
| 655 | 
+    result = cli.run(project=project, args=['show', 'target.bst'])
 | 
|
| 656 | 
+  | 
|
| 657 | 
+    # Assert a warning or an error depending on what we're checking
 | 
|
| 658 | 
+    if fail == 'error':
 | 
|
| 659 | 
+        result.assert_main_error(ErrorDomain.PLUGIN, 'git:invalid-submodule')
 | 
|
| 660 | 
+    else:
 | 
|
| 661 | 
+        result.assert_success()
 | 
|
| 662 | 
+        assert "git:invalid-submodule" in result.stderr
 | 
|
| 663 | 
+  | 
|
| 664 | 
+  | 
|
| 665 | 
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
 | 
|
| 666 | 
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
 | 
|
| 667 | 
+@pytest.mark.parametrize("fail", ['warn', 'error'])
 | 
|
| 668 | 
+def test_track_invalid_submodule(cli, tmpdir, datafiles, fail):
 | 
|
| 669 | 
+    project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
|
| 670 | 
+  | 
|
| 671 | 
+    # Make the warning an error if we're testing errors
 | 
|
| 672 | 
+    if fail == 'error':
 | 
|
| 673 | 
+        project_template = {
 | 
|
| 674 | 
+            "name": "foo",
 | 
|
| 675 | 
+            "fatal-warnings": ['git:invalid-submodule']
 | 
|
| 676 | 
+        }
 | 
|
| 677 | 
+        _yaml.dump(project_template, os.path.join(project, 'project.conf'))
 | 
|
| 678 | 
+  | 
|
| 679 | 
+    # Create the submodule first from the 'subrepofiles' subdir
 | 
|
| 680 | 
+    subrepo = create_repo('git', str(tmpdir), 'subrepo')
 | 
|
| 681 | 
+    subrepo.create(os.path.join(project, 'subrepofiles'))
 | 
|
| 682 | 
+  | 
|
| 683 | 
+    # Create the repo from 'repofiles' subdir
 | 
|
| 684 | 
+    repo = create_repo('git', str(tmpdir))
 | 
|
| 685 | 
+    ref = repo.create(os.path.join(project, 'repofiles'))
 | 
|
| 686 | 
+  | 
|
| 687 | 
+    # Add a submodule pointing to the one we created
 | 
|
| 688 | 
+    ref = repo.add_submodule('subdir', 'file://' + subrepo.repo)
 | 
|
| 689 | 
+  | 
|
| 690 | 
+    # Add a commit beyond the ref which *removes* the submodule we've added
 | 
|
| 691 | 
+    repo.remove_path('subdir')
 | 
|
| 692 | 
+  | 
|
| 693 | 
+    # Create the source, this will keep the submodules so initially
 | 
|
| 694 | 
+    # the configuration is valid for the ref we're using
 | 
|
| 695 | 
+    gitsource = repo.source_config(ref=ref)
 | 
|
| 696 | 
+  | 
|
| 697 | 
+    # Write out our test target
 | 
|
| 698 | 
+    element = {
 | 
|
| 699 | 
+        'kind': 'import',
 | 
|
| 700 | 
+        'sources': [
 | 
|
| 701 | 
+            gitsource
 | 
|
| 702 | 
+        ]
 | 
|
| 703 | 
+    }
 | 
|
| 704 | 
+    _yaml.dump(element, os.path.join(project, 'target.bst'))
 | 
|
| 705 | 
+  | 
|
| 706 | 
+    # Fetch the repo, we will not see the warning because we
 | 
|
| 707 | 
+    # are still pointing to a ref which predates the submodules
 | 
|
| 708 | 
+    result = cli.run(project=project, args=['fetch', 'target.bst'])
 | 
|
| 709 | 
+    result.assert_success()
 | 
|
| 710 | 
+    assert "git:invalid-submodule" not in result.stderr
 | 
|
| 711 | 
+  | 
|
| 712 | 
+    # In this case, we will get the error directly after tracking,
 | 
|
| 713 | 
+    # since the new HEAD does not require any submodules which are
 | 
|
| 714 | 
+    # not locally cached, the Source will be CACHED directly after
 | 
|
| 715 | 
+    # tracking and the validations will occur as a result.
 | 
|
| 716 | 
+    #
 | 
|
| 717 | 
+    result = cli.run(project=project, args=['track', 'target.bst'])
 | 
|
| 718 | 
+    if fail == 'error':
 | 
|
| 719 | 
+        result.assert_main_error(ErrorDomain.STREAM, None)
 | 
|
| 720 | 
+        result.assert_task_error(ErrorDomain.PLUGIN, 'git:invalid-submodule')
 | 
|
| 721 | 
+    else:
 | 
|
| 722 | 
+        result.assert_success()
 | 
|
| 723 | 
+        assert "git:invalid-submodule" in result.stderr
 | 
|
| 480 | 724 | 
 | 
| 481 | 725 | 
 | 
| 482 | 726 | 
 @pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
 | 
| ... | ... | @@ -76,6 +76,12 @@ class Git(Repo): | 
| 76 | 76 | 
         self._run_git('commit', '-m', 'Added the submodule')
 | 
| 77 | 77 | 
         return self.latest_commit()
 | 
| 78 | 78 | 
 | 
| 79 | 
+    # This can also be used to a file or a submodule
 | 
|
| 80 | 
+    def remove_path(self, path):
 | 
|
| 81 | 
+        self._run_git('rm', path)
 | 
|
| 82 | 
+        self._run_git('commit', '-m', 'Removing {}'.format(path))
 | 
|
| 83 | 
+        return self.latest_commit()
 | 
|
| 84 | 
+  | 
|
| 79 | 85 | 
     def source_config(self, ref=None, checkout_submodules=None):
 | 
| 80 | 86 | 
         config = {
 | 
| 81 | 87 | 
             'kind': 'git',
 | 
