summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2018-09-28 14:17:16 +0100
committerJürg Billeter <j@bitron.ch>2018-11-27 13:44:49 +0000
commit63db90b2846681943ca70bababdaa6376e33bd9b (patch)
treeb45e2f07353785a4bdd8c2c249f5a3d77d085cfc
parent7827ac5039f7d7cd80e3937d0b3c81e462524c78 (diff)
downloadbuildstream-63db90b2846681943ca70bababdaa6376e33bd9b.tar.gz
buildelement.py: Support batching for integration and build commands
-rw-r--r--buildstream/buildelement.py23
-rw-r--r--tests/integration/sandbox-bwrap.py2
2 files changed, 12 insertions, 13 deletions
diff --git a/buildstream/buildelement.py b/buildstream/buildelement.py
index 48b7f2423..f1b13e796 100644
--- a/buildstream/buildelement.py
+++ b/buildstream/buildelement.py
@@ -127,7 +127,7 @@ artifact collection purposes.
"""
import os
-from . import Element, Scope, ElementError
+from . import Element, Scope
from . import SandboxFlags
@@ -207,6 +207,10 @@ class BuildElement(Element):
# Setup environment
sandbox.set_environment(self.get_environment())
+ # Enable command batching across prepare() and assemble()
+ self.batch_prepare_assemble(SandboxFlags.ROOT_READ_ONLY,
+ collect=self.get_variable('install-root'))
+
def stage(self, sandbox):
# Stage deps in the sandbox root
@@ -215,7 +219,7 @@ class BuildElement(Element):
# Run any integration commands provided by the dependencies
# once they are all staged and ready
- with self.timed_activity("Integrating sandbox"):
+ with sandbox.batch(SandboxFlags.NONE, label="Integrating sandbox"):
for dep in self.dependencies(Scope.BUILD):
dep.integrate(sandbox)
@@ -223,14 +227,13 @@ class BuildElement(Element):
self.stage_sources(sandbox, self.get_variable('build-root'))
def assemble(self, sandbox):
-
# Run commands
for command_name in _command_steps:
commands = self.__commands[command_name]
if not commands or command_name == 'configure-commands':
continue
- with self.timed_activity("Running {}".format(command_name)):
+ with sandbox.batch(SandboxFlags.ROOT_READ_ONLY, label="Running {}".format(command_name)):
for cmd in commands:
self.__run_command(sandbox, cmd, command_name)
@@ -254,7 +257,7 @@ class BuildElement(Element):
def prepare(self, sandbox):
commands = self.__commands['configure-commands']
if commands:
- with self.timed_activity("Running configure-commands"):
+ with sandbox.batch(SandboxFlags.ROOT_READ_ONLY, label="Running configure-commands"):
for cmd in commands:
self.__run_command(sandbox, cmd, 'configure-commands')
@@ -282,13 +285,9 @@ class BuildElement(Element):
return commands
def __run_command(self, sandbox, cmd, cmd_name):
- self.status("Running {}".format(cmd_name), detail=cmd)
-
# Note the -e switch to 'sh' means to exit with an error
# if any untested command fails.
#
- exitcode = sandbox.run(['sh', '-c', '-e', cmd + '\n'],
- SandboxFlags.ROOT_READ_ONLY)
- if exitcode != 0:
- raise ElementError("Command '{}' failed with exitcode {}".format(cmd, exitcode),
- collect=self.get_variable('install-root'))
+ sandbox.run(['sh', '-c', '-e', cmd + '\n'],
+ SandboxFlags.ROOT_READ_ONLY,
+ label=cmd)
diff --git a/tests/integration/sandbox-bwrap.py b/tests/integration/sandbox-bwrap.py
index d2484bc17..b77709c35 100644
--- a/tests/integration/sandbox-bwrap.py
+++ b/tests/integration/sandbox-bwrap.py
@@ -58,5 +58,5 @@ def test_sandbox_bwrap_return_subprocess(cli, tmpdir, datafiles):
})
result = cli.run(project=project, args=['build', element_name])
- result.assert_task_error(error_domain=ErrorDomain.ELEMENT, error_reason=None)
+ result.assert_task_error(error_domain=ErrorDomain.SANDBOX, error_reason="command-failed")
assert "sandbox-bwrap/command-exit-42.bst|Command 'exit 42' failed with exitcode 42" in result.stderr