1
0
Fork 0

Simplify bin-compat by removing the nosymlink option, refs #3704

pull/4541/merge
Jordi Boggiano 2015-10-27 15:36:12 +00:00
parent c9b51a5751
commit 615638c7c3
7 changed files with 32 additions and 71 deletions

View File

@ -105,11 +105,11 @@ first until the cache fits.
## bin-compat
Defaults to `auto`. Determines the compatibility of the binaries to be installed.
If it is `auto` then Composer tries to automatically guess which compatibility mode
to use. If it is `nosymlink` then the binaries will be compatible with Unix-based
operating systems (useful for cases when symlinks are not available).
If its value is `full` then both .bat files for Windows and scripts for Unix-based
operating systems will be installed for each binary.
If it is `auto` then Composer only installs .bat proxy files when on Windows. If
set to `full` then both .bat files for Windows and scripts for Unix-based
operating systems will be installed for each binary. This is mainly useful if you
run Composer inside a linux VM but still want the .bat proxies available for use
in the Windows host OS.
## prepend-autoloader

View File

@ -187,8 +187,8 @@
"description": "The cache max size for the files cache, defaults to \"300MiB\"."
},
"bin-compat": {
"enum": ["auto", "nosymlink", "full"],
"description": "The compatibility of the binaries, defaults to \"auto\" (automatically guessed) and can be \"nosymlink\" (compatible with Unix-based systems) or \"full\" (compatible with both Windows and Unix-based systems)."
"enum": ["auto", "full"],
"description": "The compatibility of the binaries, defaults to \"auto\" (automatically guessed) and can be \"full\" (compatible with both Windows and Unix-based systems)."
},
"discard-changes": {
"type": ["string", "boolean"],

View File

@ -308,7 +308,7 @@ EOT
function ($val) { return $val; },
),
'bin-compat' => array(
function ($val) { return in_array($val, array('auto', 'nosymlink', 'full')); },
function ($val) { return in_array($val, array('auto', 'full')); },
function ($val) { return $val; }
),
'discard-changes' => array(

View File

@ -222,9 +222,9 @@ class Config
case 'bin-compat':
$value = $this->getComposerEnv('COMPOSER_BIN_COMPAT') ?: $this->config[$key];
if (!in_array($value, array('auto', 'nosymlink', 'full'))) {
if (!in_array($value, array('auto', 'full'))) {
throw new \RuntimeException(
"Invalid value for 'bin-compat': {$value}. Expected auto, nosymlink, full"
"Invalid value for 'bin-compat': {$value}. Expected auto, full"
);
}

View File

@ -229,8 +229,6 @@ class LibraryInstaller implements InstallerInterface
} else {
$this->installSymlinkBinaries($binPath, $link);
}
} elseif ($this->binCompat === "nosymlink") {
$this->installUnixyProxyBinaries($binPath, $link);
} elseif ($this->binCompat === "full") {
$this->installFullBinaries($binPath, $link, $bin, $package);
}
@ -256,10 +254,7 @@ class LibraryInstaller implements InstallerInterface
protected function installSymlinkBinaries($binPath, $link)
{
try {
$symlink = new Symlink($this->filesystem);
$symlink->symlinkBin($binPath, $link);
} catch (\ErrorException $e) {
if (!$this->filesystem->relativeSymlink($binPath, $link)) {
$this->installUnixyProxyBinaries($binPath, $link);
}
}

View File

@ -505,6 +505,26 @@ class Filesystem
return unlink($path);
}
/**
* Creates a relative symlink from $link to $target
*
* @param string $target The path of the binary file to be symlinked
* @param string $link The path where the symlink should be created
* @return bool
*/
public function relativeSymlink($target, $link)
{
$cwd = getcwd();
$relativePath = $this->filesystem->findShortestPath($link, $target);
chdir(dirname($link));
$result = @symlink($relativePath, $link);
chdir($cwd);
return (bool) $result;
}
/**
* return true if that directory is a symlink.
*

View File

@ -1,54 +0,0 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Util;
use Composer\Config;
/**
* @author Kocsis Máté <kocsismate@woohoolabs.com>
*/
class Symlink
{
protected $filesystem;
/**
* Initializes the symlinking utility.
*
* @param Filesystem $filesystem
*/
public function __construct(Filesystem $filesystem = null)
{
$this->filesystem = $filesystem ?: new Filesystem();
}
/**
* Creates a symlink for a binary file at a given path.
*
* @param string $binPath The path of the binary file to be symlinked
* @param string $link The path where the symlink should be created
* @throws \ErrorException
*/
public function symlinkBin($binPath, $link)
{
$cwd = getcwd();
$relativeBin = $this->filesystem->findShortestPath($link, $binPath);
chdir(dirname($link));
$result = @symlink($relativeBin, $link);
chdir($cwd);
if ($result === false) {
throw new \ErrorException();
}
}
}