Skip to content

Commit

Permalink
tools: fix v doctor format, fixes for windows, tcc and others (#23361)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbkpbot authored Jan 4, 2025
1 parent ac71f9e commit 30de072
Showing 1 changed file with 59 additions and 31 deletions.
90 changes: 59 additions & 31 deletions cmd/tools/vdoctor.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import time
import term
import v.util.version
import runtime
import encoding.iconv

struct App {
mut:
Expand All @@ -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{}
Expand Down Expand Up @@ -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
)
}

Expand Down Expand Up @@ -90,41 +92,58 @@ fn (mut a App) collect_info() {
line: -1
)
p := a.parse(wmic_info, '=')
caption, build_number, os_arch := p['caption'], p['buildnumber'], p['osarchitecture']
os_details = '${caption} v${build_number} ${os_arch}'
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}'
}
a.line('OS', '${os_kind}, ${os_details}')
a.line('Processor', arch_details.join(', '))
a.println('')
getwd := os.getwd()
vmodules := os.vmodules_dir()
vtmp_dir := os.vtmp_dir()
vexe := os.getenv('VEXE')
vroot := os.dir(vexe)
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')
mut vroot := os.dir(vexe)
mut vmodules := os.vmodules_dir()
mut vtmp_dir := os.vtmp_dir()
mut getwd := os.getwd()
os.chdir(vroot) or {}
a.line('getwd', getwd)
a.line('vexe', vexe)
a.line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str())
a.println('')
a.line2('vroot', diagnose_dir(vroot), vroot)
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 working dir', diagnose_dir(getwd), getwd)
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('V git 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.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'))
}

struct CmdConfig {
Expand All @@ -134,7 +153,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 {
Expand All @@ -150,11 +170,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)}')
}

Expand Down Expand Up @@ -242,17 +262,25 @@ 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(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}')
}
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() {
Expand Down

0 comments on commit 30de072

Please sign in to comment.