summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Singh <csingh43@bloomberg.net>2018-04-09 22:58:50 +0100
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2018-04-17 13:01:22 +0000
commit6c23e337abf702dbb34a56ca17cc7d09857a8ccc (patch)
treebe05c7364ce7be839e1e53607b86acfaa97c2d81
parent880e1913ee410e9b2fe3e704b288cf0b2de5e003 (diff)
downloadbuildstream-6c23e337abf702dbb34a56ca17cc7d09857a8ccc.tar.gz
refactor: Do not assume there is only one workspace target in app.py
While working with workspaces in _frontend/app.py, we currently assume that there is only workspace in the pippeline. This limits our ability to support multiple workspaces in a given command. Remove this assumption from _frontend/app.py which will allow for the possibility of supporting multiple workspaces from _frontend/cli.py in future. This commit does not change the behavior of these commands though as the target is instead passed as an argument.
-rw-r--r--buildstream/_frontend/app.py12
-rw-r--r--buildstream/_frontend/cli.py8
2 files changed, 11 insertions, 9 deletions
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index fe2c460c5..db9c97b84 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -432,15 +432,14 @@ class App():
# 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, directory, no_checkout, track_first, force):
+ def open_workspace(self, target, directory, no_checkout, track_first, force):
- # When working on workspaces we only have one target
- target = self.pipeline.targets[0]
workdir = os.path.abspath(directory)
if not list(target.sources()):
@@ -521,11 +520,10 @@ class App():
# changes.
#
# Args:
+ # target (Element): The element to reset the workspace for
# track (bool): Whether to also track the source
#
- def reset_workspace(self, track):
- # When working on workspaces we only have one target
- target = self.pipeline.targets[0]
+ def reset_workspace(self, target, track):
workspace = self.project.workspaces.get_workspace(target.name)
if workspace is None:
@@ -533,7 +531,7 @@ class App():
.format(target.name))
self.close_workspace(target.name, True)
- self.open_workspace(workspace.path, False, track, False)
+ self.open_workspace(target, workspace.path, False, track, False)
############################################################
# Local Functions #
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 9720bc44e..628a6cc85 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -624,7 +624,9 @@ def workspace_open(app, no_checkout, force, track_, element, directory):
sys.exit(-1)
with app.initialized((element,), rewritable=track_, track_elements=[element] if track_ else None):
- app.open_workspace(directory, no_checkout, track_, force)
+ # This command supports only one target
+ target = app.pipeline.targets[0]
+ app.open_workspace(target, directory, no_checkout, track_, force)
##################################################################
@@ -669,7 +671,9 @@ def workspace_reset(app, track_, element):
sys.exit(-1)
with app.initialized((element,)):
- app.reset_workspace(track_)
+ # This command supports only one target
+ target = app.pipeline.targets[0]
+ app.reset_workspace(target, track_)
##################################################################