summaryrefslogtreecommitdiff
path: root/buildstream/buildelement.py
diff options
context:
space:
mode:
authorTristan Maat <tm@tlater.net>2018-04-06 16:02:07 +0000
committerTristan Maat <tristan.maat@codethink.co.uk>2018-04-13 12:51:17 +0100
commit299df2339fee78af2a18faa656e85f01b972926d (patch)
tree12a70345cde2483fe5ea707b1fecd7e7ce7abe0b /buildstream/buildelement.py
parent596264d1e4cdcdf61d1f81b6d6b11ca504048a35 (diff)
downloadbuildstream-299df2339fee78af2a18faa656e85f01b972926d.tar.gz
Add element.prepare method
This is one of the tasks of #209
Diffstat (limited to 'buildstream/buildelement.py')
-rw-r--r--buildstream/buildelement.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/buildstream/buildelement.py b/buildstream/buildelement.py
index 243491c97..6d6c200ca 100644
--- a/buildstream/buildelement.py
+++ b/buildstream/buildelement.py
@@ -172,20 +172,12 @@ class BuildElement(Element):
# Run commands
for command_name in _command_steps:
commands = self.commands[command_name]
- if not commands:
+ if not commands or command_name == 'configure-commands':
continue
with self.timed_activity("Running {}".format(command_name)):
for cmd in commands:
- self.status("Running {}".format(command_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))
+ self._run_command(sandbox, cmd, command_name)
# %{install-root}/%{build-root} should normally not be written
# to - if an element later attempts to stage to a location
@@ -204,6 +196,12 @@ class BuildElement(Element):
# always the /buildstream-install directory
return self.get_variable('install-root')
+ def prepare(self, sandbox):
+ commands = self.commands['configure-commands']
+ if commands:
+ for cmd in commands:
+ self._run_command(sandbox, cmd, 'configure-commands')
+
def generate_script(self):
script = ""
for command_name in _command_steps:
@@ -226,3 +224,15 @@ class BuildElement(Element):
commands.append(command)
return commands
+
+ def _run_command(self, sandbox, cmd, cmd_name):
+ with self.timed_activity("Running {}".format(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))