Skip to content

Commit

Permalink
Sync the generation scripts as much as possible + various cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
helgi committed Jul 29, 2009
1 parent f30b097 commit 6e7c677
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 45 deletions.
61 changes: 36 additions & 25 deletions make-gopear-phar.php
Expand Up @@ -4,7 +4,7 @@
*
* PHP version 5.1+
*
* To use, in pear-core/PEAR create a directory
* To use, in pear-core create a directory
* named go-pear-tarballs, and run these commands in the directory
*
* <pre>
Expand All @@ -18,7 +18,7 @@
* Next, check out pear/Structure_Graph and copy it into pear-core/
*
* Next, check out pear/Console_Getopt and copy it into pear-core/
*
*
* Next, check out pear/XML_Util and copy it into pear-core/
*
* finally, run this script using PHP 5.1's cli php
Expand All @@ -32,29 +32,38 @@
* @version CVS: $Id$
*/

$peardir = dirname(__FILE__);
function replaceVersion($contents, $path)
{
return str_replace(array('@PEAR-VER@', '@package_version@'), $GLOBALS['pearver'], $contents);
}

$peardir = dirname(__FILE__);
$outputFile = 'go-pear.phar';

$dp = @opendir(dirname(__FILE__) . '/PEAR/go-pear-tarballs');
if (empty($dp)) {
die("while locating packages to install: opendir('" .
dirname(__FILE__) . "/PEAR/go-pear-tarballs') failed");
$dp = @scandir($peardir . '/go-pear-tarballs');
if ($dp === false) {
die("while locating packages to install: opendir('" . $peardir . "/go-pear-tarballs') failed");
}

$packages = array();
while (false !== ($entry = readdir($dp))) {
foreach ($dp as $entry) {
if ($entry{0} == '.' || !in_array(substr($entry, -4), array('.tar'))) {
continue;
}

$packages[] = $entry;
}
$x = explode(PATH_SEPARATOR, get_include_path());

$y = array();
foreach ($x as $path) {
foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) {
if ($path == '.') {
continue;
}

$y[] = $path;
}
// remove current dir, we will otherwise include CVS files, which is not good

// remove current dir, we will otherwise include SVN files, which is not good
set_include_path(implode(PATH_SEPARATOR, $y));
require_once 'PEAR/PackageFile.php';
require_once 'PEAR/Config.php';
Expand All @@ -73,27 +82,26 @@
}
$pearver = $pf->getVersion();

$creator = new PHP_Archive_Creator('index.php', 'go-pear.phar');
$creator = new PHP_Archive_Creator('index.php', $outputFile); // no compression
$creator->useDefaultFrontController('PEAR.php');
$creator->useSHA1Signature();

foreach ($packages as $package) {
echo "adding PEAR/go-pear-tarballs/$package\n";
$creator->addFile("PEAR/go-pear-tarballs/$package", "PEAR/go-pear-tarballs/$package");
echo "adding go-pear-tarballs/$package\n";
$creator->addFile("go-pear-tarballs/$package", "go-pear-tarballs/$package");
}

$commandcontents = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'go-pear-phar.php');
$commandcontents = str_replace('require_once \'', 'require_once \'phar://go-pear.phar/', $commandcontents);
$commandcontents = str_replace('require_once \'', 'require_once \'phar://' . $outputFile . '/', $commandcontents);
$creator->addString($commandcontents, 'index.php');

function replaceVersion($contents, $path)
{
return str_replace(array('@PEAR-VER@', '@package_version@'), $GLOBALS['pearver'], $contents);
}
$commandcontents = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . '/PEAR/Frontend.php');
$commandcontents = str_replace(
array(
"\$file = str_replace('_', '/', \$uiclass) . '.php';"
),
array(
"\$file = 'phar://go-pear.phar/' . str_replace('_', '/', \$uiclass) . '.php';"
"\$file = 'phar://' . $outputFile . '/' . str_replace('_', '/', \$uiclass) . '.php';"
), $commandcontents);
$commandcontents = replaceVersion($commandcontents, '');
$creator->addString($commandcontents, 'PEAR/Frontend.php');
Expand All @@ -104,7 +112,7 @@ function replaceVersion($contents, $path)
'$fp = @fopen("PEAR/Task/$taskfile.php", \'r\', true);',
),
array(
'$fp = @fopen("phar://go-pear.phar/PEAR/Task/$taskfile.php", \'r\', true);'
'$fp = @fopen("phar://' . $outputFile . '/PEAR/Task/$taskfile.php", \'r\', true);'
), $commandcontents);
$commandcontents = replaceVersion($commandcontents, '');
$commandcontents = $creator->tokenMagicRequire($commandcontents, 'a.php');
Expand Down Expand Up @@ -174,16 +182,19 @@ function replaceVersion($contents, $path)
'*PEAR/Validate.php',
'*PEAR/XMLParser.php',
), false, $peardir);

$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'PEAR.php', 'PEAR.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'PEAR5.php', 'PEAR5.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'System.php', 'System.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'OS/Guess.php', 'OS/Guess.php');

$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Archive/Tar.php', 'Archive/Tar.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'XML_Util/Util.php', 'XML/Util.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Console/Getopt.php', 'Console/Getopt.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'System.php', 'System.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'OS/Guess.php', 'OS/Guess.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph.php', 'Structures/Graph.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph/Node.php', 'Structures/Graph/Node.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph/Manipulator/AcyclicTest.php', 'Structures/Graph/Manipulator/AcyclicTest.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph/Manipulator/TopologicalSorter.php', 'Structures/Graph/Manipulator/TopologicalSorter.php');

$creator->useSHA1Signature();
$creator->savePhar(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'go-pear.phar');
?>
$creator->savePhar(dirname(__FILE__) . DIRECTORY_SEPARATOR . $outputFile);
49 changes: 29 additions & 20 deletions make-installpear-nozlib-phar.php
Expand Up @@ -4,7 +4,7 @@
*
* PHP version 5.1+
*
* To use, in pear-core/PEAR create a directory
* To use, in pear-core create a directory
* named go-pear-tarballs, and run these commands in the directory
*
* <pre>
Expand Down Expand Up @@ -38,34 +38,36 @@ function replaceVersion($contents, $path)
return str_replace(array('@PEAR-VER@', '@package_version@'), $GLOBALS['pearver'], $contents);
}

$peardir = dirname(__FILE__);
$peardir = dirname(__FILE__);
$outputFile = 'install-pear-nozlib.phar';

$dp = @opendir(dirname(__FILE__) . '/PEAR/go-pear-tarballs');
if (empty($dp)) {
die("while locating packages to install: opendir('" .
dirname(__FILE__) . "/PEAR/go-pear-tarballs') failed");
$dp = @scandir($peardir . '/go-pear-tarballs');
if ($dp === false) {
die("while locating packages to install: opendir('" . $peardir . "/go-pear-tarballs') failed");
}

$packages = array();
while (false !== ($entry = readdir($dp))) {
foreach ($dp as $entry) {
if ($entry{0} == '.' || !in_array(substr($entry, -4), array('.tar'))) {
continue;
}

ereg('([A-Za-z0-9_:]+)-.*\.tar$', $entry, $matches);
if ($matches[1] == 'PEAR') {
$pearentry = $entry;
continue;
$pearentry = $entry;
continue;
}

$packages[$matches[1]] = $entry;
}

$packages['PEAR'] = $pearentry;
$x = explode(PATH_SEPARATOR, get_include_path());

$y = array();
foreach ($x as $path) {
foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) {
if ($path == '.') {
continue;
}

$y[] = $path;
}

Expand All @@ -80,16 +82,23 @@ function replaceVersion($contents, $path)

$pkg = &new PEAR_PackageFile($config);
$pf = $pkg->fromPackageFile($peardir . DIRECTORY_SEPARATOR . 'package2.xml', PEAR_VALIDATE_NORMAL);
if (PEAR::isError($pf)) {
foreach ($pf->getUserInfo() as $warn) {
echo $warn['message'] . "\n";
}
die($pf->getMessage());
}
$pearver = $pf->getVersion();

$creator = new PHP_Archive_Creator('index.php', 'install-pear-nozlib.phar'); // no compression
$creator = new PHP_Archive_Creator('index.php', $outputFile); // no compression
$creator->useDefaultFrontController('PEAR.php');
$creator->useSHA1Signature();

$install_files = '$install_files = array(';
foreach ($packages as $name => $package) {
echo "$name => $package\n";
$install_files .= "'$name' => 'phar://install-pear-nozlib.phar/$package'," . "\n";
$creator->addFile("PEAR/go-pear-tarballs/$package", "$package");
$install_files .= "'$name' => 'phar://' . $outputFile . '/$package'," . "\n";
$creator->addFile("go-pear-tarballs/$package", "$package");
}

$install_files .= ');';
Expand All @@ -102,7 +111,7 @@ function replaceVersion($contents, $path)
'$install_files = array();'
),
array(
'include_once \'phar://install-pear-nozlib.phar/',
'include_once \'phar://' . $outputFile . '/',
$install_files
), $commandcontents);
$creator->addString($commandcontents, 'index.php');
Expand All @@ -113,7 +122,7 @@ function replaceVersion($contents, $path)
"\$file = str_replace('_', '/', \$uiclass) . '.php';"
),
array(
"\$file = 'phar://install-pear-nozlib.phar/' . str_replace('_', '/', \$uiclass) . '.php';"
"\$file = 'phar://' . $outputFile . '/' . str_replace('_', '/', \$uiclass) . '.php';"
), $commandcontents);
$commandcontents = replaceVersion($commandcontents, '');
$creator->addString($commandcontents, 'PEAR/Frontend.php');
Expand All @@ -124,7 +133,7 @@ function replaceVersion($contents, $path)
'$fp = @fopen("PEAR/Task/$taskfile.php", \'r\', true);',
),
array(
'$fp = @fopen("phar://install-pear-nozlib.phar/PEAR/Task/$taskfile.php", \'r\', true);'
'$fp = @fopen("phar://' . $outputFile . '/PEAR/Task/$taskfile.php", \'r\', true);'
), $commandcontents);
$commandcontents = replaceVersion($commandcontents, '');
$commandcontents = $creator->tokenMagicRequire($commandcontents, 'a.php');
Expand Down Expand Up @@ -207,6 +216,6 @@ function replaceVersion($contents, $path)
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph/Node.php', 'Structures/Graph/Node.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph/Manipulator/AcyclicTest.php', 'Structures/Graph/Manipulator/AcyclicTest.php');
$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph/Manipulator/TopologicalSorter.php', 'Structures/Graph/Manipulator/TopologicalSorter.php');

$creator->useSHA1Signature();
$creator->savePhar(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'install-pear-nozlib.phar');
?>
$creator->savePhar(dirname(__FILE__) . DIRECTORY_SEPARATOR . $outputFile);

0 comments on commit 6e7c677

Please sign in to comment.