1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tools: make v doctor more informative

This commit is contained in:
Delyan Angelov 2023-03-13 11:44:03 +02:00
parent 5cb1f8965a
commit 4ba7ad9446

View File

@ -15,6 +15,8 @@ fn (mut a App) println(s string) {
}
fn (mut a App) collect_info() {
a.line('V full version', version.full_v_version(true))
//
mut os_kind := os.user_os()
mut arch_details := []string{}
arch_details << '${runtime.nr_cpus()} cpus'
@ -96,34 +98,32 @@ fn (mut a App) collect_info() {
}
a.line('OS', '${os_kind}, ${os_details}')
a.line('Processor', arch_details.join(', '))
a.line('CC version', a.cmd(command: 'cc --version'))
a.println('')
getwd := os.getwd()
vmodules := os.vmodules_dir()
vtmp_dir := os.vtmp_dir()
vexe := os.getenv('VEXE')
vroot := os.dir(vexe)
os.chdir(vroot) or {}
a.line('getwd', getwd)
a.line('vmodules', vmodules)
a.line('vroot', vroot)
a.line('vexe', vexe)
a.line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str())
a.line('is vroot writable', is_writable_dir(vroot).str())
a.line('is vmodules writable', is_writable_dir(vmodules).str())
a.line('V full version', version.full_v_version(true))
vtmp := os.getenv('VTMP')
if vtmp != '' {
a.line('env VTMP', '"${vtmp}"')
}
a.println('')
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('')
if vflags != '' {
a.line('env VFLAGS', '"${vflags}"')
a.println('')
}
a.println('')
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('CC version', a.cmd(command: 'cc --version'))
a.report_tcc_version('thirdparty/tcc')
}
@ -153,6 +153,11 @@ fn (mut a App) line(label string, value string) {
a.println('${label}: ${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,
value2)}')
}
fn (app &App) parse(config string, sep string) map[string]string {
mut m := map[string]string{}
lines := config.split_into_lines()
@ -261,6 +266,24 @@ fn is_writable_dir(path string) bool {
return true
}
fn diagnose_dir(path string) string {
mut diagnostics := []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'
}
return diagnostics.join(', ')
}
fn main() {
mut app := App{}
app.collect_info()