Skip to content
Snippets Groups Projects
Commit 56710c49 authored by Jürg Billeter's avatar Jürg Billeter
Browse files

buildelement.py: Support batching for integration and build commands

parent c4b86ea7
No related branches found
No related tags found
No related merge requests found
......@@ -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.configure_prepare_assemble_batch(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(0, 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)
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment