summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-07-01 17:46:53 -0400
committerEudyptula <eitan@mosenkis.net>2009-07-01 17:46:53 -0400
commite77f28c56eef5feae20bfc7716e6c11b2195ada0 (patch)
treeb675457e790b107f776e6e26e0255811d24facf7 /backend/functions/execution.php
parentMany fixes to CD building and some to command execution/logging (diff)
downloadingenue-e77f28c56eef5feae20bfc7716e6c11b2195ada0.tar.gz
ingenue-e77f28c56eef5feae20bfc7716e6c11b2195ada0.tar.bz2
ingenue-e77f28c56eef5feae20bfc7716e6c11b2195ada0.zip
Update both parts for proper modularity, start catalyst-based backend, code cleanup, especially on backend
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);
+}
+?>