@@ -55,13 +55,65 @@ def host_ruby_version
5555 out
5656 end
5757
58+ sig { returns ( T . nilable ( String ) ) }
59+ def windows_version
60+ return unless OS . wsl?
61+
62+ cmd = Kernel . which ( "cmd.exe" , ORIGINAL_PATHS ) || ::Pathname . new ( "/mnt/c/Windows/System32/cmd.exe" )
63+ return unless cmd . executable?
64+
65+ windows_registry_version ( cmd ) || Utils . popen_read ( cmd , "/d" , "/c" , "ver" , err : :close )
66+ . delete ( "\r " )
67+ . lines
68+ . map ( &:strip )
69+ . find { |line | line . start_with? ( "Microsoft Windows" ) }
70+ end
71+
72+ sig { params ( cmd : ::Pathname ) . returns ( T . nilable ( String ) ) }
73+ def windows_registry_version ( cmd )
74+ values = windows_registry_values ( cmd )
75+ product_name = values [ "ProductName" ]
76+ build = values [ "CurrentBuildNumber" ]
77+ return if product_name . blank? || build . blank?
78+
79+ product_name = product_name . sub ( /\A Windows 10\b / , "Windows 11" ) if build . to_i >= 22_000
80+ build += ".#{ values [ "UBR" ] } " if values [ "UBR" ] . present?
81+
82+ version = values [ "DisplayVersion" ] || values [ "ReleaseId" ]
83+ return "#{ product_name } [#{ build } ]" if version . blank?
84+
85+ "#{ product_name } (#{ version } ) [#{ build } ]"
86+ end
87+
88+ sig { params ( cmd : ::Pathname ) . returns ( T ::Hash [ String , String ] ) }
89+ def windows_registry_values ( cmd )
90+ output = Utils . popen_read ( cmd , "/d" , "/c" , "reg" , "query" ,
91+ "HKLM\\ SOFTWARE\\ Microsoft\\ Windows NT\\ CurrentVersion" ,
92+ err : :close )
93+
94+ output . each_line . with_object ( { } ) do |line , values |
95+ match = line . delete ( "\r " ) . match ( /^\s *(\S +)\s +REG_\S +\s +(.+?)\s *$/ )
96+ next if match . nil?
97+
98+ key = match [ 1 ]
99+ value = match [ 2 ]
100+ next if key . nil? || value . nil?
101+
102+ values [ key ] = value . start_with? ( "0x" ) ? value . to_i ( 16 ) . to_s : value
103+ end
104+ end
105+
58106 sig { params ( out : T . any ( File , StringIO , IO ) ) . void }
59107 def dump_verbose_config ( out = $stdout)
60108 kernel = Utils . safe_popen_read ( "uname" , "-mors" ) . chomp
61109 super
62110 out . puts "Kernel: #{ kernel } "
63111 out . puts "OS: #{ OS ::Linux . os_version } "
64- out . puts "WSL: #{ OS ::Linux . wsl_version } " if OS . wsl?
112+ if OS . wsl?
113+ out . puts "WSL: #{ OS ::Linux . wsl_version } "
114+ windows = windows_version
115+ out . puts "Windows: #{ windows } " if windows
116+ end
65117 out . puts "Host glibc: #{ host_glibc_version } "
66118 out . puts "Host libstdc++: #{ host_libstdcxx_version } "
67119 out . puts "#{ ::DevelopmentTools . host_gcc_path } : #{ host_gcc_version } "
0 commit comments