Angelos Evripiotis pushed to branch aevri/are_you_sure at BuildStream / buildstream
Commits:
-
a3e2cdd2
by Tom Pollard at 2019-01-28T12:14:40Z
-
805baf7d
by Tom Pollard at 2019-01-28T12:14:40Z
-
38356932
by Tom Pollard at 2019-01-28T13:44:37Z
-
199d01c2
by Angelos Evripiotis at 2019-01-28T16:06:26Z
6 changed files:
- NEWS
- buildstream/_context.py
- buildstream/_frontend/cli.py
- buildstream/_stream.py
- buildstream/data/userconfig.yaml
- tests/integration/build-tree.py
Changes:
... | ... | @@ -50,6 +50,11 @@ buildstream 1.3.1 |
50 | 50 |
an error message and a hint instead, to avoid bothering folks that just
|
51 | 51 |
made a mistake.
|
52 | 52 |
|
53 |
+ o BREAKING CHANGE: The unconditional 'Are you sure?' prompts have been
|
|
54 |
+ removed. These would always ask you if you were sure when running
|
|
55 |
+ 'bst workspace close --remove-dir' or 'bst workspace reset'. They got in
|
|
56 |
+ the way too often.
|
|
57 |
+ |
|
53 | 58 |
o Failed builds are included in the cache as well.
|
54 | 59 |
`bst checkout` will provide anything in `%{install-root}`.
|
55 | 60 |
A build including cached fails will cause any dependant elements
|
... | ... | @@ -87,12 +92,6 @@ buildstream 1.3.1 |
87 | 92 |
instead of just a specially-formatted build-root with a `root` and `scratch`
|
88 | 93 |
subdirectory.
|
89 | 94 |
|
90 |
- o The buildstream.conf file learned new
|
|
91 |
- 'prompt.really-workspace-close-remove-dir' and
|
|
92 |
- 'prompt.really-workspace-reset-hard' options. These allow users to suppress
|
|
93 |
- certain confirmation prompts, e.g. double-checking that the user meant to
|
|
94 |
- run the command as typed.
|
|
95 |
- |
|
96 | 95 |
o Due to the element `build tree` being cached in the respective artifact their
|
97 | 96 |
size in some cases has significantly increased. In *most* cases the build trees
|
98 | 97 |
are not utilised when building targets, as such by default bst 'pull' & 'build'
|
... | ... | @@ -121,18 +121,10 @@ class Context(): |
121 | 121 |
# Whether or not to attempt to pull build trees globally
|
122 | 122 |
self.pull_buildtrees = None
|
123 | 123 |
|
124 |
- # Boolean, whether we double-check with the user that they meant to
|
|
125 |
- # remove a workspace directory.
|
|
126 |
- self.prompt_workspace_close_remove_dir = None
|
|
127 |
- |
|
128 | 124 |
# Boolean, whether we double-check with the user that they meant to
|
129 | 125 |
# close the workspace when they're using it to access the project.
|
130 | 126 |
self.prompt_workspace_close_project_inaccessible = None
|
131 | 127 |
|
132 |
- # Boolean, whether we double-check with the user that they meant to do
|
|
133 |
- # a hard reset of a workspace, potentially losing changes.
|
|
134 |
- self.prompt_workspace_reset_hard = None
|
|
135 |
- |
|
136 | 128 |
# Whether elements must be rebuilt when their dependencies have changed
|
137 | 129 |
self._strict_build_plan = None
|
138 | 130 |
|
... | ... | @@ -260,16 +252,10 @@ class Context(): |
260 | 252 |
prompt = _yaml.node_get(
|
261 | 253 |
defaults, Mapping, 'prompt')
|
262 | 254 |
_yaml.node_validate(prompt, [
|
263 |
- 'really-workspace-close-remove-dir',
|
|
264 | 255 |
'really-workspace-close-project-inaccessible',
|
265 |
- 'really-workspace-reset-hard',
|
|
266 | 256 |
])
|
267 |
- self.prompt_workspace_close_remove_dir = _node_get_option_str(
|
|
268 |
- prompt, 'really-workspace-close-remove-dir', ['ask', 'yes']) == 'ask'
|
|
269 | 257 |
self.prompt_workspace_close_project_inaccessible = _node_get_option_str(
|
270 | 258 |
prompt, 'really-workspace-close-project-inaccessible', ['ask', 'yes']) == 'ask'
|
271 |
- self.prompt_workspace_reset_hard = _node_get_option_str(
|
|
272 |
- prompt, 'really-workspace-reset-hard', ['ask', 'yes']) == 'ask'
|
|
273 | 259 |
|
274 | 260 |
# Load per-projects overrides
|
275 | 261 |
self._project_overrides = _yaml.node_get(defaults, Mapping, 'projects', default_value={})
|
... | ... | @@ -526,7 +526,7 @@ def shell(app, element, sysroot, mount, isolate, build_, cli_buildtree, command) |
526 | 526 |
else:
|
527 | 527 |
scope = Scope.RUN
|
528 | 528 |
|
529 |
- use_buildtree = False
|
|
529 |
+ use_buildtree = None
|
|
530 | 530 |
|
531 | 531 |
with app.initialized():
|
532 | 532 |
if not element:
|
... | ... | @@ -534,7 +534,8 @@ def shell(app, element, sysroot, mount, isolate, build_, cli_buildtree, command) |
534 | 534 |
if not element:
|
535 | 535 |
raise AppError('Missing argument "ELEMENT".')
|
536 | 536 |
|
537 |
- dependencies = app.stream.load_selection((element,), selection=PipelineSelection.NONE)
|
|
537 |
+ dependencies = app.stream.load_selection((element,), selection=PipelineSelection.NONE,
|
|
538 |
+ use_artifact_config=True)
|
|
538 | 539 |
element = dependencies[0]
|
539 | 540 |
prompt = app.shell_prompt(element)
|
540 | 541 |
mounts = [
|
... | ... | @@ -543,20 +544,31 @@ def shell(app, element, sysroot, mount, isolate, build_, cli_buildtree, command) |
543 | 544 |
]
|
544 | 545 |
|
545 | 546 |
cached = element._cached_buildtree()
|
546 |
- if cli_buildtree == "always":
|
|
547 |
- if cached:
|
|
548 |
- use_buildtree = True
|
|
549 |
- else:
|
|
550 |
- raise AppError("No buildtree is cached but the use buildtree option was specified")
|
|
551 |
- elif cli_buildtree == "never":
|
|
552 |
- pass
|
|
553 |
- elif cli_buildtree == "try":
|
|
554 |
- use_buildtree = cached
|
|
547 |
+ if cli_buildtree in ("always", "try"):
|
|
548 |
+ use_buildtree = cli_buildtree
|
|
549 |
+ if not cached and use_buildtree == "always":
|
|
550 |
+ click.echo("WARNING: buildtree is not cached locally, will attempt to pull from available remotes",
|
|
551 |
+ err=True)
|
|
555 | 552 |
else:
|
556 |
- if app.interactive and cached:
|
|
557 |
- use_buildtree = bool(click.confirm('Do you want to use the cached buildtree?'))
|
|
553 |
+ # If the value has defaulted to ask and in non interactive mode, don't consider the buildtree, this
|
|
554 |
+ # being the default behaviour of the command
|
|
555 |
+ if app.interactive and cli_buildtree == "ask":
|
|
556 |
+ if cached and bool(click.confirm('Do you want to use the cached buildtree?')):
|
|
557 |
+ use_buildtree = "always"
|
|
558 |
+ elif not cached:
|
|
559 |
+ try:
|
|
560 |
+ choice = click.prompt("Do you want to pull & use a cached buildtree?",
|
|
561 |
+ type=click.Choice(['try', 'always', 'never']),
|
|
562 |
+ err=True, show_choices=True)
|
|
563 |
+ except click.Abort:
|
|
564 |
+ click.echo('Aborting', err=True)
|
|
565 |
+ sys.exit(-1)
|
|
566 |
+ |
|
567 |
+ if choice != "never":
|
|
568 |
+ use_buildtree = choice
|
|
569 |
+ |
|
558 | 570 |
if use_buildtree and not element._cached_success():
|
559 |
- click.echo("Warning: using a buildtree from a failed build.")
|
|
571 |
+ click.echo("WARNING: using a buildtree from a failed build.", err=True)
|
|
560 | 572 |
|
561 | 573 |
try:
|
562 | 574 |
exitcode = app.stream.shell(element, scope, prompt,
|
... | ... | @@ -829,11 +841,6 @@ def workspace_close(app, remove_dir, all_, elements): |
829 | 841 |
if nonexisting:
|
830 | 842 |
raise AppError("Workspace does not exist", detail="\n".join(nonexisting))
|
831 | 843 |
|
832 |
- if app.interactive and remove_dir and app.context.prompt_workspace_close_remove_dir:
|
|
833 |
- if not click.confirm('This will remove all your changes, are you sure?'):
|
|
834 |
- click.echo('Aborting', err=True)
|
|
835 |
- sys.exit(-1)
|
|
836 |
- |
|
837 | 844 |
for element_name in elements:
|
838 | 845 |
app.stream.workspace_close(element_name, remove_dir=remove_dir)
|
839 | 846 |
|
... | ... | @@ -867,11 +874,6 @@ def workspace_reset(app, soft, track_, all_, elements): |
867 | 874 |
if all_ and not app.stream.workspace_exists():
|
868 | 875 |
raise AppError("No open workspaces to reset")
|
869 | 876 |
|
870 |
- if app.interactive and not soft and app.context.prompt_workspace_reset_hard:
|
|
871 |
- if not click.confirm('This will remove all your changes, are you sure?'):
|
|
872 |
- click.echo('Aborting', err=True)
|
|
873 |
- sys.exit(-1)
|
|
874 |
- |
|
875 | 877 |
if all_:
|
876 | 878 |
elements = tuple(element_name for element_name, _ in app.context.get_workspaces().list())
|
877 | 879 |
|
... | ... | @@ -101,19 +101,22 @@ class Stream(): |
101 | 101 |
# targets (list of str): Targets to pull
|
102 | 102 |
# selection (PipelineSelection): The selection mode for the specified targets
|
103 | 103 |
# except_targets (list of str): Specified targets to except from fetching
|
104 |
+ # use_artifact_config (bool): If artifact remote config should be loaded
|
|
104 | 105 |
#
|
105 | 106 |
# Returns:
|
106 | 107 |
# (list of Element): The selected elements
|
107 | 108 |
def load_selection(self, targets, *,
|
108 | 109 |
selection=PipelineSelection.NONE,
|
109 |
- except_targets=()):
|
|
110 |
+ except_targets=(),
|
|
111 |
+ use_artifact_config=False):
|
|
110 | 112 |
|
111 | 113 |
profile_start(Topics.LOAD_SELECTION, "_".join(t.replace(os.sep, '-') for t in targets))
|
112 | 114 |
|
113 | 115 |
elements, _ = self._load(targets, (),
|
114 | 116 |
selection=selection,
|
115 | 117 |
except_targets=except_targets,
|
116 |
- fetch_subprojects=False)
|
|
118 |
+ fetch_subprojects=False,
|
|
119 |
+ use_artifact_config=use_artifact_config)
|
|
117 | 120 |
|
118 | 121 |
profile_end(Topics.LOAD_SELECTION, "_".join(t.replace(os.sep, '-') for t in targets))
|
119 | 122 |
|
... | ... | @@ -131,7 +134,7 @@ class Stream(): |
131 | 134 |
# mounts (list of HostMount): Additional directories to mount into the sandbox
|
132 | 135 |
# isolate (bool): Whether to isolate the environment like we do in builds
|
133 | 136 |
# command (list): An argv to launch in the sandbox, or None
|
134 |
- # usebuildtree (bool): Wheather to use a buildtree as the source.
|
|
137 |
+ # usebuildtree (str): Whether to use a buildtree as the source, given cli option
|
|
135 | 138 |
#
|
136 | 139 |
# Returns:
|
137 | 140 |
# (int): The exit code of the launched shell
|
... | ... | @@ -141,7 +144,7 @@ class Stream(): |
141 | 144 |
mounts=None,
|
142 | 145 |
isolate=False,
|
143 | 146 |
command=None,
|
144 |
- usebuildtree=False):
|
|
147 |
+ usebuildtree=None):
|
|
145 | 148 |
|
146 | 149 |
# Assert we have everything we need built, unless the directory is specified
|
147 | 150 |
# in which case we just blindly trust the directory, using the element
|
... | ... | @@ -156,8 +159,31 @@ class Stream(): |
156 | 159 |
raise StreamError("Elements need to be built or downloaded before staging a shell environment",
|
157 | 160 |
detail="\n".join(missing_deps))
|
158 | 161 |
|
162 |
+ buildtree = False
|
|
163 |
+ # Check if we require a pull queue attempt, with given artifact state and context
|
|
164 |
+ if usebuildtree:
|
|
165 |
+ if not element._cached_buildtree():
|
|
166 |
+ require_buildtree = self._buildtree_pull_required([element])
|
|
167 |
+ # Attempt a pull queue for the given element if remote and context allow it
|
|
168 |
+ if require_buildtree:
|
|
169 |
+ self._message(MessageType.INFO, "Attempting to fetch missing artifact buildtree")
|
|
170 |
+ self._add_queue(PullQueue(self._scheduler))
|
|
171 |
+ self._enqueue_plan(require_buildtree)
|
|
172 |
+ self._run()
|
|
173 |
+ # Now check if the buildtree was successfully fetched
|
|
174 |
+ if element._cached_buildtree():
|
|
175 |
+ buildtree = True
|
|
176 |
+ if not buildtree:
|
|
177 |
+ if usebuildtree == "always":
|
|
178 |
+ raise StreamError("Buildtree is not cached locally or in available remotes")
|
|
179 |
+ else:
|
|
180 |
+ self._message(MessageType.INFO, """Buildtree is not cached locally or in available remotes,
|
|
181 |
+ shell will be loaded without it""")
|
|
182 |
+ else:
|
|
183 |
+ buildtree = True
|
|
184 |
+ |
|
159 | 185 |
return element._shell(scope, directory, mounts=mounts, isolate=isolate, prompt=prompt, command=command,
|
160 |
- usebuildtree=usebuildtree)
|
|
186 |
+ usebuildtree=buildtree)
|
|
161 | 187 |
|
162 | 188 |
# build()
|
163 | 189 |
#
|
... | ... | @@ -112,14 +112,6 @@ logging: |
112 | 112 |
#
|
113 | 113 |
prompt:
|
114 | 114 |
|
115 |
- # Whether to really proceed with 'bst workspace close --remove-dir' removing
|
|
116 |
- # a workspace directory, potentially losing changes.
|
|
117 |
- #
|
|
118 |
- # ask - Ask the user if they are sure.
|
|
119 |
- # yes - Always remove, without asking.
|
|
120 |
- #
|
|
121 |
- really-workspace-close-remove-dir: ask
|
|
122 |
- |
|
123 | 115 |
# Whether to really proceed with 'bst workspace close' when doing so would
|
124 | 116 |
# stop them from running bst commands in this workspace.
|
125 | 117 |
#
|
... | ... | @@ -127,11 +119,3 @@ prompt: |
127 | 119 |
# yes - Always close, without asking.
|
128 | 120 |
#
|
129 | 121 |
really-workspace-close-project-inaccessible: ask
|
130 |
- |
|
131 |
- # Whether to really proceed with 'bst workspace reset' doing a hard reset of
|
|
132 |
- # a workspace, potentially losing changes.
|
|
133 |
- #
|
|
134 |
- # ask - Ask the user if they are sure.
|
|
135 |
- # yes - Always hard reset, without asking.
|
|
136 |
- #
|
|
137 |
- really-workspace-reset-hard: ask
|
... | ... | @@ -101,7 +101,7 @@ def test_buildtree_from_failure(cli_integration, tmpdir, datafiles): |
101 | 101 |
'shell', '--build', element_name, '--use-buildtree', 'always', '--', 'cat', 'test'
|
102 | 102 |
])
|
103 | 103 |
res.assert_success()
|
104 |
- assert "Warning: using a buildtree from a failed build" in res.output
|
|
104 |
+ assert "WARNING: using a buildtree from a failed build" in res.stderr
|
|
105 | 105 |
assert 'Hi' in res.output
|
106 | 106 |
|
107 | 107 |
|
... | ... | @@ -141,7 +141,7 @@ def test_buildtree_pulled(cli, tmpdir, datafiles): |
141 | 141 |
res.assert_success()
|
142 | 142 |
|
143 | 143 |
|
144 |
-# This test checks for correct behaviour if a buildtree is not present.
|
|
144 |
+# This test checks for correct behaviour if a buildtree is not present in the local cache.
|
|
145 | 145 |
@pytest.mark.datafiles(DATA_DIR)
|
146 | 146 |
@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
|
147 | 147 |
def test_buildtree_options(cli, tmpdir, datafiles):
|
... | ... | @@ -156,6 +156,7 @@ def test_buildtree_options(cli, tmpdir, datafiles): |
156 | 156 |
result = cli.run(project=project, args=['build', element_name])
|
157 | 157 |
result.assert_success()
|
158 | 158 |
assert cli.get_element_state(project, element_name) == 'cached'
|
159 |
+ assert share.has_artifact('test', element_name, cli.get_element_key(project, element_name))
|
|
159 | 160 |
|
160 | 161 |
# Discard the cache
|
161 | 162 |
cli.configure({
|
... | ... | @@ -168,8 +169,6 @@ def test_buildtree_options(cli, tmpdir, datafiles): |
168 | 169 |
result = cli.run(project=project, args=['artifact', 'pull', '--deps', 'all', element_name])
|
169 | 170 |
result.assert_success()
|
170 | 171 |
|
171 |
- # The above is the simplest way I know to create a local cache without any buildtrees.
|
|
172 |
- |
|
173 | 172 |
# Check it's not using the cached build tree
|
174 | 173 |
res = cli.run(project=project, args=[
|
175 | 174 |
'shell', '--build', element_name, '--use-buildtree', 'never', '--', 'cat', 'test'
|
... | ... | @@ -177,24 +176,51 @@ def test_buildtree_options(cli, tmpdir, datafiles): |
177 | 176 |
res.assert_shell_error()
|
178 | 177 |
assert 'Hi' not in res.output
|
179 | 178 |
|
180 |
- # Check it's not correctly handling the lack of buildtree
|
|
179 |
+ # Check it's not using the cached build tree, default is to ask, and fall back to not
|
|
180 |
+ # for non interactive behavior
|
|
181 | 181 |
res = cli.run(project=project, args=[
|
182 |
- 'shell', '--build', element_name, '--use-buildtree', 'try', '--', 'cat', 'test'
|
|
182 |
+ 'shell', '--build', element_name, '--', 'cat', 'test'
|
|
183 | 183 |
])
|
184 | 184 |
res.assert_shell_error()
|
185 | 185 |
assert 'Hi' not in res.output
|
186 | 186 |
|
187 |
- # Check it's not using the cached build tree, default is to ask, and fall back to not
|
|
188 |
- # for non interactive behavior
|
|
187 |
+ # Check correctly handling the lack of buildtree, with 'try' not attempting to
|
|
188 |
+ # pull the buildtree as the user context is by default set to not pull them
|
|
189 | 189 |
res = cli.run(project=project, args=[
|
190 |
- 'shell', '--build', element_name, '--', 'cat', 'test'
|
|
190 |
+ 'shell', '--build', element_name, '--use-buildtree', 'try', '--', 'cat', 'test'
|
|
191 | 191 |
])
|
192 |
- res.assert_shell_error()
|
|
193 | 192 |
assert 'Hi' not in res.output
|
193 |
+ assert 'Attempting to fetch missing artifact buildtrees' not in res.stderr
|
|
194 |
+ assert """Buildtree is not cached locally or in available remotes,
|
|
195 |
+ shell will be loaded without it"""
|
|
194 | 196 |
|
195 |
- # Check it's using the cached build tree
|
|
197 |
+ # Check correctly handling the lack of buildtree, with 'try' attempting and succeeding
|
|
198 |
+ # to pull the buildtree as the user context allow the pulling of buildtrees and it is
|
|
199 |
+ # available in the remote
|
|
200 |
+ res = cli.run(project=project, args=[
|
|
201 |
+ '--pull-buildtrees', 'shell', '--build', element_name, '--use-buildtree', 'try', '--', 'cat', 'test'
|
|
202 |
+ ])
|
|
203 |
+ assert 'Attempting to fetch missing artifact buildtree' in res.stderr
|
|
204 |
+ assert 'Hi' in res.output
|
|
205 |
+ shutil.rmtree(os.path.join(os.path.join(cli.directory, 'artifacts2')))
|
|
206 |
+ assert cli.get_element_state(project, element_name) != 'cached'
|
|
207 |
+ |
|
208 |
+ # Check it's not loading the shell at all with always set for the buildtree, when the
|
|
209 |
+ # user context does not allow for buildtree pulling
|
|
210 |
+ result = cli.run(project=project, args=['artifact', 'pull', '--deps', 'all', element_name])
|
|
211 |
+ result.assert_success()
|
|
196 | 212 |
res = cli.run(project=project, args=[
|
197 | 213 |
'shell', '--build', element_name, '--use-buildtree', 'always', '--', 'cat', 'test'
|
198 | 214 |
])
|
199 | 215 |
res.assert_main_error(ErrorDomain.PROG_NOT_FOUND, None)
|
216 |
+ assert 'Buildtree is not cached locally or in available remotes' in res.stderr
|
|
200 | 217 |
assert 'Hi' not in res.output
|
218 |
+ assert 'Attempting to fetch missing artifact buildtree' not in res.stderr
|
|
219 |
+ |
|
220 |
+ # Check that when user context is set to pull buildtrees and a remote has the buildtree,
|
|
221 |
+ # 'always' will attempt and succeed at pulling the missing buildtree.
|
|
222 |
+ res = cli.run(project=project, args=[
|
|
223 |
+ '--pull-buildtrees', 'shell', '--build', element_name, '--use-buildtree', 'always', '--', 'cat', 'test'
|
|
224 |
+ ])
|
|
225 |
+ assert 'Hi' in res.output
|
|
226 |
+ assert 'Attempting to fetch missing artifact buildtree' in res.stderr
|