Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix PEAR binaries when the bin dir is non standard, fixes #1001

  • Loading branch information...
commit 269b3481c42f4d1f9272bf6f9891d7a30e3eadd8 1 parent b7d0892
@Seldaek Seldaek authored
View
4 src/Composer/Installer/LibraryInstaller.php
@@ -241,7 +241,7 @@ protected function initializeBinDir()
$this->binDir = realpath($this->binDir);
}
- private function generateWindowsProxyCode($bin, $link)
+ protected function generateWindowsProxyCode($bin, $link)
{
$binPath = $this->filesystem->findShortestPath($link, $bin);
if ('.bat' === substr($bin, -4)) {
@@ -266,7 +266,7 @@ private function generateWindowsProxyCode($bin, $link)
$caller." \"%BIN_TARGET%\" %*\r\n";
}
- private function generateUnixyProxyCode($bin, $link)
+ protected function generateUnixyProxyCode($bin, $link)
{
$binPath = $this->filesystem->findShortestPath($link, $bin);
View
54 src/Composer/Installer/PearInstaller.php
@@ -52,7 +52,7 @@ protected function installCode(PackageInterface $package)
parent::installCode($package);
parent::initializeBinDir();
- $isWindows = defined('PHP_WINDOWS_VERSION_BUILD') ? true : false;
+ $isWindows = defined('PHP_WINDOWS_VERSION_BUILD');
$php_bin = $this->binDir . ($isWindows ? '/composer-php.bat' : '/composer-php');
$installPath = $this->getInstallPath($package);
@@ -100,15 +100,53 @@ protected function initializeBinDir()
chmod($this->binDir.'/composer-php.bat', 0777);
}
+ protected function generateWindowsProxyCode($bin, $link)
+ {
+ $binPath = $this->filesystem->findShortestPath($link, $bin);
+ if ('.bat' === substr($bin, -4)) {
+ $caller = 'call';
+ } else {
+ $handle = fopen($bin, 'r');
+ $line = fgets($handle);
+ fclose($handle);
+ if (preg_match('{^#!/(?:usr/bin/env )?(?:[^/]+/)*(.+)$}m', $line, $match)) {
+ $caller = trim($match[1]);
+ } else {
+ $caller = 'php';
+ }
+
+ if ($caller === 'php') {
+ return "@echo off\r\n".
+ "pushd .\r\n".
+ "cd %~dp0\r\n".
+ "set PHP_PROXY=%CD%\\composer-php.bat\r\n".
+ "cd ".escapeshellarg(dirname($binPath))."\r\n".
+ "set BIN_TARGET=%CD%\\".basename($binPath)."\r\n".
+ "popd\r\n".
+ "%PHP_PROXY% \"%BIN_TARGET%\" %*\r\n";
+ }
+ }
+
+ return "@echo off\r\n".
+ "pushd .\r\n".
+ "cd %~dp0\r\n".
+ "cd ".escapeshellarg(dirname($binPath))."\r\n".
+ "set BIN_TARGET=%CD%\\".basename($binPath)."\r\n".
+ "popd\r\n".
+ $caller." \"%BIN_TARGET%\" %*\r\n";
+ }
+
private function generateWindowsPhpProxyCode()
{
+ $binToVendor = $this->filesystem->findShortestPath($this->binDir, $this->vendorDir, true);
+
return
"@echo off\r\n" .
"setlocal enabledelayedexpansion\r\n" .
"set BIN_DIR=%~dp0\r\n" .
- "set VENDOR_DIR=%BIN_DIR%..\\\r\n" .
- " set DIRS=.\r\n" .
- "FOR /D %%V IN (%VENDOR_DIR%*) DO (\r\n" .
+ "set VENDOR_DIR=%BIN_DIR%\\".$binToVendor."\r\n" .
+ "set DIRS=.\r\n" .
+ "FOR /D %%V IN (%VENDOR_DIR%\\*) DO (\r\n" .
" FOR /D %%P IN (%%V\\*) DO (\r\n" .
" set DIRS=!DIRS!;%%~fP\r\n" .
" )\r\n" .
@@ -118,12 +156,13 @@ private function generateWindowsPhpProxyCode()
private function generateUnixyPhpProxyCode()
{
+ $binToVendor = $this->filesystem->findShortestPath($this->binDir, $this->vendorDir, true);
+
return
"#!/usr/bin/env sh\n".
"SRC_DIR=`pwd`\n".
"BIN_DIR=`dirname $(readlink -f $0)`\n".
- "VENDOR_DIR=`dirname \$BIN_DIR`\n".
- "cd \$BIN_DIR\n".
+ "VENDOR_DIR=\$BIN_DIR/".escapeshellarg($binToVendor)."\n".
"DIRS=\"\"\n".
"for vendor in \$VENDOR_DIR/*; do\n".
" if [ -d \"\$vendor\" ]; then\n".
@@ -134,7 +173,6 @@ private function generateUnixyPhpProxyCode()
" done\n".
" fi\n".
"done\n".
- "cd \$SRC_DIR\n".
- "`which php` -d include_path=\".\$DIRS\" $@\n";
+ "php -d include_path=\".\$DIRS\" $@\n";
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.