diff options
author | Jürg Billeter <j@bitron.ch> | 2019-06-20 10:06:46 +0200 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-06-25 09:08:17 +0000 |
commit | 4c50ba274e1fbd5b15ce316621e81ad8bdcabdbf (patch) | |
tree | e7f1030fa9d6a093a7ee5c069570c92b40f1c789 | |
parent | cb0331a256af8e90e80f6937995fd9acad8725e3 (diff) | |
download | buildstream-4c50ba274e1fbd5b15ce316621e81ad8bdcabdbf.tar.gz |
app.py: Create stream before loading project
This is in preparation for moving subproject fetching to the Stream
class. Project loading may require subproject fetching as part of
processing include directives.
-rw-r--r-- | src/buildstream/_frontend/app.py | 46 | ||||
-rw-r--r-- | src/buildstream/_stream.py | 19 |
2 files changed, 39 insertions, 26 deletions
diff --git a/src/buildstream/_frontend/app.py b/src/buildstream/_frontend/app.py index a9dd46b34..b55c743e2 100644 --- a/src/buildstream/_frontend/app.py +++ b/src/buildstream/_frontend/app.py @@ -216,33 +216,12 @@ class App(): except BstError as e: self._error_exit(e, "Error instantiating artifact cache") - # - # Load the Project - # - try: - self.project = Project(directory, self.context, cli_options=self._main_options['option'], - default_mirror=self._main_options.get('default_mirror')) - except LoadError as e: - - # Help users that are new to BuildStream by suggesting 'init'. - # We don't want to slow down users that just made a mistake, so - # don't stop them with an offer to create a project for them. - if e.reason == LoadErrorReason.MISSING_PROJECT_CONF: - click.echo("No project found. You can create a new project like so:", err=True) - click.echo("", err=True) - click.echo(" bst init", err=True) - - self._error_exit(e, "Error loading project") - - except BstError as e: - self._error_exit(e, "Error loading project") - # Now that we have a logger and message handler, # we can override the global exception hook. sys.excepthook = self._global_exception_handler # Create the stream right away, we'll need to pass it around - self.stream = Stream(self.context, self.project, self._session_start, + self.stream = Stream(self.context, self._session_start, session_start_callback=self.session_start_cb, interrupt_callback=self._interrupt_handler, ticker_callback=self._tick, @@ -259,6 +238,29 @@ class App(): if session_name: self._message(MessageType.START, session_name) + # + # Load the Project + # + try: + self.project = Project(directory, self.context, cli_options=self._main_options['option'], + default_mirror=self._main_options.get('default_mirror')) + + self.stream.set_project(self.project) + except LoadError as e: + + # Help users that are new to BuildStream by suggesting 'init'. + # We don't want to slow down users that just made a mistake, so + # don't stop them with an offer to create a project for them. + if e.reason == LoadErrorReason.MISSING_PROJECT_CONF: + click.echo("No project found. You can create a new project like so:", err=True) + click.echo("", err=True) + click.echo(" bst init", err=True) + + self._error_exit(e, "Error loading project") + + except BstError as e: + self._error_exit(e, "Error loading project") + # Run the body of the session here, once everything is loaded try: yield diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index c5e056280..c9e847319 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -49,7 +49,6 @@ from . import Scope, Consistency # # Args: # context (Context): The Context object -# project (Project): The Project object # session_start (datetime): The time when the session started # session_start_callback (callable): A callback to invoke when the session starts # interrupt_callback (callable): A callback to invoke when we get interrupted @@ -59,7 +58,7 @@ from . import Scope, Consistency # class Stream(): - def __init__(self, context, project, session_start, *, + def __init__(self, context, session_start, *, session_start_callback=None, interrupt_callback=None, ticker_callback=None, @@ -80,8 +79,8 @@ class Stream(): self._artifacts = context.artifactcache self._sourcecache = context.sourcecache self._context = context - self._project = project - self._pipeline = Pipeline(context, project, self._artifacts) + self._project = None + self._pipeline = None self._scheduler = Scheduler(context, session_start, interrupt_callback=interrupt_callback, ticker_callback=ticker_callback, @@ -98,6 +97,18 @@ class Stream(): if self._project: self._project.cleanup() + # set_project() + # + # Set the top-level project. + # + # Args: + # project (Project): The Project object + # + def set_project(self, project): + assert self._project is None + self._project = project + self._pipeline = Pipeline(self._context, project, self._artifacts) + # load_selection() # # An all purpose method for loading a selection of elements, this |