diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-05-10 21:20:06 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-05-10 21:20:06 +0900 |
commit | edf3e029976ba0c605f5ff41bbb5568868c8f699 (patch) | |
tree | 8f64f250fb83e71f2cd9e4756ece64d8aa45e217 | |
parent | 8985da07604674749eecbafba0d8c716b133d27d (diff) | |
download | buildstream-edf3e029976ba0c605f5ff41bbb5568868c8f699.tar.gz |
Add soft reset functionality for workspaces
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.
Patch originally by Chandan Singh, rebased against recent refactor.
Fixes #375.
-rw-r--r-- | buildstream/_frontend/cli.py | 8 | ||||
-rw-r--r-- | buildstream/_stream.py | 9 |
2 files changed, 13 insertions, 4 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py index 41736ac2f..230c8427a 100644 --- a/buildstream/_frontend/cli.py +++ b/buildstream/_frontend/cli.py @@ -651,6 +651,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, @@ -658,7 +660,7 @@ 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""" # Check that the workspaces in question exist @@ -677,7 +679,7 @@ def workspace_reset(app, track_, all_, elements): if nonexisting: raise AppError("Workspace does not exist", detail="\n".join(nonexisting)) - 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) @@ -685,7 +687,7 @@ def workspace_reset(app, track_, all_, elements): if all_: elements = tuple(element_name for element_name, _ in app.project.workspaces.list()) - app.stream.workspace_reset(elements, track_first=track_) + app.stream.workspace_reset(elements, soft=soft, track_first=track_) ################################################################## diff --git a/buildstream/_stream.py b/buildstream/_stream.py index c8d0bb69c..a5eacacf0 100644 --- a/buildstream/_stream.py +++ b/buildstream/_stream.py @@ -504,9 +504,10 @@ class Stream(): # # Args: # targets (list of str): The target elements to reset the workspace for + # soft (bool): Only reset workspace state # track_first (bool): Whether to also track the sources first # - def workspace_reset(self, targets, *, track_first): + def workspace_reset(self, targets, *, soft, track_first): if track_first: track_targets = targets @@ -522,6 +523,12 @@ class Stream(): for element in elements: workspace = self._project.workspaces.get_workspace(element.name) + if soft: + workspace.prepared = False + self._message(MessageType.INFO, "Reset workspace state for {} at: {}" + .format(element.name, workspace.path)) + continue + with element.timed_activity("Removing workspace directory {}" .format(workspace.path)): try: |