Преглед на файлове

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

Jordi Boggiano преди 13 години
родител
ревизия
269b3481c4
променени са 2 файла, в които са добавени 48 реда и са изтрити 10 реда
  1. 2 2
      src/Composer/Installer/LibraryInstaller.php
  2. 46 8
      src/Composer/Installer/PearInstaller.php

+ 2 - 2
src/Composer/Installer/LibraryInstaller.php

@@ -241,7 +241,7 @@ class LibraryInstaller implements InstallerInterface
         $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 @@ class LibraryInstaller implements InstallerInterface
             $caller." \"%BIN_TARGET%\" %*\r\n";
     }
 
-    private function generateUnixyProxyCode($bin, $link)
+    protected function generateUnixyProxyCode($bin, $link)
     {
         $binPath = $this->filesystem->findShortestPath($link, $bin);
 

+ 46 - 8
src/Composer/Installer/PearInstaller.php

@@ -52,7 +52,7 @@ class PearInstaller extends LibraryInstaller
         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 @@ class PearInstaller extends LibraryInstaller
         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 @@ class PearInstaller extends LibraryInstaller
 
     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 @@ class PearInstaller extends LibraryInstaller
             "        done\n".
             "    fi\n".
             "done\n".
-            "cd \$SRC_DIR\n".
-            "`which php` -d include_path=\".\$DIRS\" $@\n";
+            "php -d include_path=\".\$DIRS\" $@\n";
     }
 }