From 4dde6098588890b15858d8c97c2f53e9d340bec2 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 4 Jan 2025 09:33:17 +0800 Subject: [PATCH 01/11] vdoctor: fix format, windows, tcc --- cmd/tools/vdoctor.v | 55 +++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index 2c91d3de13f217..4fce44d30ab1ca 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -3,6 +3,7 @@ import time import term import v.util.version import runtime +import encoding.iconv struct App { mut: @@ -16,6 +17,7 @@ fn (mut a App) println(s string) { fn (mut a App) collect_info() { a.line('V full version', version.full_v_version(true)) + a.line(':-------------------', ':-------------------') mut os_kind := os.user_os() mut arch_details := []string{} @@ -51,7 +53,7 @@ fn (mut a App) collect_info() { if os_kind == 'windows' { arch_details << a.cmd( command: 'wmic cpu get name /format:table' - line: 1 + line: 2 ) } @@ -91,14 +93,20 @@ fn (mut a App) collect_info() { ) p := a.parse(wmic_info, '=') caption, build_number, os_arch := p['caption'], p['buildnumber'], p['osarchitecture'] - os_details = '${caption} v${build_number} ${os_arch}' + caption_utf := iconv.encoding_to_vstring(caption.bytes(), 'ANSI') or { caption } + build_number_utf := iconv.encoding_to_vstring(build_number.bytes(), 'ANSI') or { + build_number + } + os_arch_utf := iconv.encoding_to_vstring(os_arch.bytes(), 'ANSI') or { os_arch } + os_details = '${caption_utf} ${build_number_utf} ${os_arch_utf}' } else { ouname := os.uname() os_details = '${ouname.release}, ${ouname.version}' } a.line('OS', '${os_kind}, ${os_details}') a.line('Processor', arch_details.join(', ')) - a.println('') + a.line('', '') + // a.println('') getwd := os.getwd() vmodules := os.vmodules_dir() vtmp_dir := os.vtmp_dir() @@ -108,20 +116,20 @@ fn (mut a App) collect_info() { a.line('getwd', getwd) a.line('vexe', vexe) a.line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str()) - a.println('') + a.line('', '') a.line2('vroot', diagnose_dir(vroot), vroot) a.line2('VMODULES', diagnose_dir(vmodules), vmodules) a.line2('VTMP', diagnose_dir(vtmp_dir), vtmp_dir) vflags := os.getenv('VFLAGS') - a.println('') + a.line('', '') if vflags != '' { a.line('env VFLAGS', '"${vflags}"') - a.println('') + a.line('', '') } a.line('Git version', a.cmd(command: 'git --version')) a.line('Git vroot status', a.git_info()) a.line('.git/config present', os.is_file('.git/config').str()) - a.println('') + a.line('', '') a.line('CC version', a.cmd(command: 'cc --version')) a.line('emcc version', a.cmd(command: 'emcc --version')) a.report_tcc_version('thirdparty/tcc') @@ -134,7 +142,8 @@ struct CmdConfig { fn (mut a App) cmd(c CmdConfig) string { x := os.execute(c.command) - if x.exit_code < 0 || x.exit_code == 127 { + os_kind := os.user_os() + if x.exit_code < 0 || x.exit_code == 127 || (os_kind == 'windows' && x.exit_code == 1) { return 'N/A' } if x.exit_code == 0 { @@ -150,11 +159,11 @@ fn (mut a App) cmd(c CmdConfig) string { } fn (mut a App) line(label string, value string) { - a.println('${label}: ${term.colorize(term.bold, value)}') + a.println('|${label:-20}|${term.colorize(term.bold, value)}') } fn (mut a App) line2(label string, value string, value2 string) { - a.println('${label}: ${term.colorize(term.bold, value)}, value: ${term.colorize(term.bold, + a.println('|${label:-20}|${term.colorize(term.bold, value)}, value: ${term.colorize(term.bold, value2)}') } @@ -243,16 +252,24 @@ fn (mut a App) git_info() string { fn (mut a App) report_tcc_version(tccfolder string) { if !os.is_file(os.join_path(tccfolder, '.git', 'config')) { - a.line(tccfolder, 'N/A') - return + a.line('tcc git status', 'N/A') + } else { + tcc_branch_name := a.cmd( + command: 'git -C ${os.quoted_path(tccfolder)} rev-parse --abbrev-ref HEAD' + ) + tcc_commit := a.cmd( + command: 'git -C ${os.quoted_path(tccfolder)} describe --abbrev=8 --dirty --always --tags' + ) + a.line('tcc git status', '${tcc_branch_name} ${tcc_commit}') + } + cmd := os.join_path(tccfolder, 'tcc.exe') + ' -v' + x := os.execute(cmd) + os_kind := os.user_os() + if x.exit_code == 0 { + a.line('tcc version', '${x.output.trim_space()}') + } else { + a.line('tcc version', 'N/A') } - tcc_branch_name := a.cmd( - command: 'git -C ${os.quoted_path(tccfolder)} rev-parse --abbrev-ref HEAD' - ) - tcc_commit := a.cmd( - command: 'git -C ${os.quoted_path(tccfolder)} describe --abbrev=8 --dirty --always --tags' - ) - a.line('${tccfolder} status', '${tcc_branch_name} ${tcc_commit}') } fn (mut a App) report_info() { From f1a75089a9f7462081cf4b8b0af127538ddc6f71 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 4 Jan 2025 09:47:42 +0800 Subject: [PATCH 02/11] fix windows path encoding --- cmd/tools/vdoctor.v | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index 4fce44d30ab1ca..e674ca73c009e7 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -92,13 +92,11 @@ fn (mut a App) collect_info() { line: -1 ) p := a.parse(wmic_info, '=') - caption, build_number, os_arch := p['caption'], p['buildnumber'], p['osarchitecture'] - caption_utf := iconv.encoding_to_vstring(caption.bytes(), 'ANSI') or { caption } - build_number_utf := iconv.encoding_to_vstring(build_number.bytes(), 'ANSI') or { - build_number - } - os_arch_utf := iconv.encoding_to_vstring(os_arch.bytes(), 'ANSI') or { os_arch } - os_details = '${caption_utf} ${build_number_utf} ${os_arch_utf}' + mut caption, mut build_number, mut os_arch := p['caption'], p['buildnumber'], p['osarchitecture'] + caption = iconv.encoding_to_vstring(caption.bytes(), 'ANSI') or { caption } + build_number = iconv.encoding_to_vstring(build_number.bytes(), 'ANSI') or { build_number } + os_arch = iconv.encoding_to_vstring(os_arch.bytes(), 'ANSI') or { os_arch } + os_details = '${caption} ${build_number} ${os_arch}' } else { ouname := os.uname() os_details = '${ouname.release}, ${ouname.version}' @@ -107,12 +105,20 @@ fn (mut a App) collect_info() { a.line('Processor', arch_details.join(', ')) a.line('', '') // a.println('') - getwd := os.getwd() - vmodules := os.vmodules_dir() - vtmp_dir := os.vtmp_dir() - vexe := os.getenv('VEXE') - vroot := os.dir(vexe) + mut getwd := os.getwd() + mut vmodules := os.vmodules_dir() + mut vtmp_dir := os.vtmp_dir() + mut vexe := os.getenv('VEXE') + mut vroot := os.dir(vexe) os.chdir(vroot) or {} + if os_kind == 'windows' { + // Windows use ANSI encoding + getwd = iconv.encoding_to_vstring(getwd.bytes(), 'ANSI') or { getwd } + vmodules = iconv.encoding_to_vstring(vmodules.bytes(), 'ANSI') or { vmodules } + vtmp_dir = iconv.encoding_to_vstring(vtmp_dir.bytes(), 'ANSI') or { vtmp_dir } + vexe = iconv.encoding_to_vstring(vexe.bytes(), 'ANSI') or { vexe } + vroot = iconv.encoding_to_vstring(vroot.bytes(), 'ANSI') or { vroot } + } a.line('getwd', getwd) a.line('vexe', vexe) a.line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str()) From 6e3d13c07a324aa14e85bed95835dfa8790ff83d Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 4 Jan 2025 09:57:50 +0800 Subject: [PATCH 03/11] Update cmd/tools/vdoctor.v Co-authored-by: JalonSolov --- cmd/tools/vdoctor.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index e674ca73c009e7..289e81d5a2b430 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -119,7 +119,7 @@ fn (mut a App) collect_info() { vexe = iconv.encoding_to_vstring(vexe.bytes(), 'ANSI') or { vexe } vroot = iconv.encoding_to_vstring(vroot.bytes(), 'ANSI') or { vroot } } - a.line('getwd', getwd) + a.line('V home dir', getwd) a.line('vexe', vexe) a.line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str()) a.line('', '') From 9fd6840c9b91d055c64339fbb8854b77a232ec8e Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 4 Jan 2025 09:58:05 +0800 Subject: [PATCH 04/11] Update cmd/tools/vdoctor.v Co-authored-by: JalonSolov --- cmd/tools/vdoctor.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index 289e81d5a2b430..7fd4bf4f61da4e 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -120,7 +120,7 @@ fn (mut a App) collect_info() { vroot = iconv.encoding_to_vstring(vroot.bytes(), 'ANSI') or { vroot } } a.line('V home dir', getwd) - a.line('vexe', vexe) + a.line('V executable', vexe) a.line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str()) a.line('', '') a.line2('vroot', diagnose_dir(vroot), vroot) From 663a5f60ec65310b4b60839f8529f6235e238f32 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 4 Jan 2025 09:58:19 +0800 Subject: [PATCH 05/11] Update cmd/tools/vdoctor.v Co-authored-by: JalonSolov --- cmd/tools/vdoctor.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index 7fd4bf4f61da4e..b7ee78df95de26 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -121,7 +121,7 @@ fn (mut a App) collect_info() { } a.line('V home dir', getwd) a.line('V executable', vexe) - a.line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str()) + a.line('V last modified time', time.unix(os.file_last_mod_unix(vexe)).str()) a.line('', '') a.line2('vroot', diagnose_dir(vroot), vroot) a.line2('VMODULES', diagnose_dir(vmodules), vmodules) From 7c2384ed69c022c93a4d9825edc9913be9f60815 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 4 Jan 2025 09:58:28 +0800 Subject: [PATCH 06/11] Update cmd/tools/vdoctor.v Co-authored-by: JalonSolov --- cmd/tools/vdoctor.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index b7ee78df95de26..f0224eb09be7b0 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -123,7 +123,7 @@ fn (mut a App) collect_info() { a.line('V executable', vexe) a.line('V last modified time', time.unix(os.file_last_mod_unix(vexe)).str()) a.line('', '') - a.line2('vroot', diagnose_dir(vroot), vroot) + a.line2('V home dir', diagnose_dir(vroot), vroot) a.line2('VMODULES', diagnose_dir(vmodules), vmodules) a.line2('VTMP', diagnose_dir(vtmp_dir), vtmp_dir) vflags := os.getenv('VFLAGS') From a6523cc42a96dc4bc57dfa93f2610aab55947622 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 4 Jan 2025 09:58:41 +0800 Subject: [PATCH 07/11] Update cmd/tools/vdoctor.v Co-authored-by: JalonSolov --- cmd/tools/vdoctor.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index f0224eb09be7b0..a027417ec52c7c 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -133,7 +133,7 @@ fn (mut a App) collect_info() { a.line('', '') } a.line('Git version', a.cmd(command: 'git --version')) - a.line('Git vroot status', a.git_info()) + a.line('V git status', a.git_info()) a.line('.git/config present', os.is_file('.git/config').str()) a.line('', '') a.line('CC version', a.cmd(command: 'cc --version')) From 36ff432f7ab01e5340dc7ffc76a05359c81d47f8 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 4 Jan 2025 13:15:22 +0800 Subject: [PATCH 08/11] msvc for windows;glibc;gcc;clang;path encoding --- cmd/tools/vdoctor.v | 49 ++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index a027417ec52c7c..a195e739f1caf0 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -104,28 +104,19 @@ fn (mut a App) collect_info() { a.line('OS', '${os_kind}, ${os_details}') a.line('Processor', arch_details.join(', ')) a.line('', '') - // a.println('') - mut getwd := os.getwd() - mut vmodules := os.vmodules_dir() - mut vtmp_dir := os.vtmp_dir() mut vexe := os.getenv('VEXE') mut vroot := os.dir(vexe) + mut vmodules := os.vmodules_dir() + mut vtmp_dir := os.vtmp_dir() + mut getwd := os.getwd() os.chdir(vroot) or {} - if os_kind == 'windows' { - // Windows use ANSI encoding - getwd = iconv.encoding_to_vstring(getwd.bytes(), 'ANSI') or { getwd } - vmodules = iconv.encoding_to_vstring(vmodules.bytes(), 'ANSI') or { vmodules } - vtmp_dir = iconv.encoding_to_vstring(vtmp_dir.bytes(), 'ANSI') or { vtmp_dir } - vexe = iconv.encoding_to_vstring(vexe.bytes(), 'ANSI') or { vexe } - vroot = iconv.encoding_to_vstring(vroot.bytes(), 'ANSI') or { vroot } - } - a.line('V home dir', getwd) a.line('V executable', vexe) a.line('V last modified time', time.unix(os.file_last_mod_unix(vexe)).str()) a.line('', '') a.line2('V home dir', diagnose_dir(vroot), vroot) a.line2('VMODULES', diagnose_dir(vmodules), vmodules) a.line2('VTMP', diagnose_dir(vtmp_dir), vtmp_dir) + a.line2('Current dir', diagnose_dir(getwd), getwd) vflags := os.getenv('VFLAGS') a.line('', '') if vflags != '' { @@ -137,8 +128,15 @@ fn (mut a App) collect_info() { a.line('.git/config present', os.is_file('.git/config').str()) a.line('', '') a.line('CC version', a.cmd(command: 'cc --version')) - a.line('emcc version', a.cmd(command: 'emcc --version')) + a.line('GCC version', a.cmd(command: 'gcc --version')) + a.line('clang version', a.cmd(command: 'clang --version')) + if os_kind == 'windows' { + // Check for MSVC on windows + a.line('MSVC version', a.cmd(command: 'cl')) + } a.report_tcc_version('thirdparty/tcc') + a.line('glibc version', a.cmd(command: 'ldd --version')) + a.line('emcc version', a.cmd(command: 'emcc --version')) } struct CmdConfig { @@ -257,6 +255,14 @@ fn (mut a App) git_info() string { } fn (mut a App) report_tcc_version(tccfolder string) { + cmd := os.join_path(tccfolder, 'tcc.exe') + ' -v' + x := os.execute(cmd) + os_kind := os.user_os() + if x.exit_code == 0 { + a.line('tcc version', '${x.output.trim_space()}') + } else { + a.line('tcc version', 'N/A') + } if !os.is_file(os.join_path(tccfolder, '.git', 'config')) { a.line('tcc git status', 'N/A') } else { @@ -268,14 +274,6 @@ fn (mut a App) report_tcc_version(tccfolder string) { ) a.line('tcc git status', '${tcc_branch_name} ${tcc_commit}') } - cmd := os.join_path(tccfolder, 'tcc.exe') + ' -v' - x := os.execute(cmd) - os_kind := os.user_os() - if x.exit_code == 0 { - a.line('tcc version', '${x.output.trim_space()}') - } else { - a.line('tcc version', 'N/A') - } } fn (mut a App) report_info() { @@ -294,13 +292,6 @@ fn diagnose_dir(path string) string { if !is_writable_dir(path) { diagnostics << 'NOT writable' } - if path.contains(' ') { - diagnostics << 'contains spaces' - } - path_non_ascii_runes := path.runes().filter(it > 255) - if path_non_ascii_runes.len > 0 { - diagnostics << 'contains these non ASCII characters: ${path_non_ascii_runes}' - } if diagnostics.len == 0 { diagnostics << 'OK' } From ed90c8e2ddb77fbb334d1afe0f78792fda05294d Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 4 Jan 2025 13:16:44 +0800 Subject: [PATCH 09/11] typo --- cmd/tools/vdoctor.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index a195e739f1caf0..4a396ad85f1a40 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -116,7 +116,7 @@ fn (mut a App) collect_info() { a.line2('V home dir', diagnose_dir(vroot), vroot) a.line2('VMODULES', diagnose_dir(vmodules), vmodules) a.line2('VTMP', diagnose_dir(vtmp_dir), vtmp_dir) - a.line2('Current dir', diagnose_dir(getwd), getwd) + a.line2('Current working dir', diagnose_dir(getwd), getwd) vflags := os.getenv('VFLAGS') a.line('', '') if vflags != '' { From 1fbb77e1c353153202bbbca709d4e86a49ab6f1b Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 4 Jan 2025 13:43:47 +0800 Subject: [PATCH 10/11] add free memory/total memory --- cmd/tools/vdoctor.v | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index 4a396ad85f1a40..3bbd85c69f1280 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -103,6 +103,10 @@ fn (mut a App) collect_info() { } a.line('OS', '${os_kind}, ${os_details}') a.line('Processor', arch_details.join(', ')) + total_memory := f64(runtime.total_memory()) / (1024.0 * 1024.0 * 1024.0) + free_memory := f64(runtime.free_memory()) / (1024.0 * 1024.0 * 1024.0) + a.line('Memory', '${free_memory:.2}GB/${total_memory:.2}GB') + a.line('', '') mut vexe := os.getenv('VEXE') mut vroot := os.dir(vexe) From a68b990eb9c33e0e044812d66ae77f9636e3f880 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 4 Jan 2025 14:03:04 +0800 Subject: [PATCH 11/11] fix --- cmd/tools/vdoctor.v | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index 3bbd85c69f1280..5cbd49c5d9f6df 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -103,9 +103,13 @@ fn (mut a App) collect_info() { } a.line('OS', '${os_kind}, ${os_details}') a.line('Processor', arch_details.join(', ')) - total_memory := f64(runtime.total_memory()) / (1024.0 * 1024.0 * 1024.0) - free_memory := f64(runtime.free_memory()) / (1024.0 * 1024.0 * 1024.0) - a.line('Memory', '${free_memory:.2}GB/${total_memory:.2}GB') + total_memory := f32(runtime.total_memory()) / (1024.0 * 1024.0 * 1024.0) + free_memory := f32(runtime.free_memory()) / (1024.0 * 1024.0 * 1024.0) + if total_memory != 0 && free_memory != 0 { + a.line('Memory', '${free_memory:.2}GB/${total_memory:.2}GB') + } else { + a.line('Memory', 'N/A') + } a.line('', '') mut vexe := os.getenv('VEXE') @@ -132,15 +136,14 @@ fn (mut a App) collect_info() { a.line('.git/config present', os.is_file('.git/config').str()) a.line('', '') a.line('CC version', a.cmd(command: 'cc --version')) - a.line('GCC version', a.cmd(command: 'gcc --version')) + a.line('gcc version', a.cmd(command: 'gcc --version')) a.line('clang version', a.cmd(command: 'clang --version')) if os_kind == 'windows' { // Check for MSVC on windows - a.line('MSVC version', a.cmd(command: 'cl')) + a.line('msvc version', a.cmd(command: 'cl')) } a.report_tcc_version('thirdparty/tcc') a.line('glibc version', a.cmd(command: 'ldd --version')) - a.line('emcc version', a.cmd(command: 'emcc --version')) } struct CmdConfig { @@ -296,6 +299,13 @@ fn diagnose_dir(path string) string { if !is_writable_dir(path) { diagnostics << 'NOT writable' } + if path.contains(' ') { + diagnostics << 'contains spaces' + } + path_non_ascii_runes := path.runes().filter(it > 255) + if path_non_ascii_runes.len > 0 { + diagnostics << 'contains these non ASCII characters: ${path_non_ascii_runes}' + } if diagnostics.len == 0 { diagnostics << 'OK' }