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

tools: fix v -prod cmd/tools/vdoctor.v

This commit is contained in:
Delyan Angelov 2021-03-24 10:31:42 +02:00
parent f885c7cea9
commit 0bde55f77e
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -30,9 +30,7 @@ fn (mut a App) collect_info() {
arch_details << 'little endian'
}
if os_kind == 'macos' {
arch_details << a.cmd(
command: 'sysctl -n machdep.cpu.brand_string'
)
arch_details << a.cmd(command: 'sysctl -n machdep.cpu.brand_string')
}
if os_kind == 'linux' {
mut cpu_details := ''
@ -55,13 +53,11 @@ fn (mut a App) collect_info() {
}
//
mut os_details := ''
wsl_check := a.cmd(
command: 'cat /proc/sys/kernel/osrelease'
)
wsl_check := a.cmd(command: 'cat /proc/sys/kernel/osrelease')
if os_kind == 'linux' {
os_details = a.get_linux_os_name()
if 'hypervisor' in a.cpu_info('flags') {
if 'microsoft' in wsl_check {
if a.cpu_info('flags').contains('hypervisor') {
if wsl_check.contains('microsoft') {
// WSL 2 is a Managed VM and Full Linux Kernel
// See https://docs.microsoft.com/en-us/windows/wsl/compare-versions
os_details += ' (WSL 2)'
@ -71,7 +67,7 @@ fn (mut a App) collect_info() {
}
// WSL 1 is NOT a Managed VM and Full Linux Kernel
// See https://docs.microsoft.com/en-us/windows/wsl/compare-versions
if 'Microsoft' in wsl_check {
if wsl_check.contains('Microsoft') {
os_details += ' (WSL)'
}
// From https://unix.stackexchange.com/a/14346
@ -81,15 +77,9 @@ fn (mut a App) collect_info() {
}
} else if os_kind == 'macos' {
mut details := []string{}
details << a.cmd(
command: 'sw_vers -productName'
)
details << a.cmd(
command: 'sw_vers -productVersion'
)
details << a.cmd(
command: 'sw_vers -buildVersion'
)
details << a.cmd(command: 'sw_vers -productName')
details << a.cmd(command: 'sw_vers -productVersion')
details << a.cmd(command: 'sw_vers -buildVersion')
os_details = details.join(', ')
} else if os_kind == 'windows' {
wmic_info := a.cmd(
@ -105,9 +95,7 @@ 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.line('CC version', a.cmd(command: 'cc --version'))
a.println('')
getwd := os.getwd()
vmodules := os.vmodules_dir()
@ -131,9 +119,7 @@ fn (mut a App) collect_info() {
a.line('env VFLAGS', '"$vflags"')
}
a.println('')
a.line('Git version', a.cmd(
command: 'git --version'
))
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())
//
@ -168,7 +154,8 @@ fn (mut a App) line(label string, value string) {
fn (app &App) parse(config string, sep string) map[string]string {
mut m := map[string]string{}
for line in config.split_into_lines() {
lines := config.split_into_lines()
for line in lines {
sline := line.trim_space()
if sline.len == 0 || sline[0] == `#` {
continue
@ -200,24 +187,18 @@ fn (mut a App) get_linux_os_name() string {
break
}
'lsb_release' {
exists := a.cmd(
command: 'type lsb_release'
)
exists := a.cmd(command: 'type lsb_release')
if exists.starts_with('Error') {
continue
}
os_details = a.cmd(
command: 'lsb_release -d -s'
)
os_details = a.cmd(command: 'lsb_release -d -s')
break
}
'kernel' {
if !os.is_file('/proc/version') {
continue
}
os_details = a.cmd(
command: 'cat /proc/version'
)
os_details = a.cmd(command: 'cat /proc/version')
break
}
'uname' {
@ -244,14 +225,10 @@ fn (mut a App) cpu_info(key string) string {
}
fn (mut a App) git_info() string {
mut out := a.cmd(
command: 'git -C . describe --abbrev=8 --dirty --always --tags'
).trim_space()
mut out := a.cmd(command: 'git -C . describe --abbrev=8 --dirty --always --tags').trim_space()
os.execute('git -C . remote add V_REPO https://github.com/vlang/v') // ignore failure (i.e. remote exists)
os.execute('git -C . fetch V_REPO')
commit_count := a.cmd(
command: 'git rev-list @{0}...V_REPO/master --right-only --count'
).int()
commit_count := a.cmd(command: 'git rev-list @{0}...V_REPO/master --right-only --count').int()
if commit_count > 0 {
out += ' ($commit_count commit(s) behind V master)'
}
@ -263,12 +240,8 @@ fn (mut a App) report_tcc_version(tccfolder string) {
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'
)
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')
}