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 1 commit
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
22 changes: 22 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,26 @@ 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;

$process = new ProcessExecutor();
try {
if (0 === $process->execute('cat /proc/version | grep "Microsoft"', $ignoredOutput)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in #9841 (comment) there was another suggestion to use /etc/wsl.conf for the detect. this file was not present on my WSL though ¯_(ツ)_/¯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must not fail composer when exec (or similar functions) are disabled, on Windows as well as on linux

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to just do a file_get_contents, no need for a process running cat to read a file :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right :)

clxmstaab marked this conversation as resolved.
Show resolved Hide resolved
return self::$isWindowsSubsystemForLinux = true;
}
} catch (\Exception $e) {
// noop
}
}

return self::$isWindowsSubsystemForLinux;
}

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