com web/rmtools: Rebase scripts to current version: client/include/Branch.php client/include/BranchConfig.php client/include/BuildVC.php
client/include/Repository.php client/include/Tools.php client/script/snap.php

From: Date: Wed, 21 Nov 2012 23:43:35 +0000
Subject: com web/rmtools: Rebase scripts to current version: client/include/Branch.php client/include/BranchConfig.php client/include/BuildVC.php
client/include/Repository.php client/include/Tools.php client/script/snap.php
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-15641@lists.php.net to get a copy of this message
Commit: 3fdf9c3b90f6d43f95fedcd903027018bf7ee6b9 Author: Stephen Zarkos <stephen.zarkos@microsoft.com> Wed, 21 Nov 2012 15:43:35 -0800 Parents: 742a5efc772a25fdb19c18048780d71167a2facf Branches: master Link: http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=3fdf9c3b90f6d43f95fedcd903027018bf7ee6b9 Log: Rebase scripts to current version - Add Git support - Add PGO and concurrent build support - Improve last_revision checking, broken with concurrent builds Changed paths: M client/include/Branch.php M client/include/BranchConfig.php M client/include/BuildVC.php M client/include/Repository.php M client/include/Tools.php M client/script/snap.php

diff --git a/client/include/Branch.php b/client/include/Branch.php index edaf329..f9827e6 100644 --- a/client/include/Branch.php +++ b/client/include/Branch.php @@ -1,154 +1,173 @@ -<?php -namespace rmtools; - -include __DIR__ . '/BranchConfig.php'; -include __DIR__ . '/Repository.php'; -include __DIR__ . '/BuildVC.php'; - -class Branch { - public $last_revision; - public $last_revision_has_snap; - public $config; - private $repo; - public $db_path; - private $has_new_revision; - public $data = NULL; - - public function __construct($config_path) - { - if (!is_readable($config_path)) { - throw new \Exception('Cannot open config data <' . $config_path . '>'); - } - $this->config = new BranchConfig($config_path); - $this->repo = Repository::fromBranchConfig($this->config); - $this->repo->setModule($this->config->getModule()); - $this->repo->setBranch($this->config->getRepoBranch()); - $this->db_path = __DIR__ . '/../data/db/' . $this->config->getName() . '.json'; - if (file_exists($this->db_path)) { - $this->data = json_decode(file_get_contents($this->db_path)); - } else { - $data = new \StdClass; - $data->revision_last = NULL; - $data->revision_previous = NULL; - $data->revision_last_exported = NULL; - $this->data = $data; - } - $this->addBuildList(); - } - - private function addBuildList() - { - $builds = $this->config->getBuildList(); - - if (!empty($builds)) { - $this->data->builds = array(); - foreach ($builds as $n => $v) { - $this->data->builds[] = $n; - } - } else { - $this->data->builds = NULL; - } - } - - public function update() - { - $last_id = $this->repo->getLastCommitId(); - if ($last_id != $this->data->revision_last) { - $this->data->revision_previous = $this->data->revision_last; - $this->data->revision_last = $last_id; - $json = json_encode($this->data); - file_put_contents($this->db_path, $json); - $this->has_new_revision = true; - } - } - - public function hasNewRevision() - { - return $this->has_new_revision || ( $this->data->revision_previous == NULL); - } - - public function export($revision = false, $zip = false) - { - $dir_name = $this->config->getName() . '-src-r' . $this->data->revision_last; - $target = $this->config->getBuildDir() . '/' . $dir_name; - $this->repo->export($target); - if ($zip) { - $zip_path = $dir_name . '.zip'; - $cmd = "zip -q -r $zip_path $dir_name"; - $res = exec_single_log($cmd, $this->config->getBuildDir()); - if (!$res) { - throw new \Exception("Export failed, svn exec failed to be ran"); - } - } - $target = realpath($target); - return $target; - } - - public function createSourceSnap($revision = false) - { - return $this->export($revision, true); - } - - public function setLastRevisionExported($last_rev) - { - $this->data->revision_last_exported = $last_rev; - $json = json_encode($this->data); - file_put_contents($this->db_path, $json); - } - - public function getLastRevisionExported() - { - return $this->data->revision_last_exported; - } - - public function getLastRevisionId() - { - if (!$this->data->revision_last) { - $this->update(); - } - return $this->data->revision_last; - } - - public function getPreviousRevision() - { - if (!$this->data->revision_previous) { - return NULL; - } - return $this->data->revision_previous; - } - - function getBuildList($platform) - { - $builds = array(); - foreach ($this->data->builds as $build_name) { - $build = $this->config->getBuildFromName($build_name); - if (isset($build['platform']) && $build['platform'] == $platform) { - $builds[] = $build_name; - } - } - return $builds; - } - - function createBuildInstance($build_name) - { - $build = $this->config->getBuildFromName($build_name); - - if (!$build) { - throw new \Exception("Invalid build name <$build_name>"); - } - - $compiler = strtolower($build['compiler']); - switch ($compiler) { - case 'vc9': - case 'vc6': - $build = new BuildVC($this, $build_name); - break; - case 'icc': - case 'gcc': - throw new \Exception("$compiler not supported yet. Not implemented"); - break; - } - - return $build; - } -} +<?php +namespace rmtools; + +include __DIR__ . '/BranchConfig.php'; +include __DIR__ . '/Repository.php'; +include __DIR__ . '/BuildVC.php'; + +class Branch { + public $last_revision; + public $last_revision_has_snap; + public $config; + private $repo; + public $db_path; + private $has_new_revision; + public $data = NULL; + + public function __construct($config_path) + { + if (!is_readable($config_path)) { + throw new \Exception('Cannot open config data <' . $config_path . '>'); + } + $this->config = new BranchConfig($config_path); + $this->repo = Repository::fromBranchConfig($this->config); + $this->repo->setModule($this->config->getModule()); + $this->repo->setBranch($this->config->getRepoBranch()); + $this->db_path = __DIR__ . '/../data/db/' . $this->config->getName() . '.json'; + if (file_exists($this->db_path)) { + $this->data = json_decode(file_get_contents($this->db_path)); + } else { + $data = new \StdClass; + $data->revision_last = NULL; + $data->revision_previous = NULL; + $data->revision_last_exported = NULL; + $this->data = $data; + } + $this->addBuildList(); + } + + private function addBuildList() + { + $builds = $this->config->getBuildList(); + + if (!empty($builds)) { + $this->data->builds = array(); + foreach ($builds as $n => $v) { + $this->data->builds[] = $n; + } + } else { + $this->data->builds = NULL; + } + } + + public function update() + { + $last_id = $this->repo->getLastCommitId(); + if (strcasecmp($last_id, (string)$this->data->revision_last) != 0 || + strcasecmp($last_id, $this->data->revision_previous) != 0) { + $this->data->revision_previous = $this->data->revision_last; + $this->data->revision_last = $last_id; + $json = json_encode($this->data); + file_put_contents($this->db_path, $json); + $this->has_new_revision = true; + } + } + + public function hasNewRevision() + { + return $this->has_new_revision || ( $this->data->revision_previous == NULL); + } + + public function export($revision = false, $build_type = false, $zip = false, $is_zip = false) + { + $rev_name = $this->data->revision_last; + if (strlen($this->data->revision_last) == 40) { + $rev_name = substr($this->data->revision_last, 0, 7); + } + $dir_name = $this->config->getName() . '-src-' . ($build_type ? $build_type.'-' : $build_type) . 'r' . $rev_name; + $target = $this->config->getBuildDir() . '/' . $dir_name; + $exportfile = $this->repo->export($target); + + if (preg_match('/\.zip$/', $exportfile) > 0) { // export function returned a .zip file. + $is_zip = true; + } + if ($zip && !$is_zip) { + $zip_path = $dir_name . '.zip'; + $cmd = "zip -q -r $zip_path $dir_name"; + $res = exec_single_log($cmd, $this->config->getBuildDir()); + if (!$res) { + throw new \Exception("Export failed, svn exec failed to be ran"); + } + } + elseif ($is_zip === true) { + $cmd = 'unzip -q -o ' . $exportfile . ' -d ' . $this->config->getBuildDir(); + $res = exec_single_log($cmd); + if (!$res) { + throw new \Exception("Unzipping $exportfile failed."); + } + $gitname = $this->config->getBuildDir() . '/php-src-' . strtoupper($this->config->getName()) . '-' . $rev_name; + rename($gitname, $target); + } + + $target = realpath($target); + return $target; + } + + public function createSourceSnap($build_type = false, $revision = false) + { + return $this->export($revision, $build_type, true); + } + + public function setLastRevisionExported($last_rev) + { + $this->data->revision_last_exported = $last_rev; + $json = json_encode($this->data); + file_put_contents($this->db_path, $json); + } + + public function getLastRevisionExported() + { + return $this->data->revision_last_exported; + } + + public function getLastRevisionId() + { + if (!$this->data->revision_last) { + $this->update(); + } + return $this->data->revision_last; + } + + public function getPreviousRevision() + { + if (!$this->data->revision_previous) { + return NULL; + } + return $this->data->revision_previous; + } + + function getBuildList($platform) + { + $builds = array(); + foreach ($this->data->builds as $build_name) { + $build = $this->config->getBuildFromName($build_name); + if (isset($build['platform']) && $build['platform'] == $platform) { + $builds[] = $build_name; + } + } + return $builds; + } + + function createBuildInstance($build_name) + { + $build = $this->config->getBuildFromName($build_name); + + if (!$build) { + throw new \Exception("Invalid build name <$build_name>"); + } + + $compiler = strtolower($build['compiler']); + switch ($compiler) { + case 'vc9': + case 'vc6': + $build = new BuildVC($this, $build_name); + break; + case 'icc': + case 'gcc': + throw new \Exception("$compiler not supported yet. Not implemented"); + break; + } + + return $build; + } +} diff --git a/client/include/BranchConfig.php b/client/include/BranchConfig.php index ee9fa14..ed53818 100644 --- a/client/include/BranchConfig.php +++ b/client/include/BranchConfig.php @@ -1,69 +1,70 @@ -<?php -namespace rmtools; - -class BranchConfig { - private $config = NULL; - private $config_keys = array( - 'ConfigureOptions' => 'configure_options', - 'BuildDir' => 'build_dir', - 'BuildLocation' => 'build_location', - 'SourceDir' => 'source_dir', - 'Include' => 'INCLUDE', - 'Lib' => 'LIB', - 'Path' => 'PATH', - 'Compiler' => 'compiler', - 'Architecture' => 'arch', - 'Branch' => 'branch', - 'Name' => 'name', - 'RepoName'=>'repo_name', - 'RepoBranch'=> 'repo_branch', - 'Module' => 'repo_module', - ); - - function __construct($path) - { - //$this->config = parse_ini_file($path, false, INI_SCANNER_RAW); - $this->config = parse_ini_file($path, true,INI_SCANNER_RAW); - if (!$this->config) { - throw new \Exception('Cannot parse config file <' . $path . '>'); - } - - $builds = array(); - - foreach ($this->config as $name => $entry) { - if (substr($name, 0, 6) == 'build-') { - $name = str_ireplace('build-', '', $name); - $builds[$name] = $entry; - } - } - $this->builds = $builds; - } - - function __call($name, $key) { - $name = str_replace('get', '', $name); - if (!isset($this->config_keys[$name])) { - throw new \Exception("Invalid config entry name <$name>"); - } - - $name = $this->config_keys[$name]; - return (isset($this->config[$name]) ? $this->config[$name] : ''); - } - - function getBuildList() - { - return $this->builds; - } - - function getBuildFromName($build_name) { - return isset($this->builds[$build_name]) ? $this->builds[$build_name] : NULL; - } - - function getConfigureOptions($build_name) - { - if (isset($this->builds[$build_name]) && isset($this->builds[$build_name]['configure_options'])) { - return $this->builds[$build_name]['configure_options']; - } else { - return ''; - } - } -} +<?php +namespace rmtools; + +class BranchConfig { + private $config = NULL; + private $config_keys = array( + 'ConfigureOptions' => 'configure_options', + 'BuildDir' => 'build_dir', + 'BuildLocation' => 'build_location', + 'SourceDir' => 'source_dir', + 'Include' => 'INCLUDE', + 'Lib' => 'LIB', + 'Path' => 'PATH', + 'Compiler' => 'compiler', + 'Architecture' => 'arch', + 'Branch' => 'branch', + 'Name' => 'name', + 'RepoName' => 'repo_name', + 'RepoBranch' => 'repo_branch', + 'Module' => 'repo_module', + 'PGO' => 'pgo', + ); + + function __construct($path) + { + //$this->config = parse_ini_file($path, false, INI_SCANNER_RAW); + $this->config = parse_ini_file($path, true,INI_SCANNER_RAW); + if (!$this->config) { + throw new \Exception('Cannot parse config file <' . $path . '>'); + } + + $builds = array(); + + foreach ($this->config as $name => $entry) { + if (substr($name, 0, 6) == 'build-') { + $name = str_ireplace('build-', '', $name); + $builds[$name] = $entry; + } + } + $this->builds = $builds; + } + + function __call($name, $key) { + $name = str_replace('get', '', $name); + if (!isset($this->config_keys[$name])) { + throw new \Exception("Invalid config entry name <$name>"); + } + + $name = $this->config_keys[$name]; + return (isset($this->config[$name]) ? $this->config[$name] : ''); + } + + function getBuildList() + { + return $this->builds; + } + + function getBuildFromName($build_name) { + return isset($this->builds[$build_name]) ? $this->builds[$build_name] : NULL; + } + + function getConfigureOptions($build_name) + { + if (isset($this->builds[$build_name]) && isset($this->builds[$build_name]['configure_options'])) { + return $this->builds[$build_name]['configure_options']; + } else { + return ''; + } + } +} diff --git a/client/include/BuildVC.php b/client/include/BuildVC.php index cb57f91..6615a9b 100644 --- a/client/include/BuildVC.php +++ b/client/include/BuildVC.php @@ -1,199 +1,199 @@ -<?php -namespace rmtools; -include __DIR__ . '/MakeLogParserVC.php'; - -class BuildVC { - public $branch; - public $build_name; - public $env; - private $obj_dir; - private $build_dir; - protected $old_cwd; - public $logs = array(); - - public $archive_path = false; - public $debug_path = false; - public $devel_path = false; - public $test_path = false; - - public $compiler_log_parser; - public $stats; - public $log_buildconf; - public $log_configure; - public $log_make; - public $log_archive; - - public $zip_devel_filename; - public $zip_debug_filename; - public $zip_test_filename; - - function __construct(Branch $branch, $build_name) - { - $this->branch = $branch; - $this->build_name = $build_name; - $this->obj_dir = $this->branch->config->getBuildDir() . '/' . $this->build_name; - $this->compiler = $this->branch->config->getCompiler(); - $this->architecture = $this->branch->config->getArchitecture(); - - $vc_env_prefix = strtoupper($this->compiler); - if ($this->architecture == 'x64') { - $vc_env_prefix .= '_X64_'; - } else { - $vc_env_prefix .= '_'; - } - - $path = getenv($vc_env_prefix . 'PATH'); - if (empty($path)) { - include __DIR__ . '/../data/config.php'; - /* use default config */ - $env = $custom_env; - } else { - $env = array(); - $env['PATH'] = getenv($vc_env_prefix . 'PATH') . ';' . getenv('PATH') ; - $env['INCLUDE'] = getenv($vc_env_prefix . 'INCLUDE'); - $env['LIB'] = getenv($vc_env_prefix . 'LIB'); - } - - /* We don't support anymore VC6, so calling these scripts from the - SDK are just fine */ - if (!$env['INCLUDE'] || !$env['LIB']) { - $env['INCLUDE'] = getenv('INCLUDE'); - $env['LIB'] = getenv('LIB'); - } - - $env['TMP'] = $env['TEMP'] = getenv('TEMP'); - $env['SystemDrive'] = getenv('SystemDrive'); - $env['SystemRoot'] = getenv('SystemRoot'); - if (!isset($env['BISON_SIMPLE'])) { - $env['BISON_SIMPLE'] = getenv('BISON_SIMPLE'); - } - $this->env = $env; - } - - function setSourceDir($src_dir) - { - $this->build_dir = $src_dir; - } - - private function addLogsToArchive() - { - $zip = new \ZipArchive(); - if ($zip->open($this->archive_path) === FALSE) { - throw new \Exception('cannot open archive'); - } - $zip->addFromString('logs\buildconf.txt', $this->log_buildconf); - $zip->addFromString('logs\configure.txt', $this->log_configure); - $zip->addFromString('logs\make.txt', $this->log_make); - $zip->addFromString('logs\archive.txt', $this->log_archive); - $zip->close(); - } - - function buildconf() - { - $cmd = 'buildconf'; - $ret = exec_single_log($cmd, $this->build_dir, $this->env); - if (!$ret) { - throw new \Exception('buildconf failed'); - } - $this->log_buildconf = $ret['log']; - } - - function configure($extra = false) - { - $args = $this->branch->config->getConfigureOptions($this->build_name) . ($extra ?: $extra); - $cmd = 'configure ' . $args . ' --enable-object-out-dir=' . $this->obj_dir; - /* old build may have been stoped */ - if (is_dir($this->obj_dir)) { - rmdir_rf($this->obj_dir); - } - mkdir($this->obj_dir, 0655, true); - $ret = exec_single_log($cmd, $this->build_dir, $this->env); - if (!$ret) { - throw new \Exception('Configure failed'); - } - $this->log_configure = $ret['log']; - } - - function make() - { - $cmd = 'nmake'; - $ret = exec_single_log($cmd, $this->build_dir, $this->env); - if (!$ret) { - throw new \Exception('Make failed'); - } - $this->log_make = $ret['log']; - } - - function makeArchive() - { - $cmd = 'nmake snap'; - $ret = exec_single_log($cmd, $this->build_dir, $this->env); - if (!$ret) { - throw new \Exception('Make snap failed'); - } - - $this->log_archive = $ret['log']; - - if (!preg_match('/Build dir: (.*)/', $this->log_configure, $matches)) { - throw new \Exception('Make archive failed, cannot find build dir'); - } - $zip_dir = trim($matches[1]); - - if (!preg_match('/.*(php-\d\.\d\.\d.*\.zip)/', $this->log_archive, $matches)) { - throw new \Exception('Make archive failed, cannot find php archive'); - } - $zip_filename = trim($matches[1]); - - if (!preg_match('/.*(php-devel-pack-\d\.\d\.\d.*\.zip)/', $this->log_archive, $matches)) { - throw new \Exception('Make archive failed, cannot find php-devel archive'); - } - $zip_devel_filename = trim($matches[1]); - $this->zip_devel_filename = $zip_devel_filename; - - if (!preg_match('/.*(php-debug-pack-\d\.\d\.\d.*\.zip)/', $this->log_archive, $matches)) { - throw new \Exception('Make archive failed, cannot find php-debug archive'); - } - $zip_debug_filename = trim($matches[1]); - $this->zip_debug_filename = $zip_debug_filename; - - if (!preg_match('/.*(php-test-pack-\d\.\d\.\d.*\.zip)/', $this->log_archive, $matches)) { - throw new \Exception('Make archive failed, cannot find php-test archive'); - } - $zip_test_filename = trim($matches[1]); - $this->zip_test_filename = $zip_test_filename; - - $this->archive_path = realpath($zip_dir . '/' . $zip_filename); - $this->debug_path = realpath($zip_dir . '/' . $zip_debug_filename); - $this->devel_path = realpath($zip_dir . '/' . $zip_devel_filename); - $this->test_path = realpath($zip_dir . '/' . $zip_test_filename); - - $this->addLogsToArchive(); - } - - function getMakeLogParsed() - { - $parser = new MakeLogParserVc; - $tmpfile = $this->obj_dir . '/' . 'make.txt'; - file_put_contents($tmpfile, $this->log_make); - $parser->parse($tmpfile, $this->build_dir); - unlink($tmpfile); - $this->stats = $parser->stats; - $this->compiler_log_parser = $parser; - return $parser->toHtml($this->build_name); - } - - function getStats() - { - return $this->stats; - } - - function clean() - { - rmdir_rf($this->obj_dir); - } - - function getLogs() - { - - } -} +<?php +namespace rmtools; +include __DIR__ . '/MakeLogParserVC.php'; + +class BuildVC { + public $branch; + public $build_name; + public $env; + private $obj_dir; + private $build_dir; + protected $old_cwd; + public $logs = array(); + + public $archive_path = false; + public $debug_path = false; + public $devel_path = false; + public $test_path = false; + + public $compiler_log_parser; + public $stats; + public $log_buildconf; + public $log_configure; + public $log_make; + public $log_archive; + + public $zip_devel_filename; + public $zip_debug_filename; + public $zip_test_filename; + + function __construct(Branch $branch, $build_name) + { + $this->branch = $branch; + $this->build_name = $build_name; + $this->obj_dir = $this->branch->config->getBuildDir() . '/' . $this->build_name; + $this->compiler = $this->branch->config->getCompiler(); + $this->architecture = $this->branch->config->getArchitecture(); + + $vc_env_prefix = strtoupper($this->compiler); + if ($this->architecture == 'x64') { + $vc_env_prefix .= '_X64_'; + } else { + $vc_env_prefix .= '_'; + } + + $path = getenv($vc_env_prefix . 'PATH'); + if (empty($path)) { + include __DIR__ . '/../data/config.php'; + /* use default config */ + $env = $custom_env; + } else { + $env = array(); + $env['PATH'] = getenv($vc_env_prefix . 'PATH') . ';' . getenv('PATH') ; + $env['INCLUDE'] = getenv($vc_env_prefix . 'INCLUDE'); + $env['LIB'] = getenv($vc_env_prefix . 'LIB'); + } + + /* We don't support anymore VC6, so calling these scripts from the + SDK are just fine */ + if (!$env['INCLUDE'] || !$env['LIB']) { + $env['INCLUDE'] = getenv('INCLUDE'); + $env['LIB'] = getenv('LIB'); + } + + $env['TMP'] = $env['TEMP'] = getenv('TEMP'); + $env['SystemDrive'] = getenv('SystemDrive'); + $env['SystemRoot'] = getenv('SystemRoot'); + if (!isset($env['BISON_SIMPLE'])) { + $env['BISON_SIMPLE'] = getenv('BISON_SIMPLE'); + } + $this->env = $env; + } + + function setSourceDir($src_dir) + { + $this->build_dir = $src_dir; + } + + private function addLogsToArchive() + { + $zip = new \ZipArchive(); + if ($zip->open($this->archive_path) === FALSE) { + throw new \Exception('cannot open archive'); + } + $zip->addFromString('logs\buildconf.txt', $this->log_buildconf); + $zip->addFromString('logs\configure.txt', $this->log_configure); + $zip->addFromString('logs\make.txt', $this->log_make); + $zip->addFromString('logs\archive.txt', $this->log_archive); + $zip->close(); + } + + function buildconf() + { + $cmd = 'buildconf'; + $ret = exec_single_log($cmd, $this->build_dir, $this->env); + if (!$ret) { + throw new \Exception('buildconf failed'); + } + $this->log_buildconf = $ret['log']; + } + + function configure($extra = false, $rm_obj = true) + { + $args = $this->branch->config->getConfigureOptions($this->build_name) . ($extra ?: $extra); + $cmd = 'configure ' . $args . ' --enable-object-out-dir=' . $this->obj_dir; + /* old build may have been stoped */ + if (is_dir($this->obj_dir) && $rm_obj === true) { + rmdir_rf($this->obj_dir); + } + mkdir($this->obj_dir, 0655, true); + $ret = exec_single_log($cmd, $this->build_dir, $this->env); + if (!$ret) { + throw new \Exception('Configure failed'); + } + $this->log_configure = $ret['log']; + } + + function make($target = false) + { + $cmd = 'nmake' . ($target ?: $target); + $ret = exec_single_log($cmd, $this->build_dir, $this->env); + if (!$ret) { + throw new \Exception('Make failed'); + } + $this->log_make = $ret['log']; + } + + function makeArchive() + { + $cmd = 'nmake snap'; + $ret = exec_single_log($cmd, $this->build_dir, $this->env); + if (!$ret) { + throw new \Exception('Make snap failed'); + } + + $this->log_archive = $ret['log']; + + if (!preg_match('/Build dir: (.*)/', $this->log_configure, $matches)) { + throw new \Exception('Make archive failed, cannot find build dir'); + } + $zip_dir = trim($matches[1]); + + if (!preg_match('/.*(php-\d\.\d\.\d.*\.zip)/', $this->log_archive, $matches)) { + throw new \Exception('Make archive failed, cannot find php archive'); + } + $zip_filename = trim($matches[1]); + + if (!preg_match('/.*(php-devel-pack-\d\.\d\.\d.*\.zip)/', $this->log_archive, $matches)) { + throw new \Exception('Make archive failed, cannot find php-devel archive'); + } + $zip_devel_filename = trim($matches[1]); + $this->zip_devel_filename = $zip_devel_filename; + + if (!preg_match('/.*(php-debug-pack-\d\.\d\.\d.*\.zip)/', $this->log_archive, $matches)) { + throw new \Exception('Make archive failed, cannot find php-debug archive'); + } + $zip_debug_filename = trim($matches[1]); + $this->zip_debug_filename = $zip_debug_filename; + + if (!preg_match('/.*(php-test-pack-\d\.\d\.\d.*\.zip)/', $this->log_archive, $matches)) { + throw new \Exception('Make archive failed, cannot find php-test archive'); + } + $zip_test_filename = trim($matches[1]); + $this->zip_test_filename = $zip_test_filename; + + $this->archive_path = realpath($zip_dir . '/' . $zip_filename); + $this->debug_path = realpath($zip_dir . '/' . $zip_debug_filename); + $this->devel_path = realpath($zip_dir . '/' . $zip_devel_filename); + $this->test_path = realpath($zip_dir . '/' . $zip_test_filename); + + $this->addLogsToArchive(); + } + + function getMakeLogParsed() + { + $parser = new MakeLogParserVc; + $tmpfile = $this->obj_dir . '/' . 'make.txt'; + file_put_contents($tmpfile, $this->log_make); + $parser->parse($tmpfile, $this->build_dir); + unlink($tmpfile); + $this->stats = $parser->stats; + $this->compiler_log_parser = $parser; + return $parser->toHtml($this->build_name); + } + + function getStats() + { + return $this->stats; + } + + function clean() + { + rmdir_rf($this->obj_dir); + } + + function getLogs() + { + + } +} diff --git a/client/include/Repository.php b/client/include/Repository.php index db57034..4297e3c 100644 --- a/client/include/Repository.php +++ b/client/include/Repository.php @@ -1,34 +1,39 @@ -<?php -namespace rmtools; - -include __DIR__ . '/Svn.php'; - -class Repository { - - public static function fromBranchConfig(BranchConfig $config) - { - $name = $config->getRepoName(); - $config_path = __DIR__ . '/../data/config/repo/' . $name . '.ini'; - - if (!is_readable($config_path)) { - throw new \Exception('Cannot open repo data <' . $config_path . '>'); - } - - $repo = parse_ini_file($config_path, true,INI_SCANNER_RAW); - if (!$repo) { - throw new \Exception('Cannot parse config file <' . $config_path . '>'); - } - - if (!isset($repo['type'])) { - throw new \Exception('Invalid repo config data, no type defined'); - } - switch ($repo['type']) { - case 'svn': - $r = new Svn($repo['url']); - return $r; - break; - default: - throw new \Exception('Invalid repo config data, invalid type defined'); - } - } -} +<?php +namespace rmtools; + +include __DIR__ . '/Svn.php'; +include __DIR__ . '/Git.php'; + +class Repository { + + public static function fromBranchConfig(BranchConfig $config) + { + $name = $config->getRepoName(); + $config_path = __DIR__ . '/../data/config/repo/' . $name . '.ini'; + + if (!is_readable($config_path)) { + throw new \Exception('Cannot open repo data <' . $config_path . '>'); + } + + $repo = parse_ini_file($config_path, true,INI_SCANNER_RAW); + if (!$repo) { + throw new \Exception('Cannot parse config file <' . $config_path . '>'); + } + + if (!isset($repo['type'])) { + throw new \Exception('Invalid repo config data, no type defined'); + } + switch ($repo['type']) { + case 'svn': + $r = new Svn($repo['url']); + return $r; + break; + case 'git': + $r = new Git($repo['url']); + return $r; + break; + default: + throw new \Exception('Invalid repo config data, invalid type defined'); + } + } +} diff --git a/client/include/Tools.php b/client/include/Tools.php index 722c356..99ad895 100644 --- a/client/include/Tools.php +++ b/client/include/Tools.php @@ -1,255 +1,256 @@ -<?php -namespace rmtools; -function exec_sep_log($cmd, $cwd = NULL, $env = NULL) -{ - $return_value = false; - $log_stdout = $log_stderr = NULL; - - $descriptor_spec = array( - 1 => array("pipe", "w"), // stdout is a pipe that the child will write to - 2 => array("pipe", "w") // stderr is a file to write to - ); - - $process = proc_open($cmd, $descriptor_spec, $pipes, $cwd, $env); - - if (is_resource($process)) { - // $pipes now looks like this: - // 0 => writeable handle connected to child stdin - // 1 => readable handle connected to child stdout - // Any error output will be appended to /tmp/error-output.txt - $log_stdout = stream_get_contents($pipes[1]); - $log_stderr = stream_get_contents($pipes[2]); - fclose($pipes[1]); - fclose($pipes[2]); - - $return_value = proc_close($process); - } - - return array( - 'log_stdout' => $log_stdout, - 'log_stderr' => $log_stderr, - 'return_value' => $return_value - ); -} - -function exec_single_log($cmd, $cwd = NULL, $env = NULL) -{ - /* We take one log only, for stdout and stderr - So it looks like a normal output. - */ - $descriptor_spec = array( - 1 => array("pipe", "w"), // stdout - ); - - $cmd .= ' 2>&1'; - - $process = proc_open($cmd, $descriptor_spec, $pipes, $cwd, $env); - - if (is_resource($process)) { - // $pipes now looks like this: - // 0 => writeable handle connected to child stdin - // 1 => readable handle connected to child stdout - // Any error output will be appended to /tmp/error-output.txt - $log = stream_get_contents($pipes[1]); - fclose($pipes[1]); - $return_value = proc_close($process); - } else { - return false; - } - - $ret = array( - 'return_value' => $return_value, - 'log' => $log - ); - return $ret; -} - -function wget($url, $dest) -{ - $fp = fopen ($dest, 'wb+'); - $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL,$url); - \curl_setopt($ch, CURLOPT_FILE, $fp); - \curl_exec($ch); - \curl_close($ch); - \fclose($fp); -} - -function rmdir_rf($path) -{ - if (is_dir($path)) { - $objects = scandir($path); - foreach ($objects as $object) { - if ($object != "." && $object != "..") { - if (is_dir($path."/".$object)) { - rmdir_rf($path."/".$object); - }else { - @unlink($path."/".$object); - } - } - } - reset($objects); - rmdir($path); - } -} - -function ftp_make_directory($ftp_stream, $dir) -{ - if (ftp_is_dir($ftp_stream, $dir) || @ftp_mkdir($ftp_stream, $dir)) return true; - if (!ftp_make_directory($ftp_stream, dirname($dir))) return false; - return ftp_mkdir($ftp_stream, $dir); -} - -function ftp_is_dir($ftp_stream, $dir) -{ - $original_directory = ftp_pwd($ftp_stream); - if ( @ftp_chdir( $ftp_stream, $dir ) ) { - ftp_chdir( $ftp_stream, $original_directory ); - return true; - } else { - return false; - } -} - -function upload_file($src, $target) -{ - include __DIR__ . '/../data/config/credentials_ftps.php'; - - $ftp = ftp_connect($ftp_server); - $login_result = ftp_login($ftp, $user_snaps, $password); - if (!$login_result) { - return false; - } - $res = ftp_put($ftp, $target, $src, FTP_BINARY); - ftp_close($ftp); - return $res; -} - -function update_snapshot_page() -{ - include __DIR__ . '/../data/config/credentials_ftps.php'; - - $ftp = ftp_connect($ftp_server); - $login_result = ftp_login($ftp, $user_snaps, $password); - if (!$login_result) { - return false; - } - $res = ftp_raw($ftp, 'site UPDATE_SNAPS_PAGE'); - ftp_close($ftp); - return $res; -} - -function upload_build_result_ftp_curl($src_dir, $target) -{ - include __DIR__ . '/../data/config/credentials_ftps.php'; - - $ftp = ftp_connect($ftp_server); - if (!$ftp) { - echo "Cannot connect to $ftp_server\n"; - return false; - } - $login_result = ftp_login($ftp, $user_snaps, $password); - if (!$login_result) { - return false; - } - ftp_make_directory($ftp, $target. '/logs'); - ftp_close($ftp); - - $curl = array(); - - $ftp_path = $target; - $ftp_user = $user_snaps; - $ftp_password = $password; - - if ($ftp_path[0] != '/') { - $ftp_path = '/' . $ftp_path; - } - $mh = \curl_multi_init(); - - $files = glob($src_dir . '/*.{zip,json}', GLOB_BRACE); - foreach ($files as $i => $local_file) { - - $curl[$i] = $ch = \curl_init(); - $fp = fopen($local_file, "rb"); - $local_file = basename($local_file); - - $remoteurl = "ftps://${ftp_user}:${ftp_password}@${ftp_server}${ftp_path}/${local_file}"; - - \curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - \curl_setopt($ch, CURLOPT_URL, $remoteurl); - \curl_setopt($ch, CURLOPT_UPLOAD, 1); - \curl_setopt($ch, CURLOPT_INFILE, $fp); - \curl_setopt($ch , CURLOPT_USERPWD, $ftp_user . ':' . $ftp_password); - - \curl_multi_add_handle ($mh, $ch); - } - - $files = glob($src_dir . '/logs/*.*'); - $offset = $i + 1; - foreach ($files as $i => $local_file) { - - $ch = $curl[$offset + $i] = \curl_init(); - $fp = fopen($local_file, "rb"); - $local_file = basename($local_file); - - $remoteurl = "ftps://${ftp_user}:${ftp_password}@${ftp_server}${ftp_path}/logs/${local_file}"; - - \curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - \curl_setopt($ch, CURLOPT_URL, $remoteurl); - \curl_setopt($ch, CURLOPT_UPLOAD, 1); - \curl_setopt($ch, CURLOPT_INFILE, $fp); - \curl_setopt($ch , CURLOPT_USERPWD, $ftp_user . ':' . $ftp_password); - - \curl_multi_add_handle ($mh, $ch); - } - - do { - \curl_multi_exec($mh,$active); - } while ($active); - - foreach ($curl as $ch) { - \curl_multi_remove_handle($mh, $ch); - if (\curl_errno($ch) != 0) { - echo \curl_error($ch) . "\n"; - } - \curl_close($ch); - } - //\curl_multi_close($mh); - return true; -} - -function send_error_notification($branch_name, $build_entries, $previous_revision, $current_revision, $url_log) -{ - $errors = ''; - $params = NULL; - $headers = 'From: noreply@php.net' . "\r\n" . - 'Reply-To: noreply@php.net' . "\r\n" . - 'X-Mailer: rmtools/php.net' . "\r\n" . - 'Bcc: pierre.php@gmail.com, felipensp@gmail.com' . "\r\n"; - - foreach ($build_entries as $build_name => $entries) { - $errors .= $branch_name . ', build ' . $build_name . ":\n"; - foreach ($entries as $e) { - $errors .= implode(', ', $e) . "\n"; - } - $errors .= "\n\n"; - } - - $to = 'internals@lists.php.net'; - $subject = '[rmtools][' . $branch_name . '] Build error between r' . $previous_revision . ' and ' . $current_revision; - - ob_start(); - include __DIR__ . '/../template/mail_notification.tpl.php'; - $body = ob_get_contents(); - ob_end_clean(); - - if (substr($to, -7) === 'php.net') { - $params = '-fnoreply@php.net'; - } - - if($params == null){ - return mail($to, $subject, $body, $headers); - }else{ - return mail($to, $subject, $body, $headers, $params); - } -} +<?php +namespace rmtools; +function exec_sep_log($cmd, $cwd = NULL, $env = NULL) +{ + $return_value = false; + $log_stdout = $log_stderr = NULL; + + $descriptor_spec = array( + 1 => array("pipe", "w"), // stdout is a pipe that the child will write to + 2 => array("pipe", "w") // stderr is a file to write to + ); + + $process = proc_open($cmd, $descriptor_spec, $pipes, $cwd, $env); + + if (is_resource($process)) { + // $pipes now looks like this: + // 0 => writeable handle connected to child stdin + // 1 => readable handle connected to child stdout + // Any error output will be appended to /tmp/error-output.txt + $log_stdout = stream_get_contents($pipes[1]); + $log_stderr = stream_get_contents($pipes[2]); + fclose($pipes[1]); + fclose($pipes[2]); + + $return_value = proc_close($process); + } + + return array( + 'log_stdout' => $log_stdout, + 'log_stderr' => $log_stderr, + 'return_value' => $return_value + ); +} + +function exec_single_log($cmd, $cwd = NULL, $env = NULL) +{ + /* We take one log only, for stdout and stderr + So it looks like a normal output. + */ + $descriptor_spec = array( + 1 => array("pipe", "w"), // stdout + ); + + $cmd .= ' 2>&1'; + + $process = proc_open($cmd, $descriptor_spec, $pipes, $cwd, $env); + + if (is_resource($process)) { + // $pipes now looks like this: + // 0 => writeable handle connected to child stdin + // 1 => readable handle connected to child stdout + // Any error output will be appended to /tmp/error-output.txt + $log = stream_get_contents($pipes[1]); + fclose($pipes[1]); + $return_value = proc_close($process); + } else { + return false; + } + + $ret = array( + 'return_value' => $return_value, + 'log' => $log + ); + return $ret; +} + +function wget($url, $dest) +{ + $fp = fopen ($dest, 'wb+'); + $ch = \curl_init(); + \curl_setopt($ch, CURLOPT_URL,$url); + \curl_setopt($ch, CURLOPT_FILE, $fp); + \curl_exec($ch); + \curl_close($ch); + \fclose($fp); +} + +function rmdir_rf($path) +{ + if (is_dir($path)) { + $objects = scandir($path); + foreach ($objects as $object) { + if ($object != "." && $object != "..") { + if (is_dir($path."/".$object)) { + rmdir_rf($path."/".$object); + }else { + @unlink($path."/".$object); + } + } + } + reset($objects); + rmdir($path); + } +} + +function ftp_make_directory($ftp_stream, $dir) +{ + if (ftp_is_dir($ftp_stream, $dir) || @ftp_mkdir($ftp_stream, $dir)) return true; + if (!ftp_make_directory($ftp_stream, dirname($dir))) return false; + return ftp_mkdir($ftp_stream, $dir); +} + +function ftp_is_dir($ftp_stream, $dir) +{ + $original_directory = ftp_pwd($ftp_stream); + if ( @ftp_chdir( $ftp_stream, $dir ) ) { + ftp_chdir( $ftp_stream, $original_directory ); + return true; + } else { + return false; + } +} + +function upload_file($src, $target) +{ + include __DIR__ . '/../data/config/credentials_ftps.php'; + + $ftp = ftp_connect($ftp_server); + $login_result = ftp_login($ftp, $user_snaps, $password); + if (!$login_result) { + return false; + } + $res = ftp_put($ftp, $target, $src, FTP_BINARY); + ftp_close($ftp); + return $res; +} + +function update_snapshot_page() +{ + include __DIR__ . '/../data/config/credentials_ftps.php'; + + $ftp = ftp_connect($ftp_server); + $login_result = ftp_login($ftp, $user_snaps, $password); + if (!$login_result) { + return false; + } + $res = ftp_raw($ftp, 'site UPDATE_SNAPS_PAGE'); + ftp_close($ftp); + return $res; +} + +function upload_build_result_ftp_curl($src_dir, $target) +{ + include __DIR__ . '/../data/config/credentials_ftps.php'; + + $ftp = ftp_connect($ftp_server); + if (!$ftp) { + echo "Cannot connect to $ftp_server\n"; + return false; + } + $login_result = ftp_login($ftp, $user_snaps, $password); + if (!$login_result) { + return false; + } + ftp_make_directory($ftp, $target. '/logs'); + ftp_close($ftp); + + $curl = array(); + + $ftp_path = $target; + $ftp_user = $user_snaps; + $ftp_password = $password; + + if ($ftp_path[0] != '/') { + $ftp_path = '/' . $ftp_path; + } + $mh = \curl_multi_init(); + + $files = glob($src_dir . '/*.{zip,json}', GLOB_BRACE); + foreach ($files as $i => $local_file) { + + $curl[$i] = $ch = \curl_init(); + $fp = fopen($local_file, "rb"); + $local_file = basename($local_file); + + $remoteurl = "ftps://${ftp_user}:${ftp_password}@${ftp_server}${ftp_path}/${local_file}"; + + \curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + \curl_setopt($ch, CURLOPT_URL, $remoteurl); + \curl_setopt($ch, CURLOPT_UPLOAD, 1); + \curl_setopt($ch, CURLOPT_INFILE, $fp); + \curl_setopt($ch , CURLOPT_USERPWD, $ftp_user . ':' . $ftp_password); + + \curl_multi_add_handle ($mh, $ch); + } + + $files = glob($src_dir . '/logs/*.*'); + $offset = $i + 1; + foreach ($files as $i => $local_file) { + + $ch = $curl[$offset + $i] = \curl_init(); + $fp = fopen($local_file, "rb"); + $local_file = basename($local_file); + + $remoteurl = "ftps://${ftp_user}:${ftp_password}@${ftp_server}${ftp_path}/logs/${local_file}"; + + \curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + \curl_setopt($ch, CURLOPT_URL, $remoteurl); + \curl_setopt($ch, CURLOPT_UPLOAD, 1); + \curl_setopt($ch, CURLOPT_INFILE, $fp); + \curl_setopt($ch , CURLOPT_USERPWD, $ftp_user . ':' . $ftp_password); + + \curl_multi_add_handle ($mh, $ch); + } + + do { + \curl_multi_exec($mh,$active); + } while ($active); + + foreach ($curl as $ch) { + \curl_multi_remove_handle($mh, $ch); + if (\curl_errno($ch) != 0) { + echo \curl_error($ch) . "\n"; + } + \curl_close($ch); + } + //\curl_multi_close($mh); + return true; +} + +function send_error_notification($branch_name, $build_entries, $previous_revision, $current_revision, $url_log) +{ + $errors = ''; + $params = NULL; + $headers = 'From: noreply@php.net' . "\r\n" . + 'Reply-To: noreply@php.net' . "\r\n" . + 'X-Mailer: rmtools/php.net' . "\r\n" . + 'Bcc: pierre.php@gmail.com, felipensp@gmail.com' . "\r\n"; + + foreach ($build_entries as $build_name => $entries) { + $errors .= $branch_name . ', build ' . $build_name . ":\n"; + foreach ($entries as $e) { + $errors .= implode(', ', $e) . "\n"; + } + $errors .= "\n\n"; + } + +// $to = 'internals@lists.php.net'; + $to = 'ostcphp@microsoft.com'; + $subject = '[rmtools][' . $branch_name . '] Build error between r' . $previous_revision . ' and ' . $current_revision; + + ob_start(); + include __DIR__ . '/../template/mail_notification.tpl.php'; + $body = ob_get_contents(); + ob_end_clean(); + + if (substr($to, -7) === 'php.net') { + $params = '-fnoreply@php.net'; + } + + if($params == null){ + return mail($to, $subject, $body, $headers); + }else{ + return mail($to, $subject, $body, $headers, $params); + } +} diff --git a/client/script/snap.php b/client/script/snap.php index 7f3d49b..c3fd506 100644 --- a/client/script/snap.php +++ b/client/script/snap.php @@ -1,143 +1,203 @@ -<?php -include __DIR__ . '/../data/config.php'; -include __DIR__ . '/../include/Branch.php'; -include __DIR__ . '/../include/Tools.php'; - -use rmtools as rm; - -if ($argc < 2 || $argc > 3) { - echo "Usage: snapshot <config name> [force 1/0]\n"; - exit(); -} - -$new_rev = false; -$branch_name = $argv[1]; -$force = isset($argv[2]) ? true : false; -$config_path = __DIR__ . '/../data/config/branch/' . $branch_name . '.ini'; - -$branch = new rm\Branch($config_path); -$branch->update(); - -$branch_name = $branch->config->getName(); -$branch_name_short = $branch->config->getBranch(); -$last_rev = $branch->getLastRevisionId(); - -echo "Running <$config_path>\n"; -echo "\t$branch_name\n"; -echo "\tprevious revision was: " . $branch->getPreviousRevision() . "\n"; -echo "\tlast revision is: " . $branch->getLastRevisionId() . "\n"; - -if ($force || $branch->hasNewRevision()) { - if ($force || $last_rev != $branch->getLastRevisionExported()) { - $new_rev = true; - echo "processing revision $last_rev\n"; - $src_original_path = $branch->createSourceSnap(); - $branch->setLastRevisionExported($last_rev); - - $build_dir_parent = $branch->config->getBuildLocation(); - - if (!is_dir($build_dir_parent)) { - echo "Invalid build location <$build_dir_parent>\n"; - exit(-1); - } - - $toupload_dir = TMP_DIR . '/' . $branch_name . '/r' . $last_rev . '-builds/'; - if (!is_dir($toupload_dir)) { - mkdir($toupload_dir, 0655, true); - } - - if (!is_dir($toupload_dir . '/logs')) { - mkdir($toupload_dir . '/logs', 0655, true); - } - - copy($src_original_path . '.zip', $toupload_dir . '/' . $branch_name . '-src-r'. $last_rev . '.zip'); - - $builds = $branch->getBuildList('windows'); - - $has_build_errors = false; - $build_errors = array(); - - foreach ($builds as $build_name) { - $build_src_path = realpath($build_dir_parent) . DIRECTORY_SEPARATOR . $build_name; - $log = rm\exec_single_log('mklink /J ' . $build_src_path . ' ' . $src_original_path); - - $build = $branch->createBuildInstance($build_name); - echo "running build in <$build_src_path>\n"; - try { - $build->setSourceDir($build_src_path); - $build->buildconf(); - $build->configure(); - $build->make(); - $html_make_log = $build->getMakeLogParsed(); - $build->makeArchive(); - } catch (Exception $e) { - echo $e->getMessage() . "\n"; - echo $build->log_buildconf; - } - - if ($build->archive_path) { - copy($build->archive_path, $toupload_dir . '/php-' . $branch_name_short . '-' . $build_name . '-r'. $last_rev . '.zip'); - } - if ($build->archive_path) { - copy($build->devel_path, $toupload_dir . '/php-devel-pack-' . $branch_name_short . '-' . $build_name . '-r'. $last_rev . '.zip'); - } - if ($build->archive_path) { - copy($build->debug_path, $toupload_dir . '/php-debug-pack-' . $branch_name_short . '-' . $build_name . '-r'. $last_rev . '.zip'); - } - if ($build->test_path) { - $tmp = str_replace(array('-ts', '-nts'), array('',''), $build_name); - copy($build->test_path, $toupload_dir . '/php-test-pack-' . $branch_name_short . '-' . $tmp . '-r'. $last_rev . '.zip'); - } - - file_put_contents($toupload_dir . '/logs/buildconf-' . $build_name . '-r'. $last_rev . '.txt', $build->log_buildconf); - file_put_contents($toupload_dir . '/logs/configure-' . $build_name . '-r'. $last_rev . '.txt', $build->log_configure); - file_put_contents($toupload_dir . '/logs/make-' . $build_name . '-r'. $last_rev . '.txt', $build->log_make); - file_put_contents($toupload_dir . '/logs/archive-' . $build_name . '-r'. $last_rev . '.txt', $build->log_archive); - - $html_make_log = $build->getMakeLogParsed(); - file_put_contents($toupload_dir . '/logs/make-' . $build_name . '-r'. $last_rev . '.html', $html_make_log); - copy(__DIR__ . '/../template/log_style.css', $toupload_dir . '/logs/log_style.css'); - - $stats = $build->getStats(); - - $json_filename = $build_name . '.json'; - - $json_data = array( - 'stats' => $stats, - 'has_php_pkg' => file_exists($build->archive_path), - 'has_debug_pkg' => file_exists($build->debug_path), - 'has_devel_pkg' => file_exists($build->devel_path), - 'has_test_pkg' => file_exists($build->test_path), - ); - - if ($stats['error'] > 0) { - $has_build_errors = true; - $build_errors[$build_name] = $build->compiler_log_parser->getErrors(); - $json_data['build_error'] = $build_errors[$build_name]; - } - - $json = json_encode($json_data); - file_put_contents($toupload_dir . '/' . $json_filename, $json); - - rm\upload_build_result_ftp_curl($toupload_dir, $branch_name . '/r' . $last_rev); -// $build->clean(); -// rmdir($build_src_path); - } - } -} - -if (!$new_rev) { - echo "no new revision.\n"; -} - -/*Upload the branch DB */ -rm\upload_file($branch->db_path, $branch_name . '/' . basename($branch->db_path)); - -if ($has_build_errors) { - rm\send_error_notification($branch_name, $build_errors, $branch->getPreviousRevision(), $last_rev, 'http://windows.php.net/downloads/snaps/' . $branch_name . '/r' . $last_rev); -} else { - /* if no error, let update the snapshot page */ - rm\update_snapshot_page(); -} - -echo "Done.\n"; +<?php +include __DIR__ . '/../data/config.php'; +include __DIR__ . '/../include/Branch.php'; +include __DIR__ . '/../include/Tools.php'; + +use rmtools as rm; + +if ($argc < 3 || $argc > 4) { + echo "Usage: snapshot <config name> <build type> [force 1/0]\n"; + exit(); +} + +$new_rev = false; +$branch_name = $argv[1]; +$build_type = strtolower($argv[2]); +$force = isset($argv[3]) ? true : false; +$config_path = __DIR__ . '/../data/config/branch/' . $branch_name . '.ini'; + +$branch = new rm\Branch($config_path); +$branch->update(); + +$branch_name = $branch->config->getName(); +$branch_name_short = $branch->config->getBranch(); +$last_rev = $branch->getLastRevisionId(); + +echo "Running <$config_path>\n"; +echo "\t$branch_name\n"; +echo "\tprevious revision was: " . $branch->getPreviousRevision() . "\n"; +echo "\tlast revision is: " . $branch->getLastRevisionId() . "\n"; +if ($force || $branch->hasNewRevision()) { + if ($force || substr_compare($last_rev, $branch->getLastRevisionExported(), 0, 7) != 0) { + $new_rev = true; + echo "processing revision $last_rev\n"; + if ($branch->config->getPGO() == 1) { // Check revision to maintain concurrent builds + $fh = fopen('c:\php-sdk\locks\snaps_'.$build_type.'.lock', "a"); + fwrite($fh, "$last_rev"); + fclose($fh); + if (strcmp($build_type, 'nts') == 0) { + if (!file_exists('c:\php-sdk\locks\snaps_ts.lock')) { + echo "Waiting for thread-safe build, exiting.\n"; + exit(0); + } + else { + $fh = fopen('c:\php-sdk\locks\snaps_ts.lock', "r"); + $data = fread($fh, filesize('c:\php-sdk\locks\snaps_ts.lock')); + fclose($fh); + if (!preg_match("/$last_rev/", $data)) { + echo "Revision mismatch on concurrent builds, waiting for ts build to complete\n"; + exit(0); + } + } + } + } + + if (strlen($last_rev) == 40) { + $last_rev = substr($last_rev, 0, 7); + } + $src_original_path = $branch->createSourceSnap($build_type); + $branch->setLastRevisionExported($last_rev); + + $build_dir_parent = $branch->config->getBuildLocation(); + + if (!is_dir($build_dir_parent)) { + echo "Invalid build location <$build_dir_parent>\n"; + exit(-1); + } + + $toupload_dir = TMP_DIR . '/' . $branch_name . '/r' . $last_rev . '-builds/'; + if (!is_dir($toupload_dir)) { + mkdir($toupload_dir, 0655, true); + } + + if (!is_dir($toupload_dir . '/logs')) { + mkdir($toupload_dir . '/logs', 0655, true); + } + + copy($src_original_path . '.zip', $toupload_dir . '/' . $branch_name . '-src-r'. $last_rev . '.zip'); + $builds = $branch->getBuildList('windows'); + + $has_build_errors = false; + $build_errors = array(); + + foreach ($builds as $build_name) { + if (strcmp($build_type, 'all') != 0) { + if (substr_compare($build_name, $build_type, 0, 2) != 0) { // i.e. nts-windows-vc9-x86 + continue; + } + else { + echo "Starting build for $build_name\n"; + } + } + + $build_src_path = realpath($build_dir_parent) . DIRECTORY_SEPARATOR . $build_name; + $log = rm\exec_single_log('mklink /J ' . $build_src_path . ' ' . $src_original_path); + + $build = $branch->createBuildInstance($build_name); + echo "running build in <$build_src_path>\n"; + try { + $build->setSourceDir($build_src_path); + $build->buildconf(); + if ($branch->config->getPGO() == 1) { + echo "Creating PGI build\n"; + $build->configure(' "--enable-pgi" '); + } + else { + $build->configure(); + } + $build->make(); + $html_make_log = $build->getMakeLogParsed(); + $build->makeArchive(); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + echo $build->log_buildconf; + } + if ($branch->config->getPGO() == 1) { + if ($build->archive_path) { + echo "Running pgo_controller.ps1 with PGI build at $build->archive_path, ver=$branch_name\n"; + $cmd = 'c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -Command C:\php-sdk\pgo-build\pgo_controller.ps1 -PHPBUILD '. $build->archive_path . ' -PHPVER ' . $branch_name; + $pgolog = rm\exec_single_log($cmd); + print_r($pgolog); + + echo "Creating PGO build\n"; + try { + $build->make(' clean-pgo'); + $build->configure(' "--with-pgo" ', false); + $build->make(); + $html_make_log = $build->getMakeLogParsed(); + $build->makeArchive(); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + echo $build->log_buildconf; + } + } + } + + if ($build->archive_path) { + copy($build->archive_path, $toupload_dir . '/php-' . $branch_name_short . '-' . $build_name . '-r'. $last_rev . '.zip'); + } + if ($build->archive_path) { + copy($build->devel_path, $toupload_dir . '/php-devel-pack-' . $branch_name_short . '-' . $build_name . '-r'. $last_rev . '.zip'); + } + if ($build->archive_path) { + copy($build->debug_path, $toupload_dir . '/php-debug-pack-' . $branch_name_short . '-' . $build_name . '-r'. $last_rev . '.zip'); + } + if ($build->test_path) { + $tmp = str_replace(array('-ts', '-nts'), array('',''), $build_name); + copy($build->test_path, $toupload_dir . '/php-test-pack-' . $branch_name_short . '-' . $tmp . '-r'. $last_rev . '.zip'); + } + + file_put_contents($toupload_dir . '/logs/buildconf-' . $build_name . '-r'. $last_rev . '.txt', $build->log_buildconf); + file_put_contents($toupload_dir . '/logs/configure-' . $build_name . '-r'. $last_rev . '.txt', $build->log_configure); + file_put_contents($toupload_dir . '/logs/make-' . $build_name . '-r'. $last_rev . '.txt', $build->log_make); + file_put_contents($toupload_dir . '/logs/archive-' . $build_name . '-r'. $last_rev . '.txt', $build->log_archive); + + $html_make_log = $build->getMakeLogParsed(); + file_put_contents($toupload_dir . '/logs/make-' . $build_name . '-r'. $last_rev . '.html', $html_make_log); + copy(__DIR__ . '/../template/log_style.css', $toupload_dir . '/logs/log_style.css'); + + $stats = $build->getStats(); + + $json_filename = $build_name . '.json'; + + $json_data = array( + 'stats' => $stats, + 'has_php_pkg' => file_exists($build->archive_path), + 'has_debug_pkg' => file_exists($build->debug_path), + 'has_devel_pkg' => file_exists($build->devel_path), + 'has_test_pkg' => file_exists($build->test_path), + ); + + if ($stats['error'] > 0) { + $has_build_errors = true; + $build_errors[$build_name] = $build->compiler_log_parser->getErrors(); + $json_data['build_error'] = $build_errors[$build_name]; + } + + if (strcmp($branch_name, 'php-5.4') != 0) { + $json = json_encode($json_data); + file_put_contents($toupload_dir . '/' . $json_filename, $json); + } + + rm\upload_build_result_ftp_curl($toupload_dir, $branch_name . '/r' . $last_rev); +// $build->clean(); + rmdir($build_src_path); + } + } +} + +if (!$new_rev) { + echo "no new revision.\n"; +} + +/*Upload the branch DB */ +//rm\upload_file($branch->db_path, $branch_name . '/' . basename($branch->db_path)); + +if ($has_build_errors) { + rm\send_error_notification($branch_name, $build_errors, $branch->getPreviousRevision(), $last_rev, 'http://windows.php.net/downloads/snaps/' . $branch_name . '/r' . $last_rev); +} else { + /* if no error, let update the snapshot page */ +// rm\update_snapshot_page(); +} + +echo "Done.\n";
« previous php.webmaster (#15641) next »