Skip to content

Commit

Permalink
Use 'wslview' instead of 'xdg-open' on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-belkin committed Feb 27, 2023
1 parent 06cf85f commit c9b289f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
12 changes: 1 addition & 11 deletions Library/Homebrew/extend/os/linux/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,12 @@ def host_ruby_version
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
Expand Down
4 changes: 3 additions & 1 deletion Library/Homebrew/os.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# typed: true
# frozen_string_literal: true

require "version"

# Helper functions for querying operating system information.
#
# @api private
Expand Down Expand Up @@ -67,7 +69,7 @@ def self.kernel_name
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) }
Expand Down
19 changes: 19 additions & 0 deletions Library/Homebrew/os/linux.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# typed: true
# frozen_string_literal: true

require "utils"

module OS
# Helper module for querying system information on Linux.
module Linux
Expand All @@ -25,6 +27,23 @@ def os_version
"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
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require "utils/svn"
require "utils/tty"
require "tap_constants"
require "PATH"

module Homebrew
extend Context
Expand Down

0 comments on commit c9b289f

Please sign in to comment.