Skip to content

Commit

Permalink
BinaryInstaller: install full binaries on WSL when bin-compat=auto (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
clxmstaab committed May 2, 2021
1 parent 4842f21 commit bfea0f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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')) {

This comment has been minimized.

Copy link
@DevDavido

DevDavido Jul 11, 2021

This line is causing a not caught ErrorException on systems with enabled open_basedir.

[ErrorException] is_readable(): open_basedir restriction in effect. File(/proc/version) is not within the allowed path(s): ([...])```

This comment has been minimized.

Copy link
@Seldaek

Seldaek Jul 12, 2021

Member

Should be fixed by bacbd15 - please confirm if composer self-update --snapshot fixes it for you.

This comment has been minimized.

Copy link
@DevDavido

DevDavido Jul 12, 2021

Yes, that fixes the issue. Thanks! 👍

return self::$isWindowsSubsystemForLinux = true;
}
}

return self::$isWindowsSubsystemForLinux;
}

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

0 comments on commit bfea0f7

Please sign in to comment.