doctor: detect if running in a VM / WSL / chroot (#6447)
parent
46be0710ac
commit
d44eabe247
|
@ -49,6 +49,9 @@ jobs:
|
||||||
run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v
|
run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v
|
||||||
- name: Test building v tools
|
- name: Test building v tools
|
||||||
run: ./v build-tools
|
run: ./v build-tools
|
||||||
|
- name: v doctor
|
||||||
|
run: |
|
||||||
|
./v doctor
|
||||||
- name: v vet
|
- name: v vet
|
||||||
run: |
|
run: |
|
||||||
./v vet vlib/sqlite
|
./v vet vlib/sqlite
|
||||||
|
@ -127,6 +130,9 @@ jobs:
|
||||||
run: VJOBS=1 ./v test-fixed
|
run: VJOBS=1 ./v test-fixed
|
||||||
- name: Build examples
|
- name: Build examples
|
||||||
run: ./v build-examples
|
run: ./v build-examples
|
||||||
|
- name: v doctor
|
||||||
|
run: |
|
||||||
|
./v doctor
|
||||||
- name: v vet
|
- name: v vet
|
||||||
run: |
|
run: |
|
||||||
./v vet vlib/sqlite
|
./v vet vlib/sqlite
|
||||||
|
@ -342,6 +348,9 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
./v -cg cmd\tools\vtest-fixed.v
|
./v -cg cmd\tools\vtest-fixed.v
|
||||||
./v test-fixed
|
./v test-fixed
|
||||||
|
- name: v doctor
|
||||||
|
run: |
|
||||||
|
./v doctor
|
||||||
# - name: Test
|
# - name: Test
|
||||||
# run: |
|
# run: |
|
||||||
# .\v.exe -silent test-compiler
|
# .\v.exe -silent test-compiler
|
||||||
|
|
|
@ -7,6 +7,7 @@ import runtime
|
||||||
struct App {
|
struct App {
|
||||||
mut:
|
mut:
|
||||||
report_lines []string
|
report_lines []string
|
||||||
|
cached_cpuinfo map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut a App) println(s string) {
|
fn (mut a App) println(s string) {
|
||||||
|
@ -33,12 +34,11 @@ fn (mut a App) collect_info() {
|
||||||
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' {
|
if os_kind == 'linux' {
|
||||||
mname := a.cmd(command:'grep "model name" /proc/cpuinfo | sed "s/.*: //gm"')
|
info := a.cpu_info()
|
||||||
if !mname.starts_with('Error:') {
|
if info['model name'] != '' {
|
||||||
arch_details << mname
|
arch_details << info['model name']
|
||||||
} else {
|
} else {
|
||||||
hinfo := a.cmd(command:'grep "Hardware" /proc/cpuinfo | sed "s/.*: //gm"')
|
arch_details << info['hardware']
|
||||||
arch_details << hinfo
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if os_kind == 'windows' {
|
if os_kind == 'windows' {
|
||||||
|
@ -48,6 +48,18 @@ fn (mut a App) collect_info() {
|
||||||
mut os_details := ''
|
mut os_details := ''
|
||||||
if os_kind == 'linux' {
|
if os_kind == 'linux' {
|
||||||
os_details = a.get_linux_os_name()
|
os_details = a.get_linux_os_name()
|
||||||
|
info := a.cpu_info()
|
||||||
|
if 'hypervisor' in info['flags'] {
|
||||||
|
if 'microsoft' in a.cmd(command: 'cat /proc/sys/kernel/osrelease') {
|
||||||
|
os_details += ' (WSL)'
|
||||||
|
} else {
|
||||||
|
os_details += ' (VM)'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// From https://unix.stackexchange.com/a/14346
|
||||||
|
if a.cmd(command: '[ "$(awk \'\$5=="/" {print \$1}\' </proc/1/mountinfo)" != "$(awk \'\$5=="/" {print \$1}\' </proc/$$/mountinfo)" ] ; echo \$?') == '0' {
|
||||||
|
os_details += ' (chroot)'
|
||||||
|
}
|
||||||
} else if os_kind == 'mac' {
|
} else if os_kind == 'mac' {
|
||||||
mut details := []string{}
|
mut details := []string{}
|
||||||
details << a.cmd(command: 'sw_vers -productName')
|
details << a.cmd(command: 'sw_vers -productName')
|
||||||
|
@ -175,6 +187,29 @@ fn (mut a App) get_linux_os_name() string {
|
||||||
return os_details
|
return os_details
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn (mut a App) cpu_info() map[string]string {
|
||||||
|
if a.cached_cpuinfo.len > 0 {
|
||||||
|
return a.cached_cpuinfo
|
||||||
|
}
|
||||||
|
|
||||||
|
info := os.exec('cat /proc/cpuinfo') or { return a.cached_cpuinfo }
|
||||||
|
mut vals := map[string]string
|
||||||
|
for line in info.output.split_into_lines() {
|
||||||
|
sline := line.trim(' ')
|
||||||
|
if sline.len < 1 || sline[0] == `#`{
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
x := sline.split(':')
|
||||||
|
if x.len < 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
vals[x[0].trim_space().to_lower()] = x[1].trim_space().trim('"')
|
||||||
|
}
|
||||||
|
|
||||||
|
a.cached_cpuinfo = vals
|
||||||
|
return vals
|
||||||
|
}
|
||||||
|
|
||||||
fn (mut a App) report_tcc_version(tccfolder string) {
|
fn (mut a App) report_tcc_version(tccfolder string) {
|
||||||
if !os.is_file(os.join_path(tccfolder, '.git', 'config')) {
|
if !os.is_file(os.join_path(tccfolder, '.git', 'config')) {
|
||||||
a.line(tccfolder, 'N/A')
|
a.line(tccfolder, 'N/A')
|
||||||
|
|
Loading…
Reference in New Issue