From dd55365dee01507c801d1081d1559484640a78a1 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 22 Jan 2023 03:59:42 -0600 Subject: [PATCH] os: cleanup the output of os.uname() on windows (#17066) * os: (WinOS) mimic current practices of `busybox` and `coreutils` * os: trim any possible surounding whitespace --- vlib/os/os_windows.c.v | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index 766e38c928..fefd3384d4 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -458,16 +458,24 @@ pub fn debugger_present() bool { return C.IsDebuggerPresent() } +// `uname` is not standardized, so mimic current practices +// busybox-v1.35.0 * `busybox uname -a` => "Windows_NT HOSTNAME 10.0 19044 x86_64 MS/Windows" +// rust/coreutils-v0.0.17 * `coreutils uname -a` => `Windows_NT HOSTNAME 10.0 19044 x86_64 MS/Windows (Windows 10)` +// Python3 => `uname_result(system='Windows', node='HOSTNAME', release='10', version='10.0.19044', machine='AMD64')` +// ref: [NT Version Info](https://en.wikipedia.org/wiki/Windows_NT) @@ +// ref: [NT Version Info (detailed)](https://en.wikipedia.org/wiki/Comparison_of_Microsoft_Windows_versions#NT_Kernel-based_2) pub fn uname() Uname { - sys_and_ver := execute('cmd /c ver').output.split('[') nodename := hostname() - machine := getenv('PROCESSOR_ARCHITECTURE') + // ToDO: environment variables have low reliability; check for another quick way + machine := getenv('PROCESSOR_ARCHITECTURE') // * note: 'AMD64' == 'x86_64' (not standardized, but 'x86_64' use is more common; but, python == 'AMD64') + version_info := execute('cmd /d/c ver').output + version_n := (version_info.split(' '))[3].replace(']', '').trim_space() return Uname{ - sysname: sys_and_ver[0].trim_space() + sysname: 'Windows_NT' // as of 2022-12, WinOS has only two possible kernels ~ 'Windows_NT' or 'Windows_9x' nodename: nodename - release: sys_and_ver[1].replace(']', '') - version: sys_and_ver[0] + '[' + sys_and_ver[1] - machine: machine + machine: machine.trim_space() + release: (version_n.split('.'))[0..2].join('.').trim_space() // Major.minor-only == "primary"/release version + version: (version_n.split('.'))[2].trim_space() } }