From bfea0f7d1e991f237ccf448b0a0d24ede02d923a Mon Sep 17 00:00:00 2001 From: Markus Staab <47448731+clxmstaab@users.noreply.github.com> Date: Sun, 2 May 2021 16:50:42 +0200 Subject: [PATCH] BinaryInstaller: install full binaries on WSL when bin-compat=auto (#9855) --- src/Composer/Installer/BinaryInstaller.php | 2 +- src/Composer/Util/Platform.php | 23 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Composer/Installer/BinaryInstaller.php b/src/Composer/Installer/BinaryInstaller.php index 5a6e38805..4ce134b94 100644 --- a/src/Composer/Installer/BinaryInstaller.php +++ b/src/Composer/Installer/BinaryInstaller.php @@ -82,7 +82,7 @@ class BinaryInstaller } if ($this->binCompat === "auto") { - if (Platform::isWindows()) { + if (Platform::isWindows() || Platform::isWindowsSubsystemForLinux()) { $this->installFullBinaries($binPath, $link, $bin, $package); } else { $this->installSymlinkBinaries($binPath, $link); diff --git a/src/Composer/Util/Platform.php b/src/Composer/Util/Platform.php index 6293ce80c..5693247c8 100644 --- a/src/Composer/Util/Platform.php +++ b/src/Composer/Util/Platform.php @@ -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. @@ -67,6 +69,27 @@ class Platform 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 */