com web/rmtools: next step - can read a tgz from dir and unpack: client/bin/pecl.bat client/include/PeclBuildVC.php client/include/PeclExt.php
client/include/Tools.php client/script/pecl.php
| From: | Stephen A. Zarkos | Date: | Fri, 30 Aug 2013 11:08:17 +0000 |
| Subject: | com web/rmtools: next step - can read a tgz from dir and unpack: client/bin/pecl.bat client/include/PeclBuildVC.php client/include/PeclExt.php client/include/Tools.php client/script/pecl.php |
||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-16729@lists.php.net to get a copy of this message | ||
Commit: ce71cbbb22052269a88205f74dba709aad30e24d
Author: Anatol Belski <ab@php.net> Fri, 30 Aug 2013 13:08:17 +0200
Parents: 96f6cb3a88dd9fb1aad6b3f9208098c743479b91
Branches: master
Link: http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=ce71cbbb22052269a88205f74dba709aad30e24d
Log:
next step - can read a tgz from dir and unpack
it into the php source dir
Changed paths:
M client/bin/pecl.bat
M client/include/PeclBuildVC.php
A client/include/PeclExt.php
M client/include/Tools.php
M client/script/pecl.php
diff --git a/client/bin/pecl.bat b/client/bin/pecl.bat index 51ed9e9..bd6865b 100644 --- a/client/bin/pecl.bat +++ b/client/bin/pecl.bat @@ -73,7 +73,11 @@ SET VC11_X64_SHELL=%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio REM Run pecl.php SET BISON_SIMPLE=c:\php-sdk\bin\bison.simple -c:\php-sdk\php\php.exe -d extension_dir=c:\php-sdk\php\ext -d extension=php_openssl.dll -d extension=php_curl.dll %BAT_DIR%\..\script\pecl.php pecl53 C:\pecl_in_pkg\dio-0.0.7.tgz +rem XXX iterate the c:\pecl_in_pkg here and delete the packages after successful build +c:\php-sdk\php\php.exe %BAT_DIR%\..\script\pecl.php pecl55_x64 C:\pecl_in_pkg\dio-0.0.7.tgz +rem c:\php-sdk\php\php.exe %BAT_DIR%\..\script\pecl.php pecl55_x86 C:\pecl_in_pkg\dio-0.0.7.tgz +rem c:\php-sdk\php\php.exe %BAT_DIR%\..\script\pecl.php pecl54 C:\pecl_in_pkg\dio-0.0.7.tgz +rem c:\php-sdk\php\php.exe %BAT_DIR%\..\script\pecl.php pecl53 C:\pecl_in_pkg\dio-0.0.7.tgz SET PATH=%OLD_PATH% echo Done.>> %LOG_FILE% diff --git a/client/include/PeclBuildVC.php b/client/include/PeclBuildVC.php index 73c4eff..78cc337 100644 --- a/client/include/PeclBuildVC.php +++ b/client/include/PeclBuildVC.php @@ -32,7 +32,7 @@ class PeclBuildVC { { $this->branch = $branch; $this->build_name = $build_name; - $this->obj_dir = $branch->config->getBuildDir() . '/' . $this->build_name; + $this->obj_dir = $branch->config->getBuildDir() . '/' . $branch->config->getBranch() . '-' . $this->build_name; $this->compiler = $branch->config->builds[$build_name]['compiler']; $this->architecture = $branch->config->builds[$build_name]['arch']; $this->thread_safe = (boolean)$branch->config->builds[$build_name]['thread_safe']; @@ -90,6 +90,11 @@ class PeclBuildVC { $this->build_dir = $src_dir; } + function getSourceDir() + { + return $this->build_dir; + } + private function addLogsToArchive() { $zip = new \ZipArchive(); diff --git a/client/include/PeclExt.php b/client/include/PeclExt.php new file mode 100644 index 0000000..e9ed08a --- /dev/null +++ b/client/include/PeclExt.php @@ -0,0 +1,120 @@ +<?php + +namespace rmtools; + +include_once __DIR__ . '/../include/Tools.php'; +include_once __DIR__ . '/../include/PeclBranch.php'; + +class PeclExt +{ + protected $tgz_path; + protected $name; + protected $version; + protected $build; + protected $tar_cmd = 'c:\apps\git\bin\tar.exe'; + protected $gzip_cmd = 'c:\apps\git\bin\gzip.exe'; + + public function __construct($tgz_path, $build) + { + if (!file_exists($tgz_path)) { + throw new \Exception("'$tgz_path' does not exist"); + } else if ('.tgz' != substr($tgz_path, -4)) { + throw new \Exception("Pecl package should end with .tgz"); + } + + /* Should open package.xml then and retry, but normally the below should work. */ + $tmp = explode('-', basename($tgz_path, '.tgz')); + $this->name = $tmp[0]; + $this->version = $tmp[1]; + + if (!$this->name || !$this->version) { + throw new \Exception("Couldn't parse extension name or version from the filename"); + } + + $this->tgz_path = $tgz_path; + $this->build = $build; + } + + public function getPackageName() + { + // looks like php_http-2.0.0beta4-5.3-nts-vc9-x86 + return 'php_' . $this->name + . '-' . $this->version + . '-' . $this->build->branch->config->getBranch() + . '-' . ($this->build->thread_safe ? 'ts' : 'nts') + . '-' . $this->build->compiler + . '-' . $this->build->architecture; + } + + public function unpack() + { + $tmp_path = TMP_DIR . '/' . $this->getPackageName(); + if (!file_exists($tmp_path) && !mkdir($tmp_path)) { + throw new \Exception("Couldn't create temporary dir"); + } + + + $tmp_name = $tmp_path . '/' . basename($this->tgz_path); + if (!rename($this->tgz_path, $tmp_name)) { + throw new \Exception("Couldn't move the tarball to '$tmp_name'"); + } + + $tar_name = basename($this->tgz_path, '.tgz') . '.tar'; + + /* The tar/gzip versions from the msys package won't work properly with + the windows paths, but they will if running those just in the current dir.*/ + $old_cwd = getcwd(); + + chdir($tmp_path); + + $gzip_cmd = $this->gzip_cmd . ' -df ' . basename($this->tgz_path); + system($gzip_cmd, $ret); + if ($ret) { + throw new \Exception("Failed to guzip the tarball"); + } + + $tar_cmd = $this->tar_cmd . ' -xf ' . $tar_name; + system($tar_cmd, $ret); + if ($ret) { + throw new \Exception("Failed to guzip the tarball"); + } + unlink($tar_name); + + chdir($old_cwd); + + $ret = realpath($tmp_path . '/' . basename($this->tgz_path, '.tgz')); + + $this->tgz_path = NULL; + + return $ret; + } + + public function putSourcesIntoBranch() + { + $tmp_path = $this->unpack(); + $ext_dir = $this->build->getSourceDir() . DIRECTORY_SEPARATOR . 'ext'; + + $this_ext_dir_path = $ext_dir . DIRECTORY_SEPARATOR . $this->name; + $res = copy_r($tmp_path, $this_ext_dir_path); + if (!$res) { + throw new \Exception("Failed to copy to '$this_ext_dir_path'"); + } + rmdir_rf($tmp_path); + + return $this_ext_dir_path; + } + + public function __call($name, $args) + { + if ('get' == substr($name, 0, 3)) { + $prop_name = strtolower(substr($name, 3)); + if (isset($this->$prop_name)) { + return $this->$prop_name; + } else { + return NULL; + } + } + + throw new \Exception("Unknown dynamic method called"); + } +} diff --git a/client/include/Tools.php b/client/include/Tools.php index f6605ec..5084793 100644 --- a/client/include/Tools.php +++ b/client/include/Tools.php @@ -298,3 +298,36 @@ function send_error_notification($branch_name, $build_entries, $previous_revisio return mail($to, $subject, $body, $headers, $params); } } + +function copy_r($from, $to) +{ + if (is_dir($from)) { + if (!file_exists($to)) { + mkdir($to); + } + $objs = scandir($from); + foreach ($objs as $child) { + if ('.' == $child || '..' == $child) { + continue; + } + + if (is_dir("$from/$child")) { + if (!copy_r("$from/$child", "$to/$child")) { + return false; + } + } else { + if (!copy("$from/$child", "$to/$child")) { + return false; + } + } + } + + return true; + + } else if (is_file($from)) { + return copy($from, $to); + } + + return false; +} + diff --git a/client/script/pecl.php b/client/script/pecl.php index 1599104..98e775e 100644 --- a/client/script/pecl.php +++ b/client/script/pecl.php @@ -2,6 +2,7 @@ include __DIR__ . '/../data/config.php'; include __DIR__ . '/../include/PeclBranch.php'; include __DIR__ . '/../include/Tools.php'; +include __DIR__ . '/../include/PeclExt.php'; use rmtools as rm; @@ -14,18 +15,6 @@ $branch_name = $argv[1]; $ext_tgz = $argv[2]; $config_path = __DIR__ . '/../data/config/pecl/' . $branch_name . '.ini'; -if (!file_exists($ext_tgz)) { - echo "'$ext_tgz' does not exist\n"; - exit(3); -} -if ('.tgz' != substr($ext_tgz, -4)) { - echo "Pecl package should end with .tgz\n"; - exit(3); -} -$tmp = explode('-', basename($ext_tgz, '.tgz')); -$ext_name = $tmp[0]; -$ext_ver = $tmp[1]; -unset($tmp); $branch = new rm\PeclBranch($config_path); @@ -54,14 +43,16 @@ foreach ($builds as $build_name) { $build = $branch->createBuildInstance($build_name); + try { + $ext = new rm\PeclExt($ext_tgz, $build); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + exit(3); + } + // looks like php_http-2.0.0beta4-5.3-nts-vc9-x86 - $ext_build_name = 'php_' . $ext_name - . '-' . $ext_ver - . '-' . $branch_name - . '-' . ($build->thread_safe ? 'ts' : 'nts') - . '-' . $build->compiler - . '-' . $build->architecture; - + $ext_build_name = $ext->getPackageName(); + echo "Starting build for $ext_build_name\n"; echo "running build in <$build_src_path>\n"; @@ -76,6 +67,7 @@ foreach ($builds as $build_name) { try { $build->setSourceDir($build_src_path); + $ext->putSourcesIntoBranch();exit(); $build->buildconf(); if ($branch->config->getPGO() == 1) { echo "Creating PGI build\n"; @@ -86,8 +78,7 @@ foreach ($builds as $build_name) { } $build->make(); $html_make_log = $build->getMakeLogParsed(); - continue; - $build->makeArchive(); + //$build->makeArchive(); } catch (Exception $e) { echo $e->getMessage() . "\n"; echo $build->log_buildconf; @@ -96,29 +87,15 @@ foreach ($builds as $build_name) { /* PGO stuff would come here */ - $stats = $build->getStats(); - - $json_filename = $build_config['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), - ); + /*$stats = $build->getStats(); if ($stats['error'] > 0) { $has_build_errors = true; - $build_errors[$build_config['name']] = $build->compiler_log_parser->getErrors(); - $json_data['build_error'] = $build_errors[$build_config['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); + rm\upload_build_result_ftp_curl($toupload_dir, $branch_name . '/r' . $last_rev);*/ + $build->clean(); + //rmdir($build_src_path); } /*Upload the branch DB */
diff --git a/client/bin/pecl.bat b/client/bin/pecl.bat index 51ed9e9..bd6865b 100644 --- a/client/bin/pecl.bat +++ b/client/bin/pecl.bat @@ -73,7 +73,11 @@ SET VC11_X64_SHELL=%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio REM Run pecl.php SET BISON_SIMPLE=c:\php-sdk\bin\bison.simple -c:\php-sdk\php\php.exe -d extension_dir=c:\php-sdk\php\ext -d extension=php_openssl.dll -d extension=php_curl.dll %BAT_DIR%\..\script\pecl.php pecl53 C:\pecl_in_pkg\dio-0.0.7.tgz +rem XXX iterate the c:\pecl_in_pkg here and delete the packages after successful build +c:\php-sdk\php\php.exe %BAT_DIR%\..\script\pecl.php pecl55_x64 C:\pecl_in_pkg\dio-0.0.7.tgz +rem c:\php-sdk\php\php.exe %BAT_DIR%\..\script\pecl.php pecl55_x86 C:\pecl_in_pkg\dio-0.0.7.tgz +rem c:\php-sdk\php\php.exe %BAT_DIR%\..\script\pecl.php pecl54 C:\pecl_in_pkg\dio-0.0.7.tgz +rem c:\php-sdk\php\php.exe %BAT_DIR%\..\script\pecl.php pecl53 C:\pecl_in_pkg\dio-0.0.7.tgz SET PATH=%OLD_PATH% echo Done.>> %LOG_FILE% diff --git a/client/include/PeclBuildVC.php b/client/include/PeclBuildVC.php index 73c4eff..78cc337 100644 --- a/client/include/PeclBuildVC.php +++ b/client/include/PeclBuildVC.php @@ -32,7 +32,7 @@ class PeclBuildVC { { $this->branch = $branch; $this->build_name = $build_name; - $this->obj_dir = $branch->config->getBuildDir() . '/' . $this->build_name; + $this->obj_dir = $branch->config->getBuildDir() . '/' . $branch->config->getBranch() . '-' . $this->build_name; $this->compiler = $branch->config->builds[$build_name]['compiler']; $this->architecture = $branch->config->builds[$build_name]['arch']; $this->thread_safe = (boolean)$branch->config->builds[$build_name]['thread_safe']; @@ -90,6 +90,11 @@ class PeclBuildVC { $this->build_dir = $src_dir; } + function getSourceDir() + { + return $this->build_dir; + } + private function addLogsToArchive() { $zip = new \ZipArchive(); diff --git a/client/include/PeclExt.php b/client/include/PeclExt.php new file mode 100644 index 0000000..e9ed08a --- /dev/null +++ b/client/include/PeclExt.php @@ -0,0 +1,120 @@ +<?php + +namespace rmtools; + +include_once __DIR__ . '/../include/Tools.php'; +include_once __DIR__ . '/../include/PeclBranch.php'; + +class PeclExt +{ + protected $tgz_path; + protected $name; + protected $version; + protected $build; + protected $tar_cmd = 'c:\apps\git\bin\tar.exe'; + protected $gzip_cmd = 'c:\apps\git\bin\gzip.exe'; + + public function __construct($tgz_path, $build) + { + if (!file_exists($tgz_path)) { + throw new \Exception("'$tgz_path' does not exist"); + } else if ('.tgz' != substr($tgz_path, -4)) { + throw new \Exception("Pecl package should end with .tgz"); + } + + /* Should open package.xml then and retry, but normally the below should work. */ + $tmp = explode('-', basename($tgz_path, '.tgz')); + $this->name = $tmp[0]; + $this->version = $tmp[1]; + + if (!$this->name || !$this->version) { + throw new \Exception("Couldn't parse extension name or version from the filename"); + } + + $this->tgz_path = $tgz_path; + $this->build = $build; + } + + public function getPackageName() + { + // looks like php_http-2.0.0beta4-5.3-nts-vc9-x86 + return 'php_' . $this->name + . '-' . $this->version + . '-' . $this->build->branch->config->getBranch() + . '-' . ($this->build->thread_safe ? 'ts' : 'nts') + . '-' . $this->build->compiler + . '-' . $this->build->architecture; + } + + public function unpack() + { + $tmp_path = TMP_DIR . '/' . $this->getPackageName(); + if (!file_exists($tmp_path) && !mkdir($tmp_path)) { + throw new \Exception("Couldn't create temporary dir"); + } + + + $tmp_name = $tmp_path . '/' . basename($this->tgz_path); + if (!rename($this->tgz_path, $tmp_name)) { + throw new \Exception("Couldn't move the tarball to '$tmp_name'"); + } + + $tar_name = basename($this->tgz_path, '.tgz') . '.tar'; + + /* The tar/gzip versions from the msys package won't work properly with + the windows paths, but they will if running those just in the current dir.*/ + $old_cwd = getcwd(); + + chdir($tmp_path); + + $gzip_cmd = $this->gzip_cmd . ' -df ' . basename($this->tgz_path); + system($gzip_cmd, $ret); + if ($ret) { + throw new \Exception("Failed to guzip the tarball"); + } + + $tar_cmd = $this->tar_cmd . ' -xf ' . $tar_name; + system($tar_cmd, $ret); + if ($ret) { + throw new \Exception("Failed to guzip the tarball"); + } + unlink($tar_name); + + chdir($old_cwd); + + $ret = realpath($tmp_path . '/' . basename($this->tgz_path, '.tgz')); + + $this->tgz_path = NULL; + + return $ret; + } + + public function putSourcesIntoBranch() + { + $tmp_path = $this->unpack(); + $ext_dir = $this->build->getSourceDir() . DIRECTORY_SEPARATOR . 'ext'; + + $this_ext_dir_path = $ext_dir . DIRECTORY_SEPARATOR . $this->name; + $res = copy_r($tmp_path, $this_ext_dir_path); + if (!$res) { + throw new \Exception("Failed to copy to '$this_ext_dir_path'"); + } + rmdir_rf($tmp_path); + + return $this_ext_dir_path; + } + + public function __call($name, $args) + { + if ('get' == substr($name, 0, 3)) { + $prop_name = strtolower(substr($name, 3)); + if (isset($this->$prop_name)) { + return $this->$prop_name; + } else { + return NULL; + } + } + + throw new \Exception("Unknown dynamic method called"); + } +} diff --git a/client/include/Tools.php b/client/include/Tools.php index f6605ec..5084793 100644 --- a/client/include/Tools.php +++ b/client/include/Tools.php @@ -298,3 +298,36 @@ function send_error_notification($branch_name, $build_entries, $previous_revisio return mail($to, $subject, $body, $headers, $params); } } + +function copy_r($from, $to) +{ + if (is_dir($from)) { + if (!file_exists($to)) { + mkdir($to); + } + $objs = scandir($from); + foreach ($objs as $child) { + if ('.' == $child || '..' == $child) { + continue; + } + + if (is_dir("$from/$child")) { + if (!copy_r("$from/$child", "$to/$child")) { + return false; + } + } else { + if (!copy("$from/$child", "$to/$child")) { + return false; + } + } + } + + return true; + + } else if (is_file($from)) { + return copy($from, $to); + } + + return false; +} + diff --git a/client/script/pecl.php b/client/script/pecl.php index 1599104..98e775e 100644 --- a/client/script/pecl.php +++ b/client/script/pecl.php @@ -2,6 +2,7 @@ include __DIR__ . '/../data/config.php'; include __DIR__ . '/../include/PeclBranch.php'; include __DIR__ . '/../include/Tools.php'; +include __DIR__ . '/../include/PeclExt.php'; use rmtools as rm; @@ -14,18 +15,6 @@ $branch_name = $argv[1]; $ext_tgz = $argv[2]; $config_path = __DIR__ . '/../data/config/pecl/' . $branch_name . '.ini'; -if (!file_exists($ext_tgz)) { - echo "'$ext_tgz' does not exist\n"; - exit(3); -} -if ('.tgz' != substr($ext_tgz, -4)) { - echo "Pecl package should end with .tgz\n"; - exit(3); -} -$tmp = explode('-', basename($ext_tgz, '.tgz')); -$ext_name = $tmp[0]; -$ext_ver = $tmp[1]; -unset($tmp); $branch = new rm\PeclBranch($config_path); @@ -54,14 +43,16 @@ foreach ($builds as $build_name) { $build = $branch->createBuildInstance($build_name); + try { + $ext = new rm\PeclExt($ext_tgz, $build); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + exit(3); + } + // looks like php_http-2.0.0beta4-5.3-nts-vc9-x86 - $ext_build_name = 'php_' . $ext_name - . '-' . $ext_ver - . '-' . $branch_name - . '-' . ($build->thread_safe ? 'ts' : 'nts') - . '-' . $build->compiler - . '-' . $build->architecture; - + $ext_build_name = $ext->getPackageName(); + echo "Starting build for $ext_build_name\n"; echo "running build in <$build_src_path>\n"; @@ -76,6 +67,7 @@ foreach ($builds as $build_name) { try { $build->setSourceDir($build_src_path); + $ext->putSourcesIntoBranch();exit(); $build->buildconf(); if ($branch->config->getPGO() == 1) { echo "Creating PGI build\n"; @@ -86,8 +78,7 @@ foreach ($builds as $build_name) { } $build->make(); $html_make_log = $build->getMakeLogParsed(); - continue; - $build->makeArchive(); + //$build->makeArchive(); } catch (Exception $e) { echo $e->getMessage() . "\n"; echo $build->log_buildconf; @@ -96,29 +87,15 @@ foreach ($builds as $build_name) { /* PGO stuff would come here */ - $stats = $build->getStats(); - - $json_filename = $build_config['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), - ); + /*$stats = $build->getStats(); if ($stats['error'] > 0) { $has_build_errors = true; - $build_errors[$build_config['name']] = $build->compiler_log_parser->getErrors(); - $json_data['build_error'] = $build_errors[$build_config['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); + rm\upload_build_result_ftp_curl($toupload_dir, $branch_name . '/r' . $last_rev);*/ + $build->clean(); + //rmdir($build_src_path); } /*Upload the branch DB */