Fix handling of local binaries on windows, refs #5612
parent
f63f1ff95f
commit
2d8251b7ad
|
@ -23,6 +23,7 @@ use Composer\Repository\CompositeRepository;
|
||||||
use Composer\Script;
|
use Composer\Script;
|
||||||
use Composer\Script\CommandEvent;
|
use Composer\Script\CommandEvent;
|
||||||
use Composer\Script\PackageEvent;
|
use Composer\Script\PackageEvent;
|
||||||
|
use Composer\Installer\BinaryInstaller;
|
||||||
use Composer\Util\ProcessExecutor;
|
use Composer\Util\ProcessExecutor;
|
||||||
use Symfony\Component\Process\PhpExecutableFinder;
|
use Symfony\Component\Process\PhpExecutableFinder;
|
||||||
|
|
||||||
|
@ -222,10 +223,11 @@ class EventDispatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
$possibleLocalBinaries = $this->composer->getPackage()->getBinaries();
|
$possibleLocalBinaries = $this->composer->getPackage()->getBinaries();
|
||||||
if ( $possibleLocalBinaries ) {
|
if ($possibleLocalBinaries) {
|
||||||
foreach ( $possibleLocalBinaries as $localExec ) {
|
foreach ($possibleLocalBinaries as $localExec) {
|
||||||
if ( preg_match("/\b${callable}$/", $localExec)) {
|
if (preg_match("/\b${callable}$/", $localExec)) {
|
||||||
$exec = str_replace($callable, $localExec, $exec);
|
$caller = BinaryInstaller::determineBinaryCaller($localExec);
|
||||||
|
$exec = preg_replace('{^'.preg_quote($callable).'}', $caller . ' ' . $localExec, $exec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
protected function getBinaries(PackageInterface $package)
|
||||||
{
|
{
|
||||||
return $package->getBinaries();
|
return $package->getBinaries();
|
||||||
|
@ -160,18 +176,7 @@ class BinaryInstaller
|
||||||
protected function generateWindowsProxyCode($bin, $link)
|
protected function generateWindowsProxyCode($bin, $link)
|
||||||
{
|
{
|
||||||
$binPath = $this->filesystem->findShortestPath($link, $bin);
|
$binPath = $this->filesystem->findShortestPath($link, $bin);
|
||||||
if ('.bat' === substr($bin, -4) || '.exe' === substr($bin, -4)) {
|
$caller = self::determineBinaryCaller($bin);
|
||||||
$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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "@ECHO OFF\r\n".
|
return "@ECHO OFF\r\n".
|
||||||
"setlocal DISABLEDELAYEDEXPANSION\r\n".
|
"setlocal DISABLEDELAYEDEXPANSION\r\n".
|
||||||
|
|
Loading…
Reference in New Issue