diff options
Diffstat (limited to 'buildstream/_frontend/app.py')
-rw-r--r-- | buildstream/_frontend/app.py | 122 |
1 files changed, 9 insertions, 113 deletions
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py index feac0ab9c..2e53b54de 100644 --- a/buildstream/_frontend/app.py +++ b/buildstream/_frontend/app.py @@ -20,7 +20,6 @@ import os import sys -import shutil import resource import traceback import datetime @@ -32,7 +31,7 @@ import click from click import UsageError # Import buildstream public symbols -from .. import Scope, Consistency +from .. import Scope # Import various buildstream internals from .._context import Context @@ -212,6 +211,9 @@ class App(): except BstError as e: self._error_exit(e, "Error loading project") + # Create the stream now. + self.stream = Stream(self.context) + # Run the body of the session here, once everything is loaded try: yield @@ -296,7 +298,11 @@ class App(): except BstError as e: self._error_exit(e, "Error initializing pipeline") - self.stream = Stream(self.context, self.scheduler, self.pipeline) + # XXX This is going to change soon ! + # + self.stream._scheduler = self.scheduler + self.stream._pipeline = self.pipeline + self.stream.total_elements = len(list(self.pipeline.dependencies(Scope.ALL))) # Pipeline is loaded, now we can tell the logger about it self.logger.size_request(self.pipeline) @@ -448,116 +454,6 @@ class App(): self.pipeline.cleanup() ############################################################ - # Workspace Commands # - ############################################################ - - # open_workspace - # - # Open a project workspace - this requires full initialization - # - # Args: - # target (Element): The element to open the workspace for - # directory (str): The directory to stage the source in - # no_checkout (bool): Whether to skip checking out the source - # track_first (bool): Whether to track and fetch first - # force (bool): Whether to ignore contents in an existing directory - # - def open_workspace(self, target, directory, no_checkout, track_first, force): - - workdir = os.path.abspath(directory) - - if not list(target.sources()): - build_depends = [x.name for x in target.dependencies(Scope.BUILD, recurse=False)] - if not build_depends: - raise AppError("The given element has no sources") - detail = "Try opening a workspace on one of its dependencies instead:\n" - detail += " \n".join(build_depends) - raise AppError("The given element has no sources", detail=detail) - - # Check for workspace config - if self.project.workspaces.get_workspace(target): - raise AppError("Workspace '{}' is already defined.".format(target.name)) - - # If we're going to checkout, we need at least a fetch, - # if we were asked to track first, we're going to fetch anyway. - if not no_checkout or track_first: - self.stream.fetch(self.scheduler, [target]) - - if not no_checkout and target._get_consistency() != Consistency.CACHED: - raise AppError("Could not stage uncached source. " + - "Use `--track` to track and " + - "fetch the latest version of the " + - "source.") - - try: - os.makedirs(directory, exist_ok=True) - except OSError as e: - raise AppError("Failed to create workspace directory: {}".format(e)) from e - - self.project.workspaces.create_workspace(target.name, workdir) - - if not no_checkout: - with target.timed_activity("Staging sources to {}".format(directory)): - target._open_workspace() - - self.project.workspaces.save_config() - self._message(MessageType.INFO, "Saved workspace configuration") - - # close_workspace - # - # Close a project workspace - this requires only partial initialization - # - # Args: - # element_name (str): The element name to close the workspace for - # remove_dir (bool): Whether to remove the associated directory - # - def close_workspace(self, element_name, remove_dir): - - workspace = self.project.workspaces.get_workspace(element_name) - - if workspace is None: - raise AppError("Workspace '{}' does not exist".format(element_name)) - - if self.interactive and remove_dir: - if not click.confirm('This will remove all your changes, are you sure?'): - click.echo('Aborting', err=True) - sys.exit(-1) - - # Remove workspace directory if prompted - if remove_dir: - with self.context.timed_activity("Removing workspace directory {}" - .format(workspace.path)): - try: - shutil.rmtree(workspace.path) - except OSError as e: - raise AppError("Could not remove '{}': {}" - .format(workspace.path, e)) from e - - # Delete the workspace and save the configuration - self.project.workspaces.delete_workspace(element_name) - self.project.workspaces.save_config() - self._message(MessageType.INFO, "Saved workspace configuration") - - # reset_workspace - # - # Reset a workspace to its original state, discarding any user - # changes. - # - # Args: - # target (Element): The element to reset the workspace for - # track (bool): Whether to also track the source - # - def reset_workspace(self, target, track): - workspace = self.project.workspaces.get_workspace(target.name) - - if workspace is None: - raise AppError("Workspace '{}' is currently not defined" - .format(target.name)) - - self.close_workspace(target.name, True) - self.open_workspace(target, workspace.path, False, track, False) - - ############################################################ # Local Functions # ############################################################ |