1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Pickle |
5
|
|
|
* |
6
|
|
|
* |
7
|
|
|
* @license |
8
|
|
|
* |
9
|
|
|
* New BSD License |
10
|
|
|
* |
11
|
|
|
* Copyright © 2015-2015, Pickle community. All rights reserved. |
12
|
|
|
* |
13
|
|
|
* Redistribution and use in source and binary forms, with or without |
14
|
|
|
* modification, are permitted provided that the following conditions are met: |
15
|
|
|
* * Redistributions of source code must retain the above copyright |
16
|
|
|
* notice, this list of conditions and the following disclaimer. |
17
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
18
|
|
|
* notice, this list of conditions and the following disclaimer in the |
19
|
|
|
* documentation and/or other materials provided with the distribution. |
20
|
|
|
* * Neither the name of the Hoa nor the names of its contributors may be |
21
|
|
|
* used to endorse or promote products derived from this software without |
22
|
|
|
* specific prior written permission. |
23
|
|
|
* |
24
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
25
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
26
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
27
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
28
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
29
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
30
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
31
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
32
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
33
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
34
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
namespace Pickle\Package\PHP\Command\Build; |
38
|
|
|
|
39
|
|
|
use Pickle\Base\Interfaces; |
40
|
|
|
use Pickle\Base\Abstracts; |
41
|
|
|
use Pickle\Engine; |
42
|
|
|
|
43
|
|
|
class Windows extends Abstracts\Package\Build implements Interfaces\Package\Build |
44
|
|
|
{ |
45
|
|
|
public function prepare() |
46
|
|
|
{ |
47
|
|
|
if (!file_exists('c:\\php-sdk\\bin')) { |
48
|
|
|
throw new \Exception('PHP SDK not found'); |
49
|
|
|
} |
50
|
|
|
putenv('path=c:\\php-sdk\\bin;'.getenv('path')); |
51
|
|
|
|
52
|
|
|
if (!$this->runCommand('phpsdk_setvars')) { |
53
|
|
|
throw new \Exception('phpsdk_setvars failed'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$this->phpize(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $src |
61
|
|
|
*/ |
62
|
|
|
private function copySrcDir($src, $dest) |
63
|
|
|
{ |
64
|
|
|
foreach (scandir($src) as $file) { |
65
|
|
|
$srcfile = rtrim($src, '/').'/'.$file; |
66
|
|
|
$destfile = rtrim($dest, '/').'/'.$file; |
67
|
|
|
if (!is_readable($srcfile)) { |
68
|
|
|
continue; |
69
|
|
|
} |
70
|
|
|
if ($file != '.' && $file != '..') { |
71
|
|
|
if (is_dir($srcfile)) { |
72
|
|
|
if (!is_dir($destfile)) { |
73
|
|
|
mkdir($destfile); |
74
|
|
|
} |
75
|
|
|
$this->copySrcDir($srcfile, $destfile); |
76
|
|
|
} else { |
77
|
|
|
copy($srcfile, $destfile); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function phpize() |
84
|
|
|
{ |
85
|
|
|
$backCwd = getcwd(); |
86
|
|
|
chdir($this->pkg->getSourceDir()); |
87
|
|
|
|
88
|
|
|
$res = $this->runCommand('phpize'); |
89
|
|
|
chdir($backCwd); |
90
|
|
|
if (!$res) { |
91
|
|
|
throw new \Exception('phpize failed'); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
protected function prepareConfigOpts() |
96
|
|
|
{ |
97
|
|
|
$configureOptions = '--enable-debug-pack'; |
98
|
|
|
foreach ($this->options as $name => $option) { |
99
|
|
|
$decision = null; |
100
|
|
|
if ('enable' === $option->type) { |
101
|
|
|
$decision = true == $option->input ? 'enable' : 'disable'; |
102
|
|
|
} elseif ('disable' == $option->type) { |
103
|
|
|
$decision = false == $option->input ? 'enable' : 'disable'; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if (!is_null($decision)) { |
107
|
|
|
$configureOptions .= ' --'.$decision.'-'.$name; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$php_prefix = dirname(Engine::factory()->getPath()); |
112
|
|
|
$configureOptions .= " --with-prefix=$php_prefix"; |
113
|
|
|
|
114
|
|
|
$this->appendPkgConfigureOptions($configureOptions); |
115
|
|
|
|
116
|
|
|
return $configureOptions; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function configure($opts = null) |
120
|
|
|
{ |
121
|
|
|
/* duplicate src tree to do not pollute repo or src dir */ |
122
|
|
|
$this->copySrcDir($this->pkg->getSourceDir(), $this->tempDir); |
123
|
|
|
$backCwd = getcwd(); |
124
|
|
|
chdir($this->tempDir); |
125
|
|
|
|
126
|
|
|
/* XXX check sanity */ |
127
|
|
|
$configureOptions = $opts ? $opts : $this->prepareConfigOpts(); |
128
|
|
|
|
129
|
|
|
$res = $this->runCommand($this->pkg->getSourceDir().'/configure '.$configureOptions); |
130
|
|
|
chdir($backCwd); |
131
|
|
|
if (!$res) { |
132
|
|
|
throw new \Exception('configure failed, see log at '.$this->tempDir.'\config.log'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/* This post check is required for the case when config.w32 doesn't |
136
|
|
|
bail out on error but silently disables an extension. In this |
137
|
|
|
case we won't see any bad exit status. */ |
138
|
|
|
$opts = $this->pkg->getConfigureOptions(); |
139
|
|
|
list($ext) = each($opts); |
140
|
|
|
if (preg_match(',\|\s+'.preg_quote($ext).'\s+\|\s+shared\s+\|,Sm', $this->getlog('configure')) < 1) { |
141
|
|
|
throw new \Exception("failed to configure the '$ext' extension"); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function make() |
146
|
|
|
{ |
147
|
|
|
$backCwd = getcwd(); |
148
|
|
|
chdir($this->tempDir); |
149
|
|
|
$res = $this->runCommand('nmake'); |
150
|
|
|
chdir($backCwd); |
151
|
|
|
|
152
|
|
|
if (!$res) { |
153
|
|
|
throw new \Exception('nmake failed'); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function install() |
158
|
|
|
{ |
159
|
|
|
$backCwd = getcwd(); |
160
|
|
|
chdir($this->tempDir); |
161
|
|
|
|
162
|
|
|
/* Record the produced DLL filenames. */ |
163
|
|
|
$files = (array)glob("*/*/php_*.dll"); |
164
|
|
|
$files = array_merge($files, glob("*/php_*.dll")); |
165
|
|
|
$dlls = []; |
166
|
|
|
foreach ($files as $file) { |
167
|
|
|
$dlls[] = basename($file); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
$res = $this->runCommand('nmake install'); |
171
|
|
|
chdir($backCwd); |
172
|
|
|
if (!$res) { |
173
|
|
|
throw new \Exception('nmake install failed'); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
$ini = \Pickle\Engine\Ini::factory(Engine::factory()); |
177
|
|
|
$ini->updatePickleSection($dlls); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function getInfo() |
181
|
|
|
{ |
182
|
|
|
$info = array(); |
183
|
|
|
$info = array_merge($info, $this->getInfoFromPhpizeLog()); |
184
|
|
|
$info = array_merge($info, $this->getInfoFromConfigureLog()); |
185
|
|
|
|
186
|
|
|
if (!preg_match(',(.+)/(.+),', $info['name'], $m)) { |
187
|
|
|
$info['vendor'] = null; |
188
|
|
|
} else { |
189
|
|
|
$info['name'] = $m[2]; |
190
|
|
|
$info['vendor'] = $m[1]; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
return $info; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
protected function getInfoFromPhpizeLog() |
197
|
|
|
{ |
198
|
|
|
$ret = array( |
199
|
|
|
'php_major' => null, |
200
|
|
|
'php_minor' => null, |
201
|
|
|
'php_patch' => null, |
202
|
|
|
); |
203
|
|
|
|
204
|
|
|
$tmp = $this->getLog('phpize'); |
205
|
|
|
if (!preg_match(",Rebuilding configure.js[\n\r\d:]+\s+(.+)[\n\r]+,", $tmp, $m)) { |
206
|
|
|
throw new \Exception("Couldn't determine PHP development SDK path"); |
207
|
|
|
} |
208
|
|
|
$sdk = $m[1]; |
209
|
|
|
|
210
|
|
|
$ver_header = file_get_contents("$sdk/include/main/php_version.h"); |
211
|
|
|
|
212
|
|
|
if (!preg_match(",PHP_MAJOR_VERSION\s+(\d+),", $ver_header, $m)) { |
213
|
|
|
throw new \Exception("Couldn't determine PHP_MAJOR_VERSION"); |
214
|
|
|
} |
215
|
|
|
$ret['php_major'] = $m[1]; |
216
|
|
|
|
217
|
|
|
if (!preg_match(",PHP_MINOR_VERSION\s+(\d+),", $ver_header, $m)) { |
218
|
|
|
throw new \Exception("Couldn't determine PHP_MINOR_VERSION"); |
219
|
|
|
} |
220
|
|
|
$ret['php_minor'] = $m[1]; |
221
|
|
|
|
222
|
|
|
if (!preg_match(",PHP_RELEASE_VERSION\s+(\d+),", $ver_header, $m)) { |
223
|
|
|
throw new \Exception("Couldn't determine PHP_RELEASE_VERSION"); |
224
|
|
|
} |
225
|
|
|
$ret['php_patch'] = $m[1]; |
226
|
|
|
|
227
|
|
|
return $ret; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
protected function getInfoFromConfigureLog() |
231
|
|
|
{ |
232
|
|
|
$info = array( |
233
|
|
|
'thread_safe' => null, |
234
|
|
|
'compiler' => null, |
235
|
|
|
'arch' => null, |
236
|
|
|
'version' => null, |
237
|
|
|
'name' => null, |
238
|
|
|
); |
239
|
|
|
|
240
|
|
|
$tmp = $this->getLog('configure'); |
241
|
|
|
|
242
|
|
|
if (!preg_match(",Build type\s+\|\s+([a-zA-Z]+),", $tmp, $m)) { |
243
|
|
|
throw new \Exception("Couldn't determine the build thread safety"); |
244
|
|
|
} |
245
|
|
|
$is_release = 'Release' == $m[1]; |
|
|
|
|
246
|
|
|
|
247
|
|
|
if (!preg_match(",Thread Safety\s+\|\s+([a-zA-Z]+),", $tmp, $m)) { |
248
|
|
|
throw new \Exception("Couldn't determine the build thread safety"); |
249
|
|
|
} |
250
|
|
|
$info['thread_safe'] = strtolower($m[1]) == 'yes'; |
251
|
|
|
|
252
|
|
|
if (!preg_match(",Compiler\s+\|\s+MSVC(\d+),", $tmp, $m)) { |
253
|
|
|
throw new \Exception('Currently only MSVC is supported'); |
254
|
|
|
} |
255
|
|
|
$info['compiler'] = 'vc'.$m[1]; |
256
|
|
|
|
257
|
|
|
if (!preg_match(",Architecture\s+\|\s+([a-zA-Z0-9]+),", $tmp, $m)) { |
258
|
|
|
throw new \Exception("Couldn't determine the build architecture"); |
259
|
|
|
} |
260
|
|
|
$info['arch'] = $m[1]; |
261
|
|
|
|
262
|
|
|
$info['version'] = $this->getPackage()->getPrettyVersion(); |
263
|
|
|
$info['name'] = $this->getPackage()->getName(); |
264
|
|
|
|
265
|
|
|
return $info; |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: fdm=marker */ |
270
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.