Re: [Patch] Optional dependencies
| From: | Martin Jansen | Date: | Fri, 16 May 2003 17:04:37 +0000 |
| Subject: | Re: [Patch] Optional dependencies | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-16368@lists.php.net to get a copy of this message | ||
On Thu May 15, 2003 at 04:5913PM -0400, Jon Parise wrote:
> On Thu, May 15, 2003 at 09:43:37PM +0200, Martin Jansen wrote:
> > @@ -599,12 +601,18 @@
> >
> > // Check dependencies -------------------------------------------
> > if (isset($pkginfo['release_deps']) &&
> > empty($options['nodeps'])) {
> > - $error = $this->checkDeps($pkginfo);
> > - if ($error) {
> > + $dep_errors = "";
>
> Please use '' instead of "" (for consistency with the rest of the
> file).
I always thought I was a nitpicker :-).
A cleaned patch is attached.
--
- Martin Martin Jansen
http://martinjansen.com/
Index: Installer.php =================================================================== RCS file: /repository/php4/pear/PEAR/Installer.php,v retrieving revision 1.86 diff -u -r1.86 Installer.php --- Installer.php 18 Mar 2003 12:06:06 -0000 1.86 +++ Installer.php 16 May 2003 17:02:34 -0000 @@ -15,6 +15,7 @@ // +----------------------------------------------------------------------+ // | Authors: Stig Bakken <ssb@php.net> | // | Tomas V.V.Cox <cox@idecnet.com> | +// | Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // // $Id: Installer.php,v 1.86 2003/03/18 12:06:06 ssb Exp $ @@ -40,6 +41,7 @@ * * @since PHP 4.0.2 * @author Stig Bakken <ssb@php.net> + * @author Martin Jansen <mj@php.net> */ class PEAR_Installer extends PEAR_Common { @@ -599,12 +601,18 @@ // Check dependencies ------------------------------------------- if (isset($pkginfo['release_deps']) && empty($options['nodeps'])) { - $error = $this->checkDeps($pkginfo); - if ($error) { + $dep_errors = ''; + $error = $this->checkDeps($pkginfo, $dep_errors); + if ($error == true) { if (empty($options['soft'])) { - $this->log(0, $error); + $this->log(0, substr($dep_errors, 1)); + } + return $this->raiseError("$pkgname: Dependencies failed"); + } else if (!empty($dep_errors)) { + // Print optional dependencies + if (empty($options['soft'])) { + $this->log(0, $dep_errors); } - return $this->raiseError("$pkgname: dependencies failed"); } } @@ -784,22 +792,35 @@ // }}} // {{{ checkDeps() - function checkDeps(&$pkginfo) + /** + * Check if the package meets all dependencies + * + * @param array Package information (passed by reference) + * @param string Error message (passed by reference) + * @return boolean False when no error occured, otherwise true + */ + function checkDeps(&$pkginfo, &$errors) { $depchecker = &new PEAR_Dependency($this->registry); $error = $errors = ''; - $failed_deps = array(); + $failed_deps = $optional_deps = array(); if (is_array($pkginfo['release_deps'])) { foreach($pkginfo['release_deps'] as $dep) { $code = $depchecker->callCheckMethod($error, $dep); if ($code) { - $failed_deps[] = array($dep, $code, $error); + if (isset($dep['optional']) && $dep['optional'] == 'yes') { + // Ugly hack to adjust the error messages + $error = str_replace('requires ', '', $error); + $error = ucfirst($error); + $error = $error . ' is recommended to utilize some features.'; + $optional_deps[] = array($dep, $code, $error); + } else { + $failed_deps[] = array($dep, $code, $error); + } } } $n = count($failed_deps); if ($n > 0) { - $depinstaller =& new PEAR_Installer($this->ui); - $to_install = array(); for ($i = 0; $i < $n; $i++) { if (isset($failed_deps[$i]['type'])) { $type = $failed_deps[$i]['type']; @@ -824,7 +845,28 @@ break; } } - return substr($errors, 1); + return true; + } + + $count_optional = count($optional_deps); + if ($count_optional > 0) { + $errors = "Optional dependencies:"; + + for ($i = 0; $i < $count_optional; $i++) { + if (isset($optional_deps[$i]['type'])) { + $type = $optional_deps[$i]['type']; + } else { + $type = 'pkg'; + } + switch ($optional_deps[$i][1]) { + case PEAR_DEPENDENCY_MISSING: + case PEAR_DEPENDENCY_UPGRADE_MINOR: + default: + $errors .= "\n" . $optional_deps[$i][2]; + break; + } + } + return false; } } return false;
Index: Installer.php =================================================================== RCS file: /repository/php4/pear/PEAR/Installer.php,v retrieving revision 1.86 diff -u -r1.86 Installer.php --- Installer.php 18 Mar 2003 12:06:06 -0000 1.86 +++ Installer.php 16 May 2003 17:02:34 -0000 @@ -15,6 +15,7 @@ // +----------------------------------------------------------------------+ // | Authors: Stig Bakken <ssb@php.net> | // | Tomas V.V.Cox <cox@idecnet.com> | +// | Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // // $Id: Installer.php,v 1.86 2003/03/18 12:06:06 ssb Exp $ @@ -40,6 +41,7 @@ * * @since PHP 4.0.2 * @author Stig Bakken <ssb@php.net> + * @author Martin Jansen <mj@php.net> */ class PEAR_Installer extends PEAR_Common { @@ -599,12 +601,18 @@ // Check dependencies ------------------------------------------- if (isset($pkginfo['release_deps']) && empty($options['nodeps'])) { - $error = $this->checkDeps($pkginfo); - if ($error) { + $dep_errors = ''; + $error = $this->checkDeps($pkginfo, $dep_errors); + if ($error == true) { if (empty($options['soft'])) { - $this->log(0, $error); + $this->log(0, substr($dep_errors, 1)); + } + return $this->raiseError("$pkgname: Dependencies failed"); + } else if (!empty($dep_errors)) { + // Print optional dependencies + if (empty($options['soft'])) { + $this->log(0, $dep_errors); } - return $this->raiseError("$pkgname: dependencies failed"); } } @@ -784,22 +792,35 @@ // }}} // {{{ checkDeps() - function checkDeps(&$pkginfo) + /** + * Check if the package meets all dependencies + * + * @param array Package information (passed by reference) + * @param string Error message (passed by reference) + * @return boolean False when no error occured, otherwise true + */ + function checkDeps(&$pkginfo, &$errors) { $depchecker = &new PEAR_Dependency($this->registry); $error = $errors = ''; - $failed_deps = array(); + $failed_deps = $optional_deps = array(); if (is_array($pkginfo['release_deps'])) { foreach($pkginfo['release_deps'] as $dep) { $code = $depchecker->callCheckMethod($error, $dep); if ($code) { - $failed_deps[] = array($dep, $code, $error); + if (isset($dep['optional']) && $dep['optional'] == 'yes') { + // Ugly hack to adjust the error messages + $error = str_replace('requires ', '', $error); + $error = ucfirst($error); + $error = $error . ' is recommended to utilize some features.'; + $optional_deps[] = array($dep, $code, $error); + } else { + $failed_deps[] = array($dep, $code, $error); + } } } $n = count($failed_deps); if ($n > 0) { - $depinstaller =& new PEAR_Installer($this->ui); - $to_install = array(); for ($i = 0; $i < $n; $i++) { if (isset($failed_deps[$i]['type'])) { $type = $failed_deps[$i]['type']; @@ -824,7 +845,28 @@ break; } } - return substr($errors, 1); + return true; + } + + $count_optional = count($optional_deps); + if ($count_optional > 0) { + $errors = "Optional dependencies:"; + + for ($i = 0; $i < $count_optional; $i++) { + if (isset($optional_deps[$i]['type'])) { + $type = $optional_deps[$i]['type']; + } else { + $type = 'pkg'; + } + switch ($optional_deps[$i][1]) { + case PEAR_DEPENDENCY_MISSING: + case PEAR_DEPENDENCY_UPGRADE_MINOR: + default: + $errors .= "\n" . $optional_deps[$i][2]; + break; + } + } + return false; } } return false;