Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 176 lines (144 sloc) 5.992 kB
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
1 <?php
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
2 error_reporting(1803);
3
21a1759 add instructions/doc comment
Greg Beaver authored
4 /**
e69c634 fix problems with phar creation
Greg Beaver authored
5 * go-pear.phar creator. Requires PHP_Archive version 0.11.0 or newer
21a1759 add instructions/doc comment
Greg Beaver authored
6 *
7 * PHP version 5.1+
8 *
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
9 * To use, in pear-core create a directory
21a1759 add instructions/doc comment
Greg Beaver authored
10 * named go-pear-tarballs, and run these commands in the directory
11 *
12 * <pre>
1506496 @helgi Add required packages for the phar generators as svn externals and up…
helgi authored
13 * $ pear download -Z PEAR Archive_Tar Console_Getopt Structures_Graph XML_Util
21a1759 add instructions/doc comment
Greg Beaver authored
14 * </pre>
15 *
16 * finally, run this script using PHP 5.1's cli php
eae8c10 @helgi use the bsd license
helgi authored
17
21a1759 add instructions/doc comment
Greg Beaver authored
18 *
19 * @category pear
20 * @package PEAR
21 * @author Greg Beaver <cellog@php.net>
836496a @helgi properly update to new bsd license
helgi authored
22 * @copyright 2005-2009 The Authors
23 * @license http://opensource.org/licenses/bsd-license.php New BSD License
21a1759 add instructions/doc comment
Greg Beaver authored
24 * @version CVS: $Id$
25 */
26
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
27 $y = array();
28 foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) {
29 if ($path == '.') {
30 continue;
31 }
32
33 $y[] = $path;
34 }
35
36 // remove current dir, we will otherwise include git files, which is not good
37 set_include_path(implode(PATH_SEPARATOR, $y));
38 require_once 'PEAR/PackageFile.php';
39 require_once 'PEAR/Config.php';
40 require_once 'PHP/Archive/Creator.php';
41 $config = &PEAR_Config::singleton();
42
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
43 function replaceVersion($contents, $path)
44 {
45 return str_replace(array('@PEAR-VER@', '@package_version@'), $GLOBALS['pearver'], $contents);
46 }
47
48 $outputFile = 'go-pear.phar';
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
49
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
50 $tardir = __DIR__ . '/go-pear-tarballs';
51 $dp = @scandir($tardir);
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
52 if ($dp === false) {
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
53 die("while locating packages to install: scandir('" . $tardir. "') failed\n");
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
54 }
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
55
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
56 $required = array('Archive_Tar', 'Console_Getopt', 'PEAR', 'Structures_Graph', 'XML_Util');
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
57 $packages = array();
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
58 foreach ($dp as $entry) {
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
59 if ($entry{0} == '.' || !in_array(substr($entry, -4), array('.tar'))) {
60 continue;
61 }
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
62
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
63 $package = strstr($entry, '-', true);
64 $key = array_search($package, $required);
65 if ($key !== false) {
66 unset($required[$key]);
67 }
68
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
69 $packages[] = $entry;
70 }
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
71
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
72 if (!empty($required)) {
73 die('Following packages were not available in tar format in go-pear-tarballs: ' . implode(', ', $required). "\n");
74 }
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
75
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
76 if (!file_exists("$tardir/tmp")) {
77 mkdir("$tardir/tmp");
e8d2a85 fixes needed to make go-pear.phar work
Greg Beaver authored
78 }
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
79
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
80 // Use the tar files for required Phar files
81 require_once 'Archive/Tar.php';
82 require_once 'System.php';
83
84 foreach ($packages as $package) {
85 $name = substr($package, 0, -4);
86 $tar = new Archive_Tar("$tardir/$package");
87 $tar->extractModify("$tardir/tmp", $name);
88 }
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
89
3dfc129 @helgi Quick cleanup - Requires PHP 5.3 to generate the phar archives now (n…
helgi authored
90 chdir(__DIR__);
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
91
600e756 @saltybeagle Remove assignment of new by reference. Add newline to die message.
saltybeagle authored
92 $pkg = new PEAR_PackageFile($config);
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
93 $pf = $pkg->fromPackageFile($tardir . '/tmp/package2.xml', PEAR_VALIDATE_NORMAL);
e8d2a85 fixes needed to make go-pear.phar work
Greg Beaver authored
94 if (PEAR::isError($pf)) {
95 foreach ($pf->getUserInfo() as $warn) {
96 echo $warn['message'] . "\n";
97 }
3dfc129 @helgi Quick cleanup - Requires PHP 5.3 to generate the phar archives now (n…
helgi authored
98
e8d2a85 fixes needed to make go-pear.phar work
Greg Beaver authored
99 die($pf->getMessage());
100 }
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
101 $pearver = $pf->getVersion();
102
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
103 $creator = new PHP_Archive_Creator('index.php', $outputFile); // no compression
e69c634 fix problems with phar creation
Greg Beaver authored
104 $creator->useDefaultFrontController('PEAR.php');
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
105 $creator->useSHA1Signature();
106
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
107 foreach ($packages as $package) {
e8ff447 more fixes to phar generation
Greg Beaver authored
108 echo "adding PEAR/go-pear-tarballs/$package\n";
109 $creator->addFile("go-pear-tarballs/$package", "PEAR/go-pear-tarballs/$package");
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
110 }
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
111
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
112 $commandcontents = file_get_contents(__DIR__ . '/go-pear-phar.php');
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
113 $commandcontents = str_replace('require_once \'', 'require_once \'phar://' . $outputFile . '/', $commandcontents);
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
114 $creator->addString($commandcontents, 'index.php');
115
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
116 $commandcontents = file_get_contents($tardir . '/tmp/PEAR/Frontend.php');
e69c634 fix problems with phar creation
Greg Beaver authored
117 $commandcontents = str_replace(
118 array(
119 "\$file = str_replace('_', '/', \$uiclass) . '.php';"
120 ),
121 array(
5f001d0 oops, need double quote instead of single quote
Greg Beaver authored
122 "\$file = 'phar://" . $outputFile . "/' . str_replace('_', '/', \$uiclass) . '.php';"
e69c634 fix problems with phar creation
Greg Beaver authored
123 ), $commandcontents);
124 $commandcontents = replaceVersion($commandcontents, '');
125 $creator->addString($commandcontents, 'PEAR/Frontend.php');
126
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
127 $commandcontents = file_get_contents($tardir . '/tmp/PEAR/PackageFile/v2.php');
e69c634 fix problems with phar creation
Greg Beaver authored
128 $commandcontents = str_replace(
129 array(
130 '$fp = @fopen("PEAR/Task/$taskfile.php", \'r\', true);',
131 ),
132 array(
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
133 '$fp = @fopen("phar://' . $outputFile . '/PEAR/Task/$taskfile.php", \'r\', true);'
e69c634 fix problems with phar creation
Greg Beaver authored
134 ), $commandcontents);
135 $commandcontents = replaceVersion($commandcontents, '');
136 $commandcontents = $creator->tokenMagicRequire($commandcontents, 'a.php');
137 $creator->addString($commandcontents, 'PEAR/PackageFile/v2.php');
1fee0a3 tweak OS_Guess addition (include_once 'System.php' needs
Greg Beaver authored
138
125243c streamline script immensely
Greg Beaver authored
139 $creator->addMagicRequireCallback(array($creator, 'limitedSmartMagicRequire'));
140 $creator->addMagicRequireCallback('replaceVersion');
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
141 $creator->addFile($tardir . '/tmp/PEAR/Command.php', 'PEAR/Command.php');
25a393f add the .phar creation script for go-pear.phar
Greg Beaver authored
142
125243c streamline script immensely
Greg Beaver authored
143 $creator->clearMagicRequire();
144 $creator->addMagicRequireCallback(array($creator, 'tokenMagicRequire'));
145 $creator->addMagicRequireCallback('replaceVersion');
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
146
a4d15bd @Tyrael add these three files to the ignore list as they are already added af…
Tyrael authored
147 $ignores = array(
148 '*PEAR/Frontend.php',
149 '*PEAR/PackageFile/v2.php',
150 '*PEAR/Command.php',
151 );
152
153 $creator->addDir($tardir . '/tmp/PEAR', $ignores, array('*PEAR/*'), false, $tardir . '/tmp');
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
154
155 $creator->addFile($tardir . '/tmp/PEAR.php', 'PEAR.php');
156 $creator->addFile($tardir . '/tmp/PEAR5.php', 'PEAR5.php');
157 $creator->addFile($tardir . '/tmp/System.php', 'System.php');
158 $creator->addFile($tardir . '/tmp/OS/Guess.php', 'OS/Guess.php');
3dfc129 @helgi Quick cleanup - Requires PHP 5.3 to generate the phar archives now (n…
helgi authored
159
160 // Other packages
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
161 $creator->addFile($tardir . '/tmp/Archive/Tar.php', 'Archive/Tar.php');
162 $creator->addFile($tardir . '/tmp/Util.php', 'XML/Util.php');
163 $creator->addFile($tardir . '/tmp/Console/Getopt.php', 'Console/Getopt.php');
164 $creator->addFile($tardir . '/tmp/Structures/Graph.php', 'Structures/Graph.php');
165 $creator->addFile($tardir . '/tmp/Structures/Graph/Node.php', 'Structures/Graph/Node.php');
166 $creator->addFile($tardir . '/tmp/Structures/Graph/Manipulator/AcyclicTest.php', 'Structures/Graph/Manipulator/AcyclicTest.php');
167 $creator->addFile($tardir . '/tmp/Structures/Graph/Manipulator/TopologicalSorter.php', 'Structures/Graph/Manipulator/TopologicalSorter.php');
168
70a0afd @Tyrael fix typo
Tyrael authored
169 // Include Start scripts specifically since they are never in the releases
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
170 $creator->addFile(__DIR__ . '/PEAR/Start.php', 'PEAR/Start.php');
171 $creator->addFile(__DIR__ . '/PEAR/Start/CLI.php', 'PEAR/Start/CLI.php');
6e7c677 @helgi Sync the generation scripts as much as possible + various cosmetics
helgi authored
172
f9a0e96 set SHA1 signature, will avoid future problems with phar.require_hash=1
Greg Beaver authored
173 $creator->useSHA1Signature();
3dfc129 @helgi Quick cleanup - Requires PHP 5.3 to generate the phar archives now (n…
helgi authored
174 $creator->savePhar(__DIR__ . DIRECTORY_SEPARATOR . $outputFile);
b9095f2 @helgi - Move boilerplate include_path handling to top
helgi authored
175
176 System::rm(array("-rf", "$tardir/tmp"));
Something went wrong with that request. Please try again.