Browse Source

Fix handling of local binaries on windows, refs #5612

Jordi Boggiano 8 years ago
parent
commit
2d8251b7ad

+ 6 - 4
src/Composer/EventDispatcher/EventDispatcher.php

@@ -23,6 +23,7 @@ use Composer\Repository\CompositeRepository;
 use Composer\Script;
 use Composer\Script\CommandEvent;
 use Composer\Script\PackageEvent;
+use Composer\Installer\BinaryInstaller;
 use Composer\Util\ProcessExecutor;
 use Symfony\Component\Process\PhpExecutableFinder;
 
@@ -222,10 +223,11 @@ class EventDispatcher
                 }
 
                 $possibleLocalBinaries = $this->composer->getPackage()->getBinaries();
-                if ( $possibleLocalBinaries ) {
-                    foreach ( $possibleLocalBinaries as $localExec ) {
-                        if ( preg_match("/\b${callable}$/", $localExec)) {
-                            $exec = str_replace($callable, $localExec, $exec);
+                if ($possibleLocalBinaries) {
+                    foreach ($possibleLocalBinaries as $localExec) {
+                        if (preg_match("/\b${callable}$/", $localExec)) {
+                            $caller = BinaryInstaller::determineBinaryCaller($localExec);
+                            $exec = preg_replace('{^'.preg_quote($callable).'}', $caller . ' ' . $localExec, $exec);
                             break;
                         }
                     }

+ 17 - 12
src/Composer/Installer/BinaryInstaller.php

@@ -118,6 +118,22 @@ class BinaryInstaller
         }
     }
 
+    public static function determineBinaryCaller($bin)
+    {
+        if ('.bat' === substr($bin, -4) || '.exe' === substr($bin, -4)) {
+            return 'call';
+        }
+
+        $handle = fopen($bin, 'r');
+        $line = fgets($handle);
+        fclose($handle);
+        if (preg_match('{^#!/(?:usr/bin/env )?(?:[^/]+/)*(.+)$}m', $line, $match)) {
+            return trim($match[1]);
+        }
+
+        return 'php';
+    }
+
     protected function getBinaries(PackageInterface $package)
     {
         return $package->getBinaries();
@@ -160,18 +176,7 @@ class BinaryInstaller
     protected function generateWindowsProxyCode($bin, $link)
     {
         $binPath = $this->filesystem->findShortestPath($link, $bin);
-        if ('.bat' === substr($bin, -4) || '.exe' === 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';
-            }
-        }
+        $caller = self::determineBinaryCaller($bin);
 
         return "@ECHO OFF\r\n".
             "setlocal DISABLEDELAYEDEXPANSION\r\n".