Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BinaryInstaller: install full binaries on WSL when bin-compat=auto #9855

Merged
merged 3 commits into from May 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Composer/Installer/BinaryInstaller.php
Expand Up @@ -82,7 +82,7 @@ public function installBinaries(PackageInterface $package, $installPath, $warnOn
}

if ($this->binCompat === "auto") {
if (Platform::isWindows()) {
if (Platform::isWindows() || Platform::isWindowsSubsystemForLinux()) {
$this->installFullBinaries($binPath, $link, $bin, $package);
} else {
$this->installSymlinkBinaries($binPath, $link);
Expand Down
23 changes: 23 additions & 0 deletions src/Composer/Util/Platform.php
Expand Up @@ -21,6 +21,8 @@ class Platform
{
/** @var ?bool */
private static $isVirtualBoxGuest = null;
/** @var ?bool */
private static $isWindowsSubsystemForLinux = null;

/**
* Parses tildes and environment variables in paths.
Expand Down Expand Up @@ -67,6 +69,27 @@ public static function getUserDirectory()
throw new \RuntimeException('Could not determine user directory');
}

/**
* @return bool Whether the host machine is running on the Windows Subsystem for Linux (WSL)
*/
public static function isWindowsSubsystemForLinux()
{
if (null === self::$isWindowsSubsystemForLinux) {
self::$isWindowsSubsystemForLinux = false;

// while WSL will be hosted within windows, WSL itself cannot be windows based itself.
if (self::isWindows()) {
return self::$isWindowsSubsystemForLinux = false;
}

if (is_readable('/proc/version') && false !== stripos(file_get_contents('/proc/version'), 'microsoft')) {
return self::$isWindowsSubsystemForLinux = true;
}
}

return self::$isWindowsSubsystemForLinux;
}

/**
* @return bool Whether the host machine is running a Windows OS
*/
Expand Down