2020-09-20 12:13:20 +02:00
|
|
|
import os
|
|
|
|
import time
|
2021-07-27 11:35:54 +02:00
|
|
|
import term
|
|
|
|
import v.util.version
|
2020-09-20 12:13:20 +02:00
|
|
|
import runtime
|
|
|
|
|
2020-09-21 20:46:51 +02:00
|
|
|
struct App {
|
|
|
|
mut:
|
2020-09-22 16:41:32 +02:00
|
|
|
report_lines []string
|
|
|
|
cached_cpuinfo map[string]string
|
2020-09-21 20:46:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn (mut a App) println(s string) {
|
|
|
|
a.report_lines << s
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (mut a App) collect_info() {
|
2020-09-20 13:37:51 +02:00
|
|
|
mut os_kind := os.user_os()
|
2020-09-20 12:13:20 +02:00
|
|
|
mut arch_details := []string{}
|
2020-10-21 13:36:16 +02:00
|
|
|
arch_details << '$runtime.nr_cpus() cpus'
|
2020-09-20 12:13:20 +02:00
|
|
|
if runtime.is_32bit() {
|
|
|
|
arch_details << '32bit'
|
|
|
|
}
|
|
|
|
if runtime.is_64bit() {
|
|
|
|
arch_details << '64bit'
|
|
|
|
}
|
|
|
|
if runtime.is_big_endian() {
|
|
|
|
arch_details << 'big endian'
|
|
|
|
}
|
|
|
|
if runtime.is_little_endian() {
|
|
|
|
arch_details << 'little endian'
|
|
|
|
}
|
2020-09-29 21:10:33 +02:00
|
|
|
if os_kind == 'macos' {
|
2021-03-24 09:31:42 +01:00
|
|
|
arch_details << a.cmd(command: 'sysctl -n machdep.cpu.brand_string')
|
2020-09-20 13:37:51 +02:00
|
|
|
}
|
|
|
|
if os_kind == 'linux' {
|
2020-12-03 18:15:17 +01:00
|
|
|
mut cpu_details := ''
|
|
|
|
if cpu_details == '' {
|
2021-02-16 12:46:12 +01:00
|
|
|
cpu_details = a.cpu_info('model name')
|
2020-09-21 20:21:07 +02:00
|
|
|
}
|
2020-12-03 18:15:17 +01:00
|
|
|
if cpu_details == '' {
|
2021-02-16 12:46:12 +01:00
|
|
|
cpu_details = a.cpu_info('hardware')
|
2020-12-03 18:15:17 +01:00
|
|
|
}
|
|
|
|
if cpu_details == '' {
|
|
|
|
cpu_details = os.uname().machine
|
|
|
|
}
|
|
|
|
arch_details << cpu_details
|
2020-09-20 13:37:51 +02:00
|
|
|
}
|
|
|
|
if os_kind == 'windows' {
|
2021-03-08 19:52:13 +01:00
|
|
|
arch_details << a.cmd(
|
2020-10-21 13:36:16 +02:00
|
|
|
command: 'wmic cpu get name /format:table'
|
|
|
|
line: 1
|
2021-03-08 19:52:13 +01:00
|
|
|
)
|
2020-09-20 13:37:51 +02:00
|
|
|
}
|
|
|
|
//
|
2020-09-20 12:13:20 +02:00
|
|
|
mut os_details := ''
|
2021-03-24 09:31:42 +01:00
|
|
|
wsl_check := a.cmd(command: 'cat /proc/sys/kernel/osrelease')
|
2020-09-20 12:13:20 +02:00
|
|
|
if os_kind == 'linux' {
|
2020-09-21 20:46:51 +02:00
|
|
|
os_details = a.get_linux_os_name()
|
2021-03-24 09:31:42 +01:00
|
|
|
if a.cpu_info('flags').contains('hypervisor') {
|
|
|
|
if wsl_check.contains('microsoft') {
|
2020-12-02 14:41:13 +01:00
|
|
|
// 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)'
|
2020-09-22 16:41:32 +02:00
|
|
|
} else {
|
|
|
|
os_details += ' (VM)'
|
|
|
|
}
|
|
|
|
}
|
2020-12-02 14:41:13 +01:00
|
|
|
// WSL 1 is NOT a Managed VM and Full Linux Kernel
|
|
|
|
// See https://docs.microsoft.com/en-us/windows/wsl/compare-versions
|
2021-03-24 09:31:42 +01:00
|
|
|
if wsl_check.contains('Microsoft') {
|
2020-12-02 14:41:13 +01:00
|
|
|
os_details += ' (WSL)'
|
|
|
|
}
|
2020-09-22 16:41:32 +02:00
|
|
|
// From https://unix.stackexchange.com/a/14346
|
2021-03-08 19:52:13 +01:00
|
|
|
awk_cmd := '[ "$(awk \'\$5=="/" {print \$1}\' </proc/1/mountinfo)" != "$(awk \'\$5=="/" {print \$1}\' </proc/$$/mountinfo)" ] ; echo \$?'
|
|
|
|
if a.cmd(command: awk_cmd) == '0' {
|
2020-09-22 16:41:32 +02:00
|
|
|
os_details += ' (chroot)'
|
|
|
|
}
|
2020-09-29 21:10:33 +02:00
|
|
|
} else if os_kind == 'macos' {
|
2020-09-21 16:36:31 +02:00
|
|
|
mut details := []string{}
|
2021-03-24 09:31:42 +01:00
|
|
|
details << a.cmd(command: 'sw_vers -productName')
|
|
|
|
details << a.cmd(command: 'sw_vers -productVersion')
|
|
|
|
details << a.cmd(command: 'sw_vers -buildVersion')
|
2020-09-20 13:37:51 +02:00
|
|
|
os_details = details.join(', ')
|
2020-09-20 14:28:34 +02:00
|
|
|
} else if os_kind == 'windows' {
|
2021-03-08 19:52:13 +01:00
|
|
|
wmic_info := a.cmd(
|
2020-10-21 13:36:16 +02:00
|
|
|
command: 'wmic os get * /format:value'
|
|
|
|
line: -1
|
2021-03-08 19:52:13 +01:00
|
|
|
)
|
2020-09-25 18:24:00 +02:00
|
|
|
p := a.parse(wmic_info, '=')
|
|
|
|
caption, build_number, os_arch := p['caption'], p['buildnumber'], p['osarchitecture']
|
|
|
|
os_details = '$caption v$build_number $os_arch'
|
2020-09-20 14:28:34 +02:00
|
|
|
} else {
|
|
|
|
ouname := os.uname()
|
|
|
|
os_details = '$ouname.release, $ouname.version'
|
2020-09-20 13:37:51 +02:00
|
|
|
}
|
2020-09-21 20:46:51 +02:00
|
|
|
a.line('OS', '$os_kind, $os_details')
|
|
|
|
a.line('Processor', arch_details.join(', '))
|
2021-03-24 09:31:42 +01:00
|
|
|
a.line('CC version', a.cmd(command: 'cc --version'))
|
2020-09-24 15:36:04 +02:00
|
|
|
a.println('')
|
2020-12-05 21:30:59 +01:00
|
|
|
getwd := os.getwd()
|
|
|
|
vmodules := os.vmodules_dir()
|
2020-09-20 12:13:20 +02:00
|
|
|
vexe := os.getenv('VEXE')
|
|
|
|
vroot := os.dir(vexe)
|
2021-08-28 09:23:01 +02:00
|
|
|
os.chdir(vroot) or {}
|
2020-12-05 21:30:59 +01:00
|
|
|
a.line('getwd', getwd)
|
|
|
|
a.line('vmodules', vmodules)
|
2020-09-21 20:46:51 +02:00
|
|
|
a.line('vroot', vroot)
|
|
|
|
a.line('vexe', vexe)
|
|
|
|
a.line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str())
|
2020-12-05 21:30:59 +01:00
|
|
|
a.line('is vroot writable', is_writable_dir(vroot).str())
|
|
|
|
a.line('is vmodules writable', is_writable_dir(vmodules).str())
|
2021-07-27 11:35:54 +02:00
|
|
|
a.line('V full version', version.full_v_version(true))
|
2020-09-21 16:36:31 +02:00
|
|
|
vtmp := os.getenv('VTMP')
|
|
|
|
if vtmp != '' {
|
2020-09-21 20:46:51 +02:00
|
|
|
a.line('env VTMP', '"$vtmp"')
|
2020-09-21 16:36:31 +02:00
|
|
|
}
|
|
|
|
vflags := os.getenv('VFLAGS')
|
|
|
|
if vflags != '' {
|
2020-09-21 20:46:51 +02:00
|
|
|
a.line('env VFLAGS', '"$vflags"')
|
2020-09-21 16:36:31 +02:00
|
|
|
}
|
2020-09-24 15:36:04 +02:00
|
|
|
a.println('')
|
2021-03-24 09:31:42 +01:00
|
|
|
a.line('Git version', a.cmd(command: 'git --version'))
|
2020-09-25 18:24:00 +02:00
|
|
|
a.line('Git vroot status', a.git_info())
|
2020-09-21 20:46:51 +02:00
|
|
|
a.line('.git/config present', os.is_file('.git/config').str())
|
|
|
|
//
|
|
|
|
a.report_tcc_version('thirdparty/tcc')
|
2020-09-20 12:13:20 +02:00
|
|
|
}
|
|
|
|
|
2020-09-20 13:49:27 +02:00
|
|
|
struct CmdConfig {
|
2020-10-21 13:36:16 +02:00
|
|
|
line int
|
2020-09-20 13:49:27 +02:00
|
|
|
command string
|
|
|
|
}
|
|
|
|
|
2020-09-21 20:46:51 +02:00
|
|
|
fn (mut a App) cmd(c CmdConfig) string {
|
2021-03-08 19:52:13 +01:00
|
|
|
x := os.execute(c.command)
|
|
|
|
if x.exit_code < 0 {
|
2020-09-20 12:13:20 +02:00
|
|
|
return 'N/A'
|
|
|
|
}
|
|
|
|
if x.exit_code == 0 {
|
2020-10-21 13:36:16 +02:00
|
|
|
if c.line < 0 {
|
|
|
|
return x.output
|
|
|
|
}
|
2020-09-21 20:21:07 +02:00
|
|
|
output := x.output.split_into_lines()
|
|
|
|
if output.len > 0 && output.len > c.line {
|
|
|
|
return output[c.line]
|
|
|
|
}
|
2020-09-20 12:13:20 +02:00
|
|
|
}
|
2020-09-20 14:28:34 +02:00
|
|
|
return 'Error: $x.output'
|
2020-09-20 12:13:20 +02:00
|
|
|
}
|
|
|
|
|
2020-09-21 20:46:51 +02:00
|
|
|
fn (mut a App) line(label string, value string) {
|
2021-07-27 11:35:54 +02:00
|
|
|
a.println('$label: ${term.colorize(term.bold, value)}')
|
2020-09-20 12:13:20 +02:00
|
|
|
}
|
2020-09-21 16:36:31 +02:00
|
|
|
|
2020-10-15 15:17:52 +02:00
|
|
|
fn (app &App) parse(config string, sep string) map[string]string {
|
2020-10-21 13:36:16 +02:00
|
|
|
mut m := map[string]string{}
|
2021-03-24 09:31:42 +01:00
|
|
|
lines := config.split_into_lines()
|
|
|
|
for line in lines {
|
2020-09-25 18:24:00 +02:00
|
|
|
sline := line.trim_space()
|
|
|
|
if sline.len == 0 || sline[0] == `#` {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
x := sline.split(sep)
|
|
|
|
if x.len < 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
m[x[0].trim_space().to_lower()] = x[1].trim_space().trim('"')
|
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2020-09-21 20:46:51 +02:00
|
|
|
fn (mut a App) get_linux_os_name() string {
|
2020-09-21 16:36:31 +02:00
|
|
|
mut os_details := ''
|
|
|
|
linux_os_methods := ['os-release', 'lsb_release', 'kernel', 'uname']
|
|
|
|
for m in linux_os_methods {
|
|
|
|
match m {
|
|
|
|
'os-release' {
|
|
|
|
if !os.is_file('/etc/os-release') {
|
|
|
|
continue
|
|
|
|
}
|
2021-03-08 19:52:13 +01:00
|
|
|
lines := os.read_file('/etc/os-release') or { continue }
|
2020-09-25 18:24:00 +02:00
|
|
|
vals := a.parse(lines, '=')
|
2020-10-21 13:36:16 +02:00
|
|
|
if vals['PRETTY_NAME'] == '' {
|
|
|
|
continue
|
|
|
|
}
|
2020-09-21 16:36:31 +02:00
|
|
|
os_details = vals['PRETTY_NAME']
|
|
|
|
break
|
|
|
|
}
|
|
|
|
'lsb_release' {
|
2021-03-24 09:31:42 +01:00
|
|
|
exists := a.cmd(command: 'type lsb_release')
|
2020-09-21 16:36:31 +02:00
|
|
|
if exists.starts_with('Error') {
|
|
|
|
continue
|
|
|
|
}
|
2021-03-24 09:31:42 +01:00
|
|
|
os_details = a.cmd(command: 'lsb_release -d -s')
|
2020-09-21 16:36:31 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
'kernel' {
|
|
|
|
if !os.is_file('/proc/version') {
|
|
|
|
continue
|
|
|
|
}
|
2021-03-24 09:31:42 +01:00
|
|
|
os_details = a.cmd(command: 'cat /proc/version')
|
2020-09-21 16:36:31 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
'uname' {
|
|
|
|
ouname := os.uname()
|
|
|
|
os_details = '$ouname.release, $ouname.version'
|
|
|
|
break
|
|
|
|
}
|
|
|
|
else {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return os_details
|
|
|
|
}
|
2020-09-21 20:46:51 +02:00
|
|
|
|
2021-02-16 12:46:12 +01:00
|
|
|
fn (mut a App) cpu_info(key string) string {
|
2020-09-22 16:41:32 +02:00
|
|
|
if a.cached_cpuinfo.len > 0 {
|
2021-02-16 12:46:12 +01:00
|
|
|
return a.cached_cpuinfo[key]
|
2020-09-22 16:41:32 +02:00
|
|
|
}
|
2021-03-08 19:52:13 +01:00
|
|
|
info := os.execute('cat /proc/cpuinfo')
|
|
|
|
if info.exit_code != 0 {
|
|
|
|
return '`cat /proc/cpuinfo` could not run'
|
2020-10-21 13:36:16 +02:00
|
|
|
}
|
2021-02-16 12:46:12 +01:00
|
|
|
a.cached_cpuinfo = a.parse(info.output, ':')
|
|
|
|
return a.cached_cpuinfo[key]
|
2020-09-22 16:41:32 +02:00
|
|
|
}
|
|
|
|
|
2020-09-25 18:24:00 +02:00
|
|
|
fn (mut a App) git_info() string {
|
2021-03-24 09:31:42 +01:00
|
|
|
mut out := a.cmd(command: 'git -C . describe --abbrev=8 --dirty --always --tags').trim_space()
|
2021-03-08 19:52:13 +01:00
|
|
|
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')
|
2021-03-24 09:31:42 +01:00
|
|
|
commit_count := a.cmd(command: 'git rev-list @{0}...V_REPO/master --right-only --count').int()
|
2020-10-21 13:36:16 +02:00
|
|
|
if commit_count > 0 {
|
|
|
|
out += ' ($commit_count commit(s) behind V master)'
|
|
|
|
}
|
2020-09-25 18:24:00 +02:00
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2020-09-21 20:46:51 +02:00
|
|
|
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
|
|
|
|
}
|
2022-01-22 20:56:01 +01:00
|
|
|
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'
|
|
|
|
)
|
2020-09-21 20:46:51 +02:00
|
|
|
a.line('$tccfolder status', '$tcc_branch_name $tcc_commit')
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (mut a App) report_info() {
|
|
|
|
for x in a.report_lines {
|
|
|
|
println(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-05 21:30:59 +01:00
|
|
|
fn is_writable_dir(path string) bool {
|
2021-03-08 19:52:13 +01:00
|
|
|
res := os.is_writable_folder(path) or { false }
|
2020-12-05 21:30:59 +01:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2020-10-21 13:36:16 +02:00
|
|
|
fn main() {
|
2020-09-21 20:46:51 +02:00
|
|
|
mut app := App{}
|
|
|
|
app.collect_info()
|
|
|
|
app.report_info()
|
|
|
|
}
|