build shell on an element should fail right reason when "fetch needed"
Summary
I cloned the the repo recently (d34a4fd1) and was playing with examples. Starting from an absolutely clean state, launching a bst shell -b
on an element with non-yet-fetched sources fails, but for the wrong reason.
Steps to reproduce
$ cd /buildstream/doc/examples/autotools
$ bst show base/alpine.bst
[--:--:--][][] START Loading elements
[00:00:00][][] SUCCESS Loading elements
[--:--:--][][] START Resolving elements
[00:00:00][][] SUCCESS Resolving elements
[--:--:--][][] START Resolving cached state
[00:00:00][][] SUCCESS Resolving cached state
fetch needed fc05961cf6dfded6a2818cdbc603ff91e72e18d518a6315a19b106d85f1a42e3 base/alpine.bst
$ bst shell -b base/alpine.bst
# fails expectedly but with a not-really-expected reason:
[--:--:--][][] START Loading elements
[00:00:00][][] SUCCESS Loading elements
[--:--:--][][] START Resolving elements
[00:00:00][][] SUCCESS Resolving elements
[--:--:--][][] START Resolving cached state
[00:00:00][][] SUCCESS Resolving cached state
[--:--:--][fc05961c][ main:base/alpine.bst ] STATUS Running command
sh -i
Error launching shell: Staged artifacts do not provide command 'sh'
It might sound weird to try to open a build shell on an import element. Probably something worth raising as topic to discuss. Not to sidetrack, let's change that file to kind: make
(I named it test.bst
):
$ bst shell -b test.bst
[--:--:--][][] START Loading elements
[00:00:00][][] SUCCESS Loading elements
[--:--:--][][] START Resolving elements
[00:00:00][][] SUCCESS Resolving elements
[--:--:--][][] START Resolving cached state
[00:00:00][][] SUCCESS Resolving cached state
[--:--:--][20a9f559][ main:test.bst ] START Staging dependencies
[00:00:00][20a9f559][ main:test.bst ] SUCCESS Staging dependencies
[--:--:--][20a9f559][ main:test.bst ] START Integrating sandbox
[00:00:00][20a9f559][ main:test.bst ] SUCCESS Integrating sandbox
[--:--:--][20a9f559][ main:test.bst ] START Staging sources
[00:00:00][20a9f559][ main:test.bst ] FAILURE Staging sources
Error launching shell: tar source at test.bst [line 7 column 2]: Error staging source: [Errno 2] No such file or directory: '/root/.cache/buildstream/sources/tar/alpine_integration_tests_base_v1_x86_64_tar_xz/3eb559250ba82b64a68d86d0636a6b127aa5f6d25d3601a79f79214dc9703639'
This error is a bit better, but it shouldn't even have reached to Staging sources
stage when fetch was needed.
What is the current bug behavior?
See above.
What is the expected correct behavior?
BuildStream complaining about fetch-needed
.
Possible fixes
I think it should terminate with the right suggestion. Ideally as early as possible, even before checking the state of dependencies.
Possibly, right here: https://gitlab.com/BuildStream/buildstream/blob/ce91ce5d2eb73295d1862aa8514e631b6231300e/buildstream/_stream.py#L143
def shell(self, element, scope, prompt, *,
directory=None,
mounts=None,
isolate=False,
command=None,
usebuildtree=False):
# Assert we have everything we need built, unless the directory is specified
# in which case we just blindly trust the directory, using the element
# definitions to control the execution environment only.
if directory is None:
+ if scope == Scope.BUILD:
+ self._pipeline.assert_sources_cached([element])
+
missing_deps = [
dep._get_full_name()
for dep in self._pipeline.dependencies([element], scope)
if not dep._cached()
]
if missing_deps:
raise StreamError("Elements need to be built or downloaded before staging a shell environment",
detail="\n".join(missing_deps))
return element._shell(scope, directory, mounts=mounts, isolate=isolate, prompt=prompt, command=command,
usebuildtree=usebuildtree)
Other relevant information
- BuildStream version affected: 1.3.0+1291.gd34a4fd1 (and probably goes earlier)