diff options
Diffstat (limited to 'backend/functions/build.php')
-rw-r--r-- | backend/functions/build.php | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/backend/functions/build.php b/backend/functions/build.php index 9859020..3346218 100644 --- a/backend/functions/build.php +++ b/backend/functions/build.php @@ -1,39 +1,43 @@ <?php -// Sample variables (will be in config file or user input) -$conf['pkgdir']='/home/eitan/soc/tinderbox/default-linux-amd64'; -// $conf['cflags']='-march=nocona -O2 -pipe'; // Not needed in a binary install -// $conf['cxxflags']='$CFLAGS'; // Not needed in a binary install -$conf['chost']='x86_64-pc-linux-gnu'; -$conf['port_logdir']='$W/log'; -$conf['emerge_log_dir']=$conf['port_logdir']; -$conf['emerge_default_opts']='-t -K --color=n --root-deps=rdeps'; -$conf['portage_tmpdir']='$W/tmp'; $profile='/etc/make.profile'; // This is the main function that carries out a build from start to finish function build(&$build) { - global $conf, $profile; + global $pdo, $conf, $profile; + $r=$pdo->query('SELECT * FROM `buildopts` WHERE `build`="'.$build->id.'"'); + while ($opt=$r->fetch(PDO::FETCH_ASSOC)) { + $opt=new sql_buildopt($opt); + $opts[$opt->name]=$opt; + } + $profile=new sql_profile($opts['profile']->value); + $headers=get_profile_headers($profile); + $makeconf['pkgdir']=$conf['pkgdir_root'].'/'.$profile->pkgdir; + $makeconf['chost']=$headers['chost']; $build->status='build/started'; $build->write(); - define('W', WORK.'/build-'.$build->id); - fatal(log_status('Creating work directory '.W, mkdir(W, 0700))); - fatal(log_status('Creating '.W.'/image', mkdir(W.'/image', 0700))); - define('I', W.'/image'); - fatal(log_status('Creating '.W.'/config_root', mkdir(W.'/config_root', 0700))); - define('C', W.'/config_root'); - fatal(log_status('Creating '.C.'/etc', mkdir(C.'/etc', 0700))); - fatal(log_status('Creating '.C.'/etc/portage', mkdir(C.'/etc/portage', 0700))); - fatal(log_status('Creating '.W.'/log', mkdir(W.'/log', 0700))); - fatal(log_status('Creating '.W.'/tmp', mkdir(W.'/tmp', 0700))); - $makeconf='W="'.W.'"'."\n"; - foreach ($conf as $name => $val) { - $makeconf.=strtoupper($name).'="'.$val.'"'."\n"; + $W=WORK.'/build-'.$build->id; + fatal(log_status('Creating work directory '.$W, mkdir($W, 0700))); + $I=$W.'/image'; + fatal(log_status('Creating '.$I, mkdir($I, 0700))); + $C=$W.'/config_root'; + fatal(log_status('Creating '.$C, mkdir($C, 0700))); + fatal(log_status("Making symlink $C/etc -> $C", symlink('.', "$C/etc"))); + fatal(log_status('Creating '.$W.'/log', mkdir($W.'/log', 0700))); + $makeconf['port_logdir']=$W.'/log'; + $makeconf['emerge_log_dir']=$conf['port_logdir']; + fatal(log_status('Creating '.$W.'/tmp', mkdir($W.'/tmp', 0700))); + $makeconf['portage_tmpdir']=$W.'/tmp'; + $makeconf['emerge_default_opts']=$conf['emerge_default_opts']; + $contents=''; + foreach ($makeconf as $name => $val) { // TODO maybe shell_escape $val + $contents.=strtoupper($name).'="'.$val.'"'."\n"; } - fatal(log_status('Writing '.C.'/make.conf:'."\n".indent($makeconf), file_put_contents(C.'/etc/make.conf', $makeconf))); unset($makeconf); - fatal(log_status('Making make.profile symlink to '.$profile, symlink($profile, C.'/etc/make.profile'))); + fatal(log_status('Writing '.$C.'/make.conf:'."\n".indent($contents), file_put_contents($C.'/etc/make.conf', $contents))); + unset($contents); + fatal(log_status('Making make.profile symlink to '.$conf['portdir'].'/profiles/'.$headers['profile'], symlink($conf['portdir'].'/profiles/'.$headers['profile'], $C.'/etc/make.profile'))); $env=array( - 'PORTAGE_CONFIGROOT' => C, - 'ROOT' => I + 'PORTAGE_CONFIGROOT' => $C, + 'ROOT' => $I ); fatal(!log_command($build, 'emerge --info', null, $env)!=0); fatal(!log_command($build, 'emerge -pv system', null, $env)!=0); |