Bearsampp 2026.9.23
Loading...
Searching...
No Matches
PEAR_Builder Class Reference
Inheritance diagram for PEAR_Builder:
Collaboration diagram for PEAR_Builder:

Public Member Functions

 __construct ($configureoptions, &$ui)
 _build_win32 ($descfile, $callback=null)
 _harvestInstDir ($dest_prefix, $dirname, &$built_files)
 _parseConfigureOptions ($options)
 _parseConfigureOptionsEndElement ($parser, $element)
 _parseConfigureOptionsStartElement ($parser, $tagName, $attribs)
 _runCommand ($command, $callback=null)
 build ($descfile, $callback=null)
 log ($level, $msg, $append_crlf=true)
 msdevCallback ($what, $data)
 phpizeCallback ($what, $data)
Public Member Functions inherited from PEAR_Common
 __construct ()
 _PEAR_Common ()
 _postProcessChecks ($pf)
 _postProcessValidPackagexml (&$pf)
 buildProvidesArray ($srcinfo)
 detectDependencies ($any, $status_callback=null)
 downloadHttp ( $url, &$ui, $save_dir='.', $callback=null, $lastmodified=null, $accept=false, $channel=false)
 infoFromAny ($info)
 infoFromDescriptionFile ($descfile)
 infoFromString ($data)
 infoFromTgzFile ($file)
 mkDirHier ($dir)
 mkTempDir ($tmpdir='')
 setFrontendObject (&$ui)
 validatePackageInfo ($info, &$errors, &$warnings, $dir_prefix='')
 validPackageName ($name)
 validPackageVersion ($ver)
 xmlFromInfo ($pkginfo)
Public Member Functions inherited from PEAR
 __call ($method, $arguments)
 __construct ($error_class=null)
 _checkDelExpect ($error_code)
 _PEAR ()
 delExpect ($error_code)
 expectError ($code=' *')
 PEAR ($error_class=null)
 popExpect ()

Data Fields

 $_firstline = null
 $_lastline = null
 $_parsed_configure_options
 $current_callback = null
 $extensions_built = array()
 $php_api_version = 0
 $zend_extension_api_no = 0
 $zend_module_api_no = 0
Data Fields inherited from PEAR_Common
 $_validPackageFile
 $config = null
 $current_attributes = array()
 $current_element
 $current_path = null
 $element_stack = array()
 $pkginfo = array()
 $ui = null
Data Fields inherited from PEAR
 $_debug = false
 $_default_error_handler = ''
 $_default_error_mode = null
 $_default_error_options = null
 $_error_class = 'PEAR_Error'
 $_expected_errors = array()

Additional Inherited Members

Static Public Member Functions inherited from PEAR_Common
static addTempFile ($file)
static analyzeSourceCode ($file)
static betterStates ($state, $include=false)
static getDependencyRelations ()
static getDependencyTypes ()
static getFileRoles ()
static getProvideTypes ()
static getReleaseStates ()
static getReplacementTypes ()
static getScriptPhases ()
static getUserRoles ()
static isIncludeable ($path)
Static Public Member Functions inherited from PEAR
static __callStatic ($method, $arguments)
static getSourceDateEpoch ()
static & getStaticProperty ($class, $var)
static isError ($data, $code=null)
static loadExtension ($ext)
static registerShutdownFunc ($func, $args=array())
static staticPopErrorHandling ()
static staticPushErrorHandling ($mode, $options=null)
Static Protected Member Functions inherited from PEAR
static _popErrorHandling ($object)
static _pushErrorHandling ($object, $mode, $options=null)
static _raiseError ($object, $message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
static _setErrorHandling ( $object, $mode=null, $options=null)
static _throwError ($object, $message=null, $code=null, $userinfo=null)
Static Protected Attributes inherited from PEAR
static $bivalentMethods

Detailed Description

Definition at line 41 of file Builder.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $configureoptions,
& $ui )

PEAR_Builder constructor.

Parameters
mixed[]$configureoptions
object$uiuser interface object (instance of PEAR_Frontend_*)

@access public

Definition at line 74 of file Builder.php.

75 {
76 parent::__construct();
77 $this->setFrontendObject($ui);
78 $this->_parseConfigureOptions($configureoptions);
79 }
_parseConfigureOptions($options)
Definition Builder.php:86
setFrontendObject(&$ui)
Definition Common.php:294

References PEAR_Common\$ui, _parseConfigureOptions(), and PEAR_Common\setFrontendObject().

Here is the call graph for this function:

Member Function Documentation

◆ _build_win32()

_build_win32 ( $descfile,
$callback = null )

Build an extension from source on windows. requires msdev

Definition at line 131 of file Builder.php.

132 {
133 if (is_object($descfile)) {
134 $pkg = $descfile;
135 $descfile = $pkg->getPackageFile();
136 } else {
137 $pf = new PEAR_PackageFile($this->config, $this->debug);
138 $pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
139 if (PEAR::isError($pkg)) {
140 return $pkg;
141 }
142 }
143 $dir = dirname($descfile);
144 $old_cwd = getcwd();
145
146 if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
147 return $this->raiseError("could not chdir to $dir");
148 }
149
150 // packages that were in a .tar have the packagefile in this directory
151 $vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
152 if (file_exists($dir) && is_dir($vdir)) {
153 if (!chdir($vdir)) {
154 return $this->raiseError("could not chdir to " . realpath($vdir));
155 }
156
157 $dir = getcwd();
158 }
159
160 $this->log(2, "building in $dir");
161
162 $dsp = $pkg->getPackage().'.dsp';
163 if (!file_exists("$dir/$dsp")) {
164 return $this->raiseError("The DSP $dsp does not exist.");
165 }
166 // XXX TODO: make release build type configurable
167 $command = 'msdev '.$dsp.' /MAKE "'.$pkg->getPackage(). ' - Release"';
168
169 $err = $this->_runCommand($command, array(&$this, 'msdevCallback'));
170 if (PEAR::isError($err)) {
171 return $err;
172 }
173
174 // figure out the build platform and type
175 $platform = 'Win32';
176 $buildtype = 'Release';
177 if (preg_match('/.*?'.$pkg->getPackage().'\s-\s(\w+)\s(.*?)-+/i',$this->_firstline,$matches)) {
178 $platform = $matches[1];
179 $buildtype = $matches[2];
180 }
181
182 if (preg_match('/(.*)?\s-\s(\d+).*?(\d+)/', $this->_lastline, $matches)) {
183 if ($matches[2]) {
184 // there were errors in the build
185 return $this->raiseError("There were errors during compilation.");
186 }
187 $out = $matches[1];
188 } else {
189 return $this->raiseError("Did not understand the completion status returned from msdev.exe.");
190 }
191
192 // msdev doesn't tell us the output directory :/
193 // open the dsp, find /out and use that directory
194 $dsptext = join('', file($dsp));
195
196 // this regex depends on the build platform and type having been
197 // correctly identified above.
198 $regex ='/.*?!IF\s+"\$\‍(CFG\‍)"\s+==\s+("'.
199 $pkg->getPackage().'\s-\s'.
200 $platform.'\s'.
201 $buildtype.'").*?'.
202 '\/out:"(.*?)"/is';
203
204 if ($dsptext && preg_match($regex, $dsptext, $matches)) {
205 // what we get back is a relative path to the output file itself.
206 $outfile = realpath($matches[2]);
207 } else {
208 return $this->raiseError("Could not retrieve output information from $dsp.");
209 }
210 // realpath returns false if the file doesn't exist
211 if ($outfile && copy($outfile, "$dir/$out")) {
212 $outfile = "$dir/$out";
213 }
214
215 $built_files[] = array(
216 'file' => "$outfile",
217 'php_api' => $this->php_api_version,
218 'zend_mod_api' => $this->zend_module_api_no,
219 'zend_ext_api' => $this->zend_extension_api_no,
220 );
221
222 return $built_files;
223 }
const PEAR_VALIDATE_NORMAL
Definition Validate.php:20
log($level, $msg, $append_crlf=true)
Definition Builder.php:549
_runCommand($command, $callback=null)
Definition Builder.php:522
if( $raw) foreach($opts as $opt) if( $store_system_config) if($store_user_config) $command
Definition pearcmd.php:322

References $command, _runCommand(), PEAR\isError(), log(), and PEAR_VALIDATE_NORMAL.

Referenced by build().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _harvestInstDir()

_harvestInstDir ( $dest_prefix,
$dirname,
& $built_files )
Parameters
string
string
array@access private

Definition at line 241 of file Builder.php.

242 {
243 $d = opendir($dirname);
244 if (!$d)
245 return false;
246
247 $ret = true;
248 while (($ent = readdir($d)) !== false) {
249 if ($ent[0] == '.')
250 continue;
251
252 $full = $dirname . DIRECTORY_SEPARATOR . $ent;
253 if (is_dir($full)) {
254 if (!$this->_harvestInstDir(
255 $dest_prefix . DIRECTORY_SEPARATOR . $ent,
256 $full, $built_files)) {
257 $ret = false;
258 break;
259 }
260 } else {
261 $dest = $dest_prefix . DIRECTORY_SEPARATOR . $ent;
262 $built_files[] = array(
263 'file' => $full,
264 'dest' => $dest,
265 'php_api' => $this->php_api_version,
266 'zend_mod_api' => $this->zend_module_api_no,
267 'zend_ext_api' => $this->zend_extension_api_no,
268 );
269 }
270 }
271 closedir($d);
272 return $ret;
273 }
_harvestInstDir($dest_prefix, $dirname, &$built_files)
Definition Builder.php:241

References _harvestInstDir().

Referenced by _harvestInstDir(), and build().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parseConfigureOptions()

_parseConfigureOptions ( $options)

Parse –configureoptions string.

Parameters
stringOptions, in the form "X=1 Y=2 Z='there\'s always one'"

Definition at line 86 of file Builder.php.

87 {
88 $data = '<XML><PROPERTIES ' . $options . ' /></XML>';
89 $parser = xml_parser_create('ISO-8859-1');
90 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
91 xml_set_element_handler(
92 $parser, array($this, '_parseConfigureOptionsStartElement'),
93 array($this, '_parseConfigureOptionsEndElement'));
94 xml_parse($parser, $data, true);
95 xml_parser_free($parser);
96 }
$options
Definition pearcmd.php:145

References $options.

Referenced by __construct().

Here is the caller graph for this function:

◆ _parseConfigureOptionsEndElement()

_parseConfigureOptionsEndElement ( $parser,
$element )

Handle element end.

See also
PEAR_Builder\_parseConfigureOptions()
Parameters
resource
string$element

Definition at line 123 of file Builder.php.

124 {
125 }

◆ _parseConfigureOptionsStartElement()

_parseConfigureOptionsStartElement ( $parser,
$tagName,
$attribs )

Handle element start.

See also
PEAR_Builder\_parseConfigureOptions()
Parameters
resource$parser
string$tagName
mixed[]$attribs

Definition at line 107 of file Builder.php.

108 {
109 if ($tagName !== 'PROPERTIES') {
110 return;
111 }
112 $this->_parsed_configure_options = $attribs;
113 }

◆ _runCommand()

_runCommand ( $command,
$callback = null )

Run an external command, using a message callback to report output. The command will be run through popen and output is reported for every line with a "cmdoutput" message with the line string, including newlines, as payload.

Parameters
string$commandthe command to run
mixed$callback(optional) function to use as message callback
Returns
bool whether the command was successful (exit code 0 means success, any other means failure)

@access private

Definition at line 522 of file Builder.php.

523 {
524 $this->log(1, "running: $command");
525 $pp = popen("$command 2>&1", "r");
526 if (!$pp) {
527 return $this->raiseError("failed to run `$command'");
528 }
529 if ($callback && $callback[0]->debug == 1) {
530 $olddbg = $callback[0]->debug;
531 $callback[0]->debug = 2;
532 }
533
534 while ($line = fgets($pp, 1024)) {
535 if ($callback) {
536 call_user_func($callback, 'cmdoutput', $line);
537 } else {
538 $this->log(2, rtrim($line));
539 }
540 }
541 if ($callback && isset($olddbg)) {
542 $callback[0]->debug = $olddbg;
543 }
544
545 $exitcode = is_resource($pp) ? pclose($pp) : -1;
546 return ($exitcode == 0);
547 }

References $command, and log().

Referenced by _build_win32(), and build().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ build()

build ( $descfile,
$callback = null )

Build an extension from source. Runs "phpize" in the source directory, but compiles in a temporary directory (TMPDIR/pear-build-USER/PACKAGE-VERSION).

Parameters
string|PEAR_PackageFile_v*$descfile path to XML package description file, or a PEAR_PackageFile object
mixed$callbackcallback function used to report output, see PEAR_Builder\_runCommand for details
Returns
array an array of associative arrays with built files, format: array( array( 'file' => '/path/to/ext.so', 'php_api' => YYYYMMDD, 'zend_mod_api' => YYYYMMDD, 'zend_ext_api' => YYYYMMDD ), ... )

@access public

See also
PEAR_Builder\_runCommand

Definition at line 298 of file Builder.php.

299 {
300 if (preg_match('/(\\/|\\\\|^)([^\\/\\\\]+)?php([^\\/\\\\]+)?$/',
301 $this->config->get('php_bin'), $matches)) {
302 if (isset($matches[2]) && strlen($matches[2]) &&
303 trim($matches[2]) != trim($this->config->get('php_prefix'))) {
304 $this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') .
305 ' appears to have a prefix ' . $matches[2] . ', but' .
306 ' config variable php_prefix does not match');
307 }
308
309 if (isset($matches[3]) && strlen($matches[3]) &&
310 trim($matches[3]) != trim($this->config->get('php_suffix'))) {
311 $this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') .
312 ' appears to have a suffix ' . $matches[3] . ', but' .
313 ' config variable php_suffix does not match');
314 }
315 }
316
317 $this->current_callback = $callback;
318 if (PEAR_OS == "Windows") {
319 return $this->_build_win32($descfile, $callback);
320 }
321
322 if (PEAR_OS != 'Unix') {
323 return $this->raiseError("building extensions not supported on this platform");
324 }
325
326 if (is_object($descfile)) {
327 $pkg = $descfile;
328 $descfile = $pkg->getPackageFile();
329 if (is_a($pkg, 'PEAR_PackageFile_v1')) {
330 $dir = dirname($descfile);
331 } else {
332 $dir = $pkg->_config->get('temp_dir') . '/' . $pkg->getName();
333 // automatically delete at session end
334 self::addTempFile($dir);
335 }
336 } else {
337 $pf = new PEAR_PackageFile($this->config);
338 $pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
339 if (PEAR::isError($pkg)) {
340 return $pkg;
341 }
342 $dir = dirname($descfile);
343 }
344
345 // Find config. outside of normal path - e.g. config.m4
346 foreach (array_keys($pkg->getInstallationFileList()) as $item) {
347 if (stristr(basename($item), 'config.m4') && dirname($item) != '.') {
348 $dir .= DIRECTORY_SEPARATOR . dirname($item);
349 break;
350 }
351 }
352
353 $old_cwd = getcwd();
354 if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
355 return $this->raiseError("could not chdir to $dir");
356 }
357
358 $vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
359 if (is_dir($vdir)) {
360 chdir($vdir);
361 }
362
363 $dir = getcwd();
364 $this->log(2, "building in $dir");
365 $binDir = $this->config->get('bin_dir');
366 if (!preg_match('@(^|:)' . preg_quote($binDir, '@') . '(:|$)@', getenv('PATH'))) {
367 putenv('PATH=' . $binDir . ':' . getenv('PATH'));
368 }
369 $err = $this->_runCommand($this->config->get('php_prefix')
370 . "phpize" .
371 $this->config->get('php_suffix'),
372 array(&$this, 'phpizeCallback'));
373 if (PEAR::isError($err)) {
374 return $err;
375 }
376
377 if (!$err) {
378 return $this->raiseError("`phpize' failed");
379 }
380
381 // {{{ start of interactive part
382 $configure_command = "$dir/configure";
383
384 $phpConfigName = $this->config->get('php_prefix')
385 . 'php-config'
386 . $this->config->get('php_suffix');
387 $phpConfigPath = System::which($phpConfigName);
388 if ($phpConfigPath !== false) {
389 $configure_command .= ' --with-php-config='
390 . $phpConfigPath;
391 }
392
393 $configure_options = $pkg->getConfigureOptions();
394 if ($configure_options) {
395 foreach ($configure_options as $option) {
396 $default = array_key_exists('default', $option) ? $option['default'] : null;
397 if (array_key_exists($option['name'], $this->_parsed_configure_options)) {
398 $response = $this->_parsed_configure_options[$option['name']];
399 } else {
400 list($response) = $this->ui->userDialog(
401 'build', [$option['prompt']], ['text'], [$default]);
402 }
403 if (substr($option['name'], 0, 5) === 'with-' &&
404 ($response === 'yes' || $response === 'autodetect')) {
405 $configure_command .= " --{$option['name']}";
406 } else {
407 $configure_command .= " --{$option['name']}=".trim($response);
408 }
409 }
410 }
411 // }}} end of interactive part
412
413 // FIXME make configurable
414 if (!$user=getenv('USER')) {
415 $user='defaultuser';
416 }
417
418 $tmpdir = $this->config->get('temp_dir');
419 $build_basedir = System::mktemp(' -t "' . $tmpdir . '" -d "pear-build-' . $user . '"');
420 $build_dir = "$build_basedir/$vdir";
421 $inst_dir = "$build_basedir/install-$vdir";
422 $this->log(1, "building in $build_dir");
423 if (is_dir($build_dir)) {
424 System::rm(array('-rf', $build_dir));
425 }
426
427 if (!System::mkDir(array('-p', $build_dir))) {
428 return $this->raiseError("could not create build dir: $build_dir");
429 }
430
431 self::addTempFile($build_dir);
432 if (!System::mkDir(array('-p', $inst_dir))) {
433 return $this->raiseError("could not create temporary install dir: $inst_dir");
434 }
435 self::addTempFile($inst_dir);
436
437 $make_command = getenv('MAKE') ? getenv('MAKE') : 'make';
438
439 $to_run = array(
440 $configure_command,
441 $make_command,
442 "$make_command INSTALL_ROOT=\"$inst_dir\" install",
443 "find \"$inst_dir\" | xargs ls -dils"
444 );
445 if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) {
446 return $this->raiseError("could not chdir to $build_dir");
447 }
448 putenv('PHP_PEAR_VERSION=1.10.18');
449 foreach ($to_run as $cmd) {
450 $err = $this->_runCommand($cmd, $callback);
451 if (PEAR::isError($err)) {
452 chdir($old_cwd);
453 return $err;
454 }
455 if (!$err) {
456 chdir($old_cwd);
457 return $this->raiseError("`$cmd' failed");
458 }
459 }
460 if (!($dp = opendir("modules"))) {
461 chdir($old_cwd);
462 return $this->raiseError("no `modules' directory found");
463 }
464 $built_files = array();
465 $prefix = exec($this->config->get('php_prefix')
466 . "php-config" .
467 $this->config->get('php_suffix') . " --prefix");
468 $this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files);
469 chdir($old_cwd);
470 return $built_files;
471 }
const PEAR_OS
Definition PEAR.php:43
_build_win32($descfile, $callback=null)
Definition Builder.php:131
static addTempFile($file)
Definition Common.php:208
static rm($args)
Definition System.php:210
static which($program, $fallback=false)
Definition System.php:495
static mktemp($args=null)
Definition System.php:395

References $response, _build_win32(), _harvestInstDir(), _runCommand(), PEAR_Common\addTempFile(), PEAR\isError(), log(), PEAR_OS, and PEAR_VALIDATE_NORMAL.

Here is the call graph for this function:

◆ log()

log ( $level,
$msg,
$append_crlf = true )

Logging method.

Parameters
int$levellog level (0 is quiet, higher is noisier)
string$msgmessage to write to the log
Returns
void

Reimplemented from PEAR_Common.

Definition at line 549 of file Builder.php.

550 {
551 if ($this->current_callback) {
552 if ($this->debug >= $level) {
553 call_user_func($this->current_callback, 'output', $msg);
554 }
555 return;
556 }
557 return parent::log($level, $msg, $append_crlf);
558 }

Referenced by _build_win32(), _runCommand(), build(), and phpizeCallback().

Here is the caller graph for this function:

◆ msdevCallback()

msdevCallback ( $what,
$data )

Definition at line 227 of file Builder.php.

228 {
229 if (!$this->_firstline)
230 $this->_firstline = $data;
231 $this->_lastline = $data;
232 call_user_func($this->current_callback, $what, $data);
233 }

◆ phpizeCallback()

phpizeCallback ( $what,
$data )

Message callback function used when running the "phpize" program. Extracts the API numbers used. Ignores other message types than "cmdoutput".

Parameters
string$whatthe type of message
mixed$datathe message
Returns
void

@access public

Definition at line 485 of file Builder.php.

486 {
487 if ($what != 'cmdoutput') {
488 return;
489 }
490 $this->log(1, rtrim($data));
491 if (preg_match('/You should update your .aclocal.m4/', $data)) {
492 return;
493 }
494 $matches = array();
495 if (preg_match('/^\s+(\S[^:]+):\s+(\d{8})/', $data, $matches)) {
496 $member = preg_replace('/[^a-z]/', '_', strtolower($matches[1]));
497 $apino = (int)$matches[2];
498 if (isset($this->$member)) {
499 $this->$member = $apino;
500 //$msg = sprintf("%-22s : %d", $matches[1], $apino);
501 //$this->log(1, $msg);
502 }
503 }
504 }

References log().

Here is the call graph for this function:

Field Documentation

◆ $_firstline

$_firstline = null

Definition at line 57 of file Builder.php.

◆ $_lastline

$_lastline = null

Definition at line 56 of file Builder.php.

◆ $_parsed_configure_options

$_parsed_configure_options

Definition at line 64 of file Builder.php.

◆ $current_callback

$current_callback = null

Definition at line 53 of file Builder.php.

◆ $extensions_built

$extensions_built = array()

Definition at line 47 of file Builder.php.

◆ $php_api_version

$php_api_version = 0

Definition at line 43 of file Builder.php.

◆ $zend_extension_api_no

$zend_extension_api_no = 0

Definition at line 45 of file Builder.php.

◆ $zend_module_api_no

$zend_module_api_no = 0

Definition at line 44 of file Builder.php.


The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/pear/PEAR/Builder.php