summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'backend/functions/execution.php')
-rw-r--r--backend/functions/execution.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/backend/functions/execution.php b/backend/functions/execution.php
new file mode 100644
index 0000000..dd6dd88
--- /dev/null
+++ b/backend/functions/execution.php
@@ -0,0 +1,40 @@
+<?php
+function execute_command_with_all($description, $command, $fatal=true, $path=null, $env=null) {
+ global $build, $task;
+ $default_env=array(
+ 'PATH' => $_ENV['PATH']
+ );
+ $env=is_array($env)?array_merge($default_env, $env):$default_env;
+ // TODO this won't work once we have internal tasks too - we need to use a common function for tracking order
+ static $buildid=null;
+ static $order=0;
+ if ($build->id !== $buildid) {
+ $buildid=$build->id;
+ $order=0;
+ }
+ $task=new sql_task($build->id, $order++, null, $description, $command);
+ $result=$task->execute($path, $env);
+ unset($task);
+ if ($result != 0 && $fatal) {
+ if ($result > 0)
+ throw_exception($command.' returned with exit status '.$result);
+ elseif ($result == -128)
+ throw_exception($command.' received an unknown signal');
+ else
+ throw_exception($command.' received signal '.-$result);
+ }
+ return $result;
+}
+function execute_command($desc, $cmd) {
+ return execute_command_with_all($desc, $cmd, true, null, null);
+}
+function execute_command_with_env($desc, $cmd, $env) {
+ return execute_command_with_all($desc, $cmd, true, null, $env);
+}
+function execute_command_with_path($desc, $cmd, $path) {
+ return execute_command_with_all($desc, $cmd, true, $path, null);
+}
+function execute_non_fatal_command($desc, $cmd, $path=null, $env=null) {
+ return execute_command_with_all($desc, $cmd, false, $path, $env);
+}
+?>