From 79ac431e9e7e4743a9d027021bc7b09fa380d948 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 20 Sep 2020 13:13:20 +0300 Subject: [PATCH] doctor: add first draft --- cmd/tools/vdoctor.v | 61 +++++++++++++++++++++++++++++++++++++++++++++ cmd/v/v.v | 2 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 cmd/tools/vdoctor.v diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v new file mode 100644 index 0000000000..6249adb30c --- /dev/null +++ b/cmd/tools/vdoctor.v @@ -0,0 +1,61 @@ +import os +import term +import time +import v.util +import runtime + +fn main(){ + mut arch_details := []string{} + arch_details << '${runtime.nr_cpus()} cpus' + 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' + } + line('Processor', arch_details.join(', ')) + mut os_kind := os.user_os() + mut os_details := '' + if os_kind == 'linux' { + os_details = first_line_of_cmd('lsb_release -d -s') + } + line('OS', os_kind) + line('OS details', os_details) + line('CC version', first_line_of_cmd('cc --version')) + println(util.bold(term.h_divider('-'))) + vexe := os.getenv('VEXE') + vroot := os.dir(vexe) + os.chdir(vroot) + line('vroot', vroot) + line('vexe', vexe) + line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str()) + is_writable_vroot := os.is_writable_folder(vroot) or { false } + line('is vroot writable', is_writable_vroot.str()) + line('V full version', util.full_v_version(true)) + println(util.bold(term.h_divider('-'))) + line('Git version', first_line_of_cmd('git --version')) + line('Git vroot status', first_line_of_cmd('git describe --dirty --tags')) + line('.git/config present', os.is_file('.git/config').str()) + println(util.bold(term.h_divider('-'))) +} + +fn first_line_of_cmd(cmd string) string { + x := os.exec(cmd) or { + return 'N/A' + } + if x.exit_code == 0 { + return x.output.split_into_lines()[0] + } + println('first_line_of_cmd error: $x.output') + return 'Error' +} + +fn line(label string, value string) { + println('$label: ${util.bold(value)}') +} diff --git a/cmd/v/v.v b/cmd/v/v.v index cf504a4dc1..c22cf5d83a 100644 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -17,7 +17,7 @@ const ( 'repl', 'build-tools', 'build-examples', 'build-vbinaries', - 'setup-freetype', 'doc' + 'setup-freetype', 'doc', 'doctor' ] list_of_flags_that_allow_duplicates = ['cc', 'd', 'define', 'cf', 'cflags'] )