summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'shared/classes/build.php')
-rw-r--r--shared/classes/build.php93
1 files changed, 74 insertions, 19 deletions
diff --git a/shared/classes/build.php b/shared/classes/build.php
index c863f1f..64730fe 100644
--- a/shared/classes/build.php
+++ b/shared/classes/build.php
@@ -30,11 +30,23 @@ class sql_build extends conf_build_common {
'length' => '\'public\',\'private\'',
'not_null' => true
),
+ 'backend' => array (
+ 'type' => 'VARCHAR',
+ 'length' => 255
+ ),
'status' => array (
+ 'type' => 'ENUM',
+ 'length' => '\'queued\',\'uploading\',\'cancel\',\'complete\',\'upload_failed\',\'canceled\',\'failed\',\'got_signal\',\'building\',\'bundling\'',
+ 'not_null' => true
+ ),
+ 'details' => array (
'type' => 'TINYINT',
- 'length' => 4,
- 'not_null' => true,
- 'default' => 0
+ 'length' => 4
+ ),
+ 'build_step' => array (
+ 'type' => 'TINYINT',
+ 'length' => 3,
+ 'unsigned' => true
),
'ctime' => array (
'type' => 'INT',
@@ -59,46 +71,48 @@ class sql_build extends conf_build_common {
$perms=$this->visibility == 'public' || owner_or_admin($this->id);
$html='<div class="build"><span class="name">'.(isset($this->name) && strlen($this->name)?htmlentities($this->name):'Unnamed Build').'</span> ';
$links=array();
- if ($this->status == INGENUE_BUILD_QUEUED) {
- $total=query('SELECT COUNT(*) FROM `builds` WHERE `status`=-128')->fetch(PDO::FETCH_COLUMN);
- $num=query('SELECT COUNT(*) FROM `builds` WHERE `status`=-128 AND `ctime` <= '.$this->ctime)->fetch(PDO::FETCH_COLUMN);
+ if ($this->status == 'queued') {
+ $total=query('SELECT COUNT(*) FROM `builds` WHERE `status`="queued"')->fetch(PDO::FETCH_COLUMN);
+ $num=query('SELECT COUNT(*) FROM `builds` WHERE `status`="queued" AND `ctime` <= '.$this->ctime)->fetch(PDO::FETCH_COLUMN);
$html.="<span class=\"status queued\">[queued ($num/$total)]</span>";
- } elseif ($this->status == INGENUE_BUILD_UPLOADING) {
+ } elseif ($this->status == 'uploading') {
$html.='<span class="status successful">[uploading]</span>';
if ($perms) $links['Build log']="build/$this->id";
- } elseif ($this->status == INGENUE_BUILD_CANCEL) {
+ } elseif ($this->status == 'cancel') {
$html.='<span class="status queued">[pending cancellation]</span>';
if ($perms) $links['Build log']="build/$this->id";
- } elseif ($this->status < 0) {
- // TODO Build stage X
- $html.='<span class="status building">[building]</span>';
+ } elseif ($this->status == 'building') {
+ // TODO stage x/y
+ $html.='<span class="status building">[building ('.$this->build_step.'/'.$this->details.')]</span>';
if ($perms) {
//$links['Watch']="build/$this->id/live";
$links['Build Log']="build/$this->id";
}
- } elseif ($this->status == INGENUE_BUILD_COMPLETE) {
+ } elseif ($this->status == 'complete') {
$r=query('SELECT COUNT(*) as `count`, MAX(`time`) as `time` FROM `downloads` WHERE `build`="'.$this->id.'"')->fetch(PDO::FETCH_ASSOC);
$d=($perms && $r['count']?'<a href="'.url("build/$this->id/history").'">':'').$r['count'].' download'.($r['count'] != 1?'s':'').($r['count']?($perms?'</a>':'').'<br/><span class="time">(last at '.date($format, $r['time']).')</span>':'');
$html.='<span class="downloads">'.$d.'</span><span class="status successful">[successful]</span>';
$links['Download image']="build/$this->id/download";
if ($perms) $links['Build log']="build/$this->id";
- } elseif ($this->status == INGENUE_BUILD_UPLOAD_FAILED) {
+ } elseif ($this->status == 'upload_failed') {
$html.='<span class="status failed">[upload failed]</span>';
if ($perms) $links['Build log']="build/$this->id";
- } elseif ($this->status == INGENUE_BUILD_FAILED) {
- $html.='<span class="status failed">[failed]</span>';
+ } elseif ($this->status == 'failed') {
+ $html.='<span class="status failed">[failed after step '.$this->build_step.']</span>';
if ($perms) {
//$links['View output of failed command']="build/$this->id/failure";
$links['Build log']="build/$this->id";
}
- } elseif ($this->status == INGENUE_BUILD_CANCELED) {
+ } elseif ($this->status == 'canceled') {
$html.='<span class="status failed">[canceled]</span>';
if ($perms) $links['Build log']="build/$this->id";
- } else {
- $html.='<span class="status failed">[failed: got signal '.$this->status.']</span>';
+ } elseif ($this->status == 'got_signal') {
+ $html.='<span class="status failed">[failed: got signal '.$this->details.' after step '.$this->build_step.']</span>';
if ($perms) $links['Build log']="build/$this->id";
+ } else {
+ $html.='<span class="status failed">[UNKNOWN STATUS: '.$this->status.']</span>';
}
- if ($this->status >= 0 || $this->status == INGENUE_BUILD_QUEUED) // Finished or queued
+ if ($perms && ($this->status == 'upload_failed' || $this->status == 'failed' || $this->status == 'canceled' || $this->status == 'queued' || $this->status == 'complete' || $this->status == 'got_signal'))
$links['Delete']="build/$this->id/delete";
if ($links) {
foreach ($links as $label => $url) {
@@ -144,5 +158,46 @@ class sql_build extends conf_build_common {
unlink($file);
parent::delete();
}
+ public function build($workdir) {
+ global $S;
+ try {
+ if (!is_dir($workdir))
+ log_status('Create work directory '.$workdir, mkdir($workdir, 0700));
+ $opts=$this->get_opts();
+ $S['build_steps']=array();
+ if (!is_readable(BACKEND."/modules/$this->module/build.php"))
+ throw_exception("No build script for module $this->module");
+ $dir=require(BACKEND."/modules/$this->module/build.php");
+ switch ($this->status) {
+ case 'queued':
+ $this->build_step=0;
+ case 'got_signal':
+ case 'failed':
+ $this->status='building';
+ $this->details=count($S['build_steps']);
+ $this->write();
+ case 'building':
+ $step=$this->build_step;
+ break;
+ case 'uploading':
+ case 'upload_failed':
+ case 'cancel':
+ case 'bundling':
+ default:
+ $step=count($S['build_steps']);
+ }
+ while ($step < count($S['build_steps'])) {
+ require(BACKEND."/modules/$this->module/{$S['build_steps'][$step]}.php");
+ $step++;
+ $this->build_step=$step;
+ $this->write();
+ }
+ return $dir;
+ } catch(Exception $e) {
+ log_msg('Caught exception: '.$e->getMessage());
+ end_internal_task(1);
+ return false;
+ }
+ }
}
?>