summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Singh <csingh43@bloomberg.net>2018-05-07 23:11:33 +0100
committerChandan Singh <csingh43@bloomberg.net>2018-05-07 23:11:33 +0100
commit98442bcd3482792c8d2418a4e73e59c4599438a7 (patch)
tree47bd517819916c762904316d49794133099c133b
parentf8952d6b8a775026d8a566969dd2570badf838fe (diff)
downloadbuildstream-chandan/workspace-soft-reset.tar.gz
Add soft reset functionality for workspaceschandan/workspace-soft-reset
Add `--soft` option to `bst workspace reset` which would allow uses to reset workspace-related state without affecting its contents. This will be useful in case when an user wants to re-run configure-commands for a workspaced element. Fixes #375.
-rw-r--r--buildstream/_frontend/app.py9
-rw-r--r--buildstream/_frontend/cli.py8
2 files changed, 13 insertions, 4 deletions
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index 3bcb0d962..4c98a2c05 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -540,15 +540,22 @@ class App():
#
# Args:
# target (Element): The element to reset the workspace for
+ # soft (bool): Only reset workspace state
# track (bool): Whether to also track the source
#
- def reset_workspace(self, target, track):
+ def reset_workspace(self, target, soft, track):
workspace = self.project.workspaces.get_workspace(target.name)
if workspace is None:
raise AppError("Workspace '{}' is currently not defined"
.format(target.name))
+ if soft:
+ workspace.prepared = False
+ self.project.workspaces.save_config()
+ self._message(MessageType.INFO, "Saved workspace configuration")
+ return
+
self.close_workspace(target.name, True)
self.open_workspace(target, workspace.path, False, track, False)
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 5f9e2751e..31f9199ee 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -667,6 +667,8 @@ def workspace_close(app, remove_dir, all_, elements):
# Workspace Reset Command #
##################################################################
@workspace.command(name='reset', short_help="Reset a workspace to its original state")
+@click.option('--soft', default=False, is_flag=True,
+ help="Reset workspace state without affecting its contents")
@click.option('--track', 'track_', default=False, is_flag=True,
help="Track and fetch the latest source before resetting")
@click.option('--all', '-a', 'all_', default=False, is_flag=True,
@@ -674,14 +676,14 @@ def workspace_close(app, remove_dir, all_, elements):
@click.argument('elements', nargs=-1,
type=click.Path(dir_okay=False, readable=True))
@click.pass_obj
-def workspace_reset(app, track_, all_, elements):
+def workspace_reset(app, soft, track_, all_, elements):
"""Reset a workspace to its original state"""
if not (all_ or elements):
click.echo('ERROR: no elements specified', err=True)
sys.exit(-1)
- if app.interactive:
+ if app.interactive and not soft:
if not click.confirm('This will remove all your changes, are you sure?'):
click.echo('Aborting', err=True)
sys.exit(-1)
@@ -692,7 +694,7 @@ def workspace_reset(app, track_, all_, elements):
with app.initialized(elements):
for target in app.pipeline.targets:
- app.reset_workspace(target, track_)
+ app.reset_workspace(target, soft, track_)
##################################################################