Skip to content

Commit

Permalink
- Move boilerplate include_path handling to top
Browse files Browse the repository at this point in the history
- Make sure we always have the required packages in .tar in go-pear-tarballs directory
- untar the require package tars and use those to create the phar files instead of requiring static files (oldest iterations) or svn externals / git submodules (previous iteration)
- Use PEAR from the .tar instead of the current path. Forces one to package up the release first before making a phar
- Include all of the PEAR/* instead of attempting to do a explicit list of files to include
  • Loading branch information
helgi committed Dec 29, 2011
1 parent 65be351 commit 08b66a2
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 178 deletions.
157 changes: 68 additions & 89 deletions make-gopear-phar.php
@@ -1,4 +1,6 @@
<?php
error_reporting(1803);

/**
* go-pear.phar creator. Requires PHP_Archive version 0.11.0 or newer
*
Expand All @@ -22,47 +24,73 @@
* @version CVS: $Id$
*/

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

$y[] = $path;
}

// remove current dir, we will otherwise include git files, which is not good
set_include_path(implode(PATH_SEPARATOR, $y));
require_once 'PEAR/PackageFile.php';
require_once 'PEAR/Config.php';
require_once 'PHP/Archive/Creator.php';
$config = &PEAR_Config::singleton();

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

$outputFile = 'go-pear.phar';

$dp = @scandir(__DIR__ . '/go-pear-tarballs');
$tardir = __DIR__ . '/go-pear-tarballs';
$dp = @scandir($tardir);
if ($dp === false) {
die("while locating packages to install: opendir('" . __DIR__ . "/go-pear-tarballs') failed\n");
die("while locating packages to install: scandir('" . $tardir. "') failed\n");
}

$required = array('Archive_Tar', 'Console_Getopt', 'PEAR', 'Structures_Graph', 'XML_Util');
$packages = array();
foreach ($dp as $entry) {
if ($entry{0} == '.' || !in_array(substr($entry, -4), array('.tar'))) {
continue;
}

$package = strstr($entry, '-', true);
$key = array_search($package, $required);
if ($key !== false) {
unset($required[$key]);
}

$packages[] = $entry;
}

$y = array();
foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) {
if ($path == '.') {
continue;
}
if (!empty($required)) {
die('Following packages were not available in tar format in go-pear-tarballs: ' . implode(', ', $required). "\n");
}

$y[] = $path;
if (!file_exists("$tardir/tmp")) {
mkdir("$tardir/tmp");
}

// 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';
require_once 'PHP/Archive/Creator.php';
$config = &PEAR_Config::singleton();
// Use the tar files for required Phar files
require_once 'Archive/Tar.php';
require_once 'System.php';

foreach ($packages as $package) {
$name = substr($package, 0, -4);
$tar = new Archive_Tar("$tardir/$package");
$tar->extractModify("$tardir/tmp", $name);
}

chdir(__DIR__);

$pkg = new PEAR_PackageFile($config);
$pf = $pkg->fromPackageFile(__DIR__ . DIRECTORY_SEPARATOR . 'package2.xml', PEAR_VALIDATE_NORMAL);
$pf = $pkg->fromPackageFile($tardir . '/tmp/package2.xml', PEAR_VALIDATE_NORMAL);
if (PEAR::isError($pf)) {
foreach ($pf->getUserInfo() as $warn) {
echo $warn['message'] . "\n";
Expand All @@ -81,11 +109,11 @@ function replaceVersion($contents, $path)
$creator->addFile("go-pear-tarballs/$package", "PEAR/go-pear-tarballs/$package");
}

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

$commandcontents = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '/PEAR/Frontend.php');
$commandcontents = file_get_contents($tardir . '/tmp/PEAR/Frontend.php');
$commandcontents = str_replace(
array(
"\$file = str_replace('_', '/', \$uiclass) . '.php';"
Expand All @@ -96,7 +124,7 @@ function replaceVersion($contents, $path)
$commandcontents = replaceVersion($commandcontents, '');
$creator->addString($commandcontents, 'PEAR/Frontend.php');

$commandcontents = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '/PEAR/PackageFile/v2.php');
$commandcontents = file_get_contents($tardir . '/tmp/PEAR/PackageFile/v2.php');
$commandcontents = str_replace(
array(
'$fp = @fopen("PEAR/Task/$taskfile.php", \'r\', true);',
Expand All @@ -110,83 +138,34 @@ function replaceVersion($contents, $path)

$creator->addMagicRequireCallback(array($creator, 'limitedSmartMagicRequire'));
$creator->addMagicRequireCallback('replaceVersion');
$creator->addFile(__DIR__ . '/PEAR/Command.php', 'PEAR/Command.php');
$creator->addFile($tardir . '/tmp/PEAR/Command.php', 'PEAR/Command.php');

$creator->clearMagicRequire();
$creator->addMagicRequireCallback(array($creator, 'tokenMagicRequire'));
$creator->addMagicRequireCallback('replaceVersion');
$creator->addDir(__DIR__ . DIRECTORY_SEPARATOR . 'PEAR', array(),
array(
'*PEAR/Dependency2.php',
'*PEAR/PackageFile/Generator/v1.php',
'*PEAR/PackageFile/Generator/v2.php',
'*PEAR/PackageFile/v2/Validator.php',
'*PEAR/Downloader/Package.php',
'*PEAR/Installer/Role.php',
'*PEAR/ChannelFile/Parser.php',
'*PEAR/Command/Install.xml',
'*PEAR/Command/Install.php',
'*PEAR/Downloader/Package.php',
'*PEAR/Frontend/CLI.php',
'*PEAR/Installer/Role/Common.php',
'*PEAR/Installer/Role/Data.php',
'*PEAR/Installer/Role/Doc.php',
'*PEAR/Installer/Role/Php.php',
'*PEAR/Installer/Role/Script.php',
'*PEAR/Installer/Role/Test.php',
'*PEAR/Installer/Role/Data.xml',
'*PEAR/Installer/Role/Doc.xml',
'*PEAR/Installer/Role/Php.xml',
'*PEAR/Installer/Role/Script.xml',
'*PEAR/Installer/Role/Test.xml',
'*PEAR/PackageFile.php',
'*PEAR/PackageFile/v1.php',
'*PEAR/PackageFile/Parser/v1.php',
'*PEAR/PackageFile/Parser/v2.php',
'*PEAR/PackageFile/Generator/v1.php',
'*PEAR/REST.php',
'*PEAR/REST/10.php',
'*PEAR/Task/Common.php',
'*PEAR/Task/Postinstallscript.php',
'*PEAR/Task/Postinstallscript/rw.php',
'*PEAR/Task/Replace.php',
'*PEAR/Task/Replace/rw.php',
'*PEAR/Task/Windowseol.php',
'*PEAR/Task/Windowseol/rw.php',
'*PEAR/Task/Unixeol.php',
'*PEAR/Task/Unixeol/rw.php',
'*PEAR/Validator/PECL.php',
'*PEAR/ChannelFile.php',
'*PEAR/Command/Common.php',
'*PEAR/Common.php',
'*PEAR/Config.php',
'*PEAR/Dependency2.php',
'*PEAR/DependencyDB.php',
'*PEAR/Downloader.php',
'*PEAR/ErrorStack.php',
'*PEAR/Installer.php',
'*PEAR/Registry.php',
'*PEAR/Remote.php',
'*PEAR/Start.php',
'*PEAR/Start/CLI.php',
'*PEAR/Validate.php',
'*PEAR/XMLParser.php',
), false, __DIR__);

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

$creator->addDir($tardir . '/tmp/PEAR', array(), array('*PEAR/*'), false, $tardir . '/tmp');

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

// Other packages
$creator->addFile(__DIR__ . DIRECTORY_SEPARATOR . 'PEAR/Exception.php', 'PEAR/Exception.php');
$creator->addFile(__DIR__ . DIRECTORY_SEPARATOR . 'Archive/Tar.php', 'Archive/Tar.php');
$creator->addFile(__DIR__ . DIRECTORY_SEPARATOR . 'XML_Util/Util.php', 'XML/Util.php');
$creator->addFile(__DIR__ . DIRECTORY_SEPARATOR . 'Console/Getopt.php', 'Console/Getopt.php');
$creator->addFile(__DIR__ . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph.php', 'Structures/Graph.php');
$creator->addFile(__DIR__ . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph/Node.php', 'Structures/Graph/Node.php');
$creator->addFile(__DIR__ . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph/Manipulator/AcyclicTest.php', 'Structures/Graph/Manipulator/AcyclicTest.php');
$creator->addFile(__DIR__ . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph/Manipulator/TopologicalSorter.php', 'Structures/Graph/Manipulator/TopologicalSorter.php');
$creator->addFile($tardir . '/tmp/PEAR/Exception.php', 'PEAR/Exception.php');
$creator->addFile($tardir . '/tmp/Archive/Tar.php', 'Archive/Tar.php');
$creator->addFile($tardir . '/tmp/Util.php', 'XML/Util.php');
$creator->addFile($tardir . '/tmp/Console/Getopt.php', 'Console/Getopt.php');
$creator->addFile($tardir . '/tmp/Structures/Graph.php', 'Structures/Graph.php');
$creator->addFile($tardir . '/tmp/Structures/Graph/Node.php', 'Structures/Graph/Node.php');
$creator->addFile($tardir . '/tmp/Structures/Graph/Manipulator/AcyclicTest.php', 'Structures/Graph/Manipulator/AcyclicTest.php');
$creator->addFile($tardir . '/tmp/Structures/Graph/Manipulator/TopologicalSorter.php', 'Structures/Graph/Manipulator/TopologicalSorter.php');

// Include Start scripts speficially since they are never in the releases
$creator->addFile(__DIR__ . '/PEAR/Start.php', 'PEAR/Start.php');
$creator->addFile(__DIR__ . '/PEAR/Start/CLI.php', 'PEAR/Start/CLI.php');

$creator->useSHA1Signature();
$creator->savePhar(__DIR__ . DIRECTORY_SEPARATOR . $outputFile);

System::rm(array("-rf", "$tardir/tmp"));

0 comments on commit 08b66a2

Please sign in to comment.