Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/buildstream/_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ def cache(
for key, value in sorted(sandbox_env.items()):
artifact.buildsandbox.environment.add(name=key, value=value)

for directory in buildsandbox._get_marked_directories():
artifact.buildsandbox.marked_directories.append(directory)

artifact.buildsandbox.working_directory = buildsandbox._get_work_directory()

for subsandbox in buildsandbox._get_subsandboxes():
Expand Down Expand Up @@ -699,7 +702,7 @@ def pull(self, *, pull_buildtrees):
def configure_sandbox(self, sandbox):
artifact = self._get_proto()

if artifact.buildsandbox and artifact.buildsandbox.environment:
if artifact.HasField("buildsandbox") and artifact.buildsandbox.environment:
env = {}
for env_var in artifact.buildsandbox.environment:
env[env_var.name] = env_var.value
Expand All @@ -708,8 +711,12 @@ def configure_sandbox(self, sandbox):

sandbox.set_environment(env)

if artifact.buildsandbox and artifact.buildsandbox.working_directory:
sandbox.set_work_directory(artifact.buildsandbox.working_directory)
if artifact.HasField("buildsandbox"):
for directory in artifact.buildsandbox.marked_directories:
sandbox.mark_directory(directory)

if artifact.buildsandbox.working_directory:
sandbox.set_work_directory(artifact.buildsandbox.working_directory)

# load_proto()
#
Expand Down
1 change: 1 addition & 0 deletions src/buildstream/_protos/buildstream/v2/artifact.proto
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ message Artifact {
repeated build.bazel.remote.execution.v2.Command.EnvironmentVariable environment = 1;
string working_directory = 2;
repeated build.bazel.remote.execution.v2.Digest subsandbox_digests = 3;
repeated string marked_directories = 4;
};
SandboxState buildsandbox = 18; // optional
}
6 changes: 3 additions & 3 deletions src/buildstream/_protos/buildstream/v2/artifact_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/buildstream/_protos/buildstream/v2/artifact_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ class Artifact(_message.Message):
digest: _remote_execution_pb2.Digest
def __init__(self, name: _Optional[str] = ..., digest: _Optional[_Union[_remote_execution_pb2.Digest, _Mapping]] = ...) -> None: ...
class SandboxState(_message.Message):
__slots__ = ("environment", "working_directory", "subsandbox_digests")
__slots__ = ("environment", "working_directory", "subsandbox_digests", "marked_directories")
ENVIRONMENT_FIELD_NUMBER: _ClassVar[int]
WORKING_DIRECTORY_FIELD_NUMBER: _ClassVar[int]
SUBSANDBOX_DIGESTS_FIELD_NUMBER: _ClassVar[int]
MARKED_DIRECTORIES_FIELD_NUMBER: _ClassVar[int]
environment: _containers.RepeatedCompositeFieldContainer[_remote_execution_pb2.Command.EnvironmentVariable]
working_directory: str
subsandbox_digests: _containers.RepeatedCompositeFieldContainer[_remote_execution_pb2.Digest]
def __init__(self, environment: _Optional[_Iterable[_Union[_remote_execution_pb2.Command.EnvironmentVariable, _Mapping]]] = ..., working_directory: _Optional[str] = ..., subsandbox_digests: _Optional[_Iterable[_Union[_remote_execution_pb2.Digest, _Mapping]]] = ...) -> None: ...
marked_directories: _containers.RepeatedScalarFieldContainer[str]
def __init__(self, environment: _Optional[_Iterable[_Union[_remote_execution_pb2.Command.EnvironmentVariable, _Mapping]]] = ..., working_directory: _Optional[str] = ..., subsandbox_digests: _Optional[_Iterable[_Union[_remote_execution_pb2.Digest, _Mapping]]] = ..., marked_directories: _Optional[_Iterable[str]] = ...) -> None: ...
VERSION_FIELD_NUMBER: _ClassVar[int]
BUILD_SUCCESS_FIELD_NUMBER: _ClassVar[int]
BUILD_ERROR_FIELD_NUMBER: _ClassVar[int]
Expand Down
33 changes: 31 additions & 2 deletions tests/integration/shellbuildtrees.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,21 @@ def test_shell_pull_cached_buildtree(share_with_buildtrees, datafiles, cli, pull
result.assert_success()
assert "Hi" in result.output

# Check that the working directory is writable
result = cli.run(
project=project,
args=[
"shell",
"--build",
element_name,
"--use-buildtree",
"--",
"touch",
"foo",
],
)
result.assert_success()


#
# Test behavior of shelling into a buildtree by its artifact name
Expand All @@ -362,8 +377,7 @@ def test_shell_pull_artifact_cached_buildtree(share_with_buildtrees, datafiles,
artifact_name,
"--",
"cat",
# We don't preserve the working directory in artifacts, so we will be executing at /
"/buildstream/test/build-shell/buildtree.bst/test",
"test",
],
)

Expand All @@ -373,6 +387,21 @@ def test_shell_pull_artifact_cached_buildtree(share_with_buildtrees, datafiles,
result.assert_success()
assert "Hi" in result.output

# Check that the working directory is writable
result = cli.run(
project=project,
args=[
"shell",
"--build",
"--use-buildtree",
artifact_name,
"--",
"touch",
"foo",
],
)
result.assert_success()


#
# Test behavior of launching a shell and requesting to use a buildtree.
Expand Down
Loading