doctor: report tcc location/branch/commit too

pull/6445/head
Delyan Angelov 2020-09-21 21:46:51 +03:00
parent 61330c60b5
commit f66dcbe6e5
1 changed files with 70 additions and 33 deletions

View File

@ -4,7 +4,16 @@ import time
import v.util import v.util
import runtime import runtime
fn main(){ struct App {
mut:
report_lines []string
}
fn (mut a App) println(s string) {
a.report_lines << s
}
fn (mut a App) collect_info() {
mut os_kind := os.user_os() mut os_kind := os.user_os()
mut arch_details := []string{} mut arch_details := []string{}
arch_details << '${runtime.nr_cpus()} cpus' arch_details << '${runtime.nr_cpus()} cpus'
@ -21,62 +30,68 @@ fn main(){
arch_details << 'little endian' arch_details << 'little endian'
} }
if os_kind == 'mac' { if os_kind == 'mac' {
arch_details << cmd(command:'sysctl -n machdep.cpu.brand_string') arch_details << a.cmd(command:'sysctl -n machdep.cpu.brand_string')
} }
if os_kind == 'linux' { if os_kind == 'linux' {
mname := cmd(command:'grep "model name" /proc/cpuinfo | sed "s/.*: //gm"') mname := a.cmd(command:'grep "model name" /proc/cpuinfo | sed "s/.*: //gm"')
if !mname.starts_with('Error:') { if !mname.starts_with('Error:') {
arch_details << mname arch_details << mname
} else { } else {
hinfo := cmd(command:'grep "Hardware" /proc/cpuinfo | sed "s/.*: //gm"') hinfo := a.cmd(command:'grep "Hardware" /proc/cpuinfo | sed "s/.*: //gm"')
arch_details << hinfo arch_details << hinfo
} }
} }
if os_kind == 'windows' { if os_kind == 'windows' {
arch_details << cmd(command:'wmic cpu get name /format:table', line: 1) arch_details << a.cmd(command:'wmic cpu get name /format:table', line: 1)
} }
// //
mut os_details := '' mut os_details := ''
if os_kind == 'linux' { if os_kind == 'linux' {
os_details = get_linux_os_name() os_details = a.get_linux_os_name()
} else if os_kind == 'mac' { } else if os_kind == 'mac' {
mut details := []string{} mut details := []string{}
details << cmd(command: 'sw_vers -productName') details << a.cmd(command: 'sw_vers -productName')
details << cmd(command: 'sw_vers -productVersion') details << a.cmd(command: 'sw_vers -productVersion')
details << cmd(command: 'sw_vers -buildVersion') details << a.cmd(command: 'sw_vers -buildVersion')
os_details = details.join(', ') os_details = details.join(', ')
} else if os_kind == 'windows' { } else if os_kind == 'windows' {
os_details = cmd(command:'wmic os get name, buildnumber, osarchitecture', line: 1) os_details = a.cmd(command:'wmic os get name, buildnumber, osarchitecture', line: 1)
} else { } else {
ouname := os.uname() ouname := os.uname()
os_details = '$ouname.release, $ouname.version' os_details = '$ouname.release, $ouname.version'
} }
line('OS', '$os_kind, $os_details') a.line('OS', '$os_kind, $os_details')
line('Processor', arch_details.join(', ')) a.line('Processor', arch_details.join(', '))
line('CC version', cmd(command:'cc --version')) a.line('CC version', a.cmd(command:'cc --version'))
println(util.bold(term.h_divider('-'))) a.println(util.bold(term.h_divider('-')))
vexe := os.getenv('VEXE') vexe := os.getenv('VEXE')
vroot := os.dir(vexe) vroot := os.dir(vexe)
os.chdir(vroot) os.chdir(vroot)
line('vroot', vroot) a.line('vroot', vroot)
line('vexe', vexe) a.line('vexe', vexe)
line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str()) a.line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str())
is_writable_vroot := os.is_writable_folder(vroot) or { false } is_writable_vroot := os.is_writable_folder(vroot) or { false }
line('is vroot writable', is_writable_vroot.str()) a.line('is vroot writable', is_writable_vroot.str())
line('V full version', util.full_v_version(true)) a.line('V full version', util.full_v_version(true))
vtmp := os.getenv('VTMP') vtmp := os.getenv('VTMP')
if vtmp != '' { if vtmp != '' {
line('env VTMP', '"$vtmp"') a.line('env VTMP', '"$vtmp"')
} }
vflags := os.getenv('VFLAGS') vflags := os.getenv('VFLAGS')
if vflags != '' { if vflags != '' {
line('env VFLAGS', '"$vflags"') a.line('env VFLAGS', '"$vflags"')
} }
println(util.bold(term.h_divider('-'))) a.println(util.bold(term.h_divider('-')))
line('Git version', cmd(command:'git --version')) a.line('Git version', a.cmd(command:'git --version'))
line('Git vroot status', cmd(command:'git -C . describe --abbrev=8 --dirty --always --tags')) a.line('Git vroot status', a.cmd(command:'git -C . describe --abbrev=8 --dirty --always --tags'))
line('.git/config present', os.is_file('.git/config').str()) a.line('.git/config present', os.is_file('.git/config').str())
println(util.bold(term.h_divider('-'))) //
if os_kind == 'linux' {
a.report_tcc_version('/var/tmp/tcc')
}
a.report_tcc_version('thirdparty/tcc')
//
a.println(util.bold(term.h_divider('-')))
} }
struct CmdConfig { struct CmdConfig {
@ -84,7 +99,7 @@ struct CmdConfig {
command string command string
} }
fn cmd(c CmdConfig) string { fn (mut a App) cmd(c CmdConfig) string {
x := os.exec(c.command) or { x := os.exec(c.command) or {
return 'N/A' return 'N/A'
} }
@ -97,11 +112,11 @@ fn cmd(c CmdConfig) string {
return 'Error: $x.output' return 'Error: $x.output'
} }
fn line(label string, value string) { fn (mut a App) line(label string, value string) {
println('$label: ${util.bold(value)}') a.println('$label: ${util.bold(value)}')
} }
fn get_linux_os_name() string { fn (mut a App) get_linux_os_name() string {
mut os_details := '' mut os_details := ''
linux_os_methods := ['os-release', 'lsb_release', 'kernel', 'uname'] linux_os_methods := ['os-release', 'lsb_release', 'kernel', 'uname']
for m in linux_os_methods { for m in linux_os_methods {
@ -125,18 +140,18 @@ fn get_linux_os_name() string {
break break
} }
'lsb_release' { 'lsb_release' {
exists := cmd(command:'type lsb_release') exists := a.cmd(command:'type lsb_release')
if exists.starts_with('Error') { if exists.starts_with('Error') {
continue continue
} }
os_details = cmd(command: 'lsb_release -d -s') os_details = a.cmd(command: 'lsb_release -d -s')
break break
} }
'kernel' { 'kernel' {
if !os.is_file('/proc/version') { if !os.is_file('/proc/version') {
continue continue
} }
os_details = cmd(command: 'cat /proc/version') os_details = a.cmd(command: 'cat /proc/version')
break break
} }
'uname' { 'uname' {
@ -149,3 +164,25 @@ fn get_linux_os_name() string {
} }
return os_details return os_details
} }
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
}
tcc_branch_name := a.cmd(command:'git -C $tccfolder rev-parse --abbrev-ref HEAD')
tcc_commit := a.cmd(command:'git -C $tccfolder describe --abbrev=8 --dirty --always --tags')
a.line('$tccfolder status', '$tcc_branch_name $tcc_commit')
}
fn (mut a App) report_info() {
for x in a.report_lines {
println(x)
}
}
fn main(){
mut app := App{}
app.collect_info()
app.report_info()
}