diff --git a/Library/Homebrew/extend/os/linux/system_config.rb b/Library/Homebrew/extend/os/linux/system_config.rb index d17b5a7516..69be2c06a7 100644 --- a/Library/Homebrew/extend/os/linux/system_config.rb +++ b/Library/Homebrew/extend/os/linux/system_config.rb @@ -40,22 +40,12 @@ module SystemConfig out end - def wsl_version(kernel) - return unless /-microsoft/i.match?(kernel) - - return "2 (Microsoft Store)" if Version.new(kernel[/Linux ([0-9.]*)-.*/, 1]) > Version.new("5.15") - return "2" if kernel.include?("-microsoft") - return "1" if kernel.include?("-Microsoft") - end - def dump_verbose_config(out = $stdout) kernel = Utils.safe_popen_read("uname", "-mors").chomp dump_generic_verbose_config(out) out.puts "Kernel: #{kernel}" out.puts "OS: #{OS::Linux.os_version}" - if (wsl = wsl_version(kernel).presence) - out.puts "WSL: #{wsl}" - end + out.puts "WSL: #{OS::Linux.wsl_version}" if OS::Linux.wsl? out.puts "Host glibc: #{host_glibc_version}" out.puts "/usr/bin/gcc: #{host_gcc_version}" out.puts "/usr/bin/ruby: #{host_ruby_version}" if RUBY_PATH != HOST_RUBY_PATH diff --git a/Library/Homebrew/os.rb b/Library/Homebrew/os.rb index b1d38b0669..4281aa4fd2 100644 --- a/Library/Homebrew/os.rb +++ b/Library/Homebrew/os.rb @@ -1,6 +1,8 @@ # typed: true # frozen_string_literal: true +require "version" + # Helper functions for querying operating system information. # # @api private @@ -67,7 +69,7 @@ module OS elsif OS.linux? require "os/linux" ISSUES_URL = "https://docs.brew.sh/Troubleshooting" - PATH_OPEN = "xdg-open" + PATH_OPEN = (OS::Linux.wsl? ? "wslview" : "xdg-open").freeze end sig { returns(T::Boolean) } diff --git a/Library/Homebrew/os/linux.rb b/Library/Homebrew/os/linux.rb index 277e3de3a9..91e2c4da78 100644 --- a/Library/Homebrew/os/linux.rb +++ b/Library/Homebrew/os/linux.rb @@ -1,6 +1,8 @@ # typed: true # frozen_string_literal: true +require "utils" + module OS # Helper module for querying system information on Linux. module Linux @@ -25,6 +27,23 @@ module OS "Unknown" end end + + sig { returns(T::Boolean) } + def wsl? + /-microsoft/i.match?(OS.kernel_version.to_s) + end + + sig { returns(Version) } + def wsl_version + Version::NULL unless wsl? + kernel = OS.kernel_version.to_s + return Version.new("2 (Microsoft Store)") if Version.new(T.must(kernel[/^([0-9.]*)-.*/, + 1])) > Version.new("5.15") + return Version.new("2") if kernel.include?("-microsoft") + return Version.new("1") if kernel.include?("-Microsoft") + + Version::NULL + end end # rubocop:disable Style/Documentation diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index cb8f2b07e7..254d51b64e 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -19,6 +19,7 @@ require "utils/repology" require "utils/svn" require "utils/tty" require "tap_constants" +require "PATH" module Homebrew extend Context