1
0
Fork 0

Fix handling of local binaries on windows, refs #5612

pull/5503/merge
Jordi Boggiano 2016-09-10 12:51:28 +02:00
parent f63f1ff95f
commit 2d8251b7ad
2 changed files with 23 additions and 16 deletions

View File

@ -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;
}
}

View File

@ -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".