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

v.util: extract v.util.version, use it to speed up building v repl, v up and v doctor

This commit is contained in:
Delyan Angelov
2021-07-27 12:35:54 +03:00
parent cb7be87d4e
commit 6134c4870b
12 changed files with 134 additions and 122 deletions

View File

@@ -6,7 +6,6 @@ import time
import term
import math
import scripting
import v.util
struct CmdResult {
mut:
@@ -127,8 +126,12 @@ fn new_aints(ovals []int, extreme_mins int, extreme_maxs int) Aints {
return res
}
fn bold(s string) string {
return term.colorize(term.bold, s)
}
fn (a Aints) str() string {
return util.bold('${a.average:6.2f}') +
return bold('${a.average:6.2f}') +
'ms ± σ: ${a.stddev:4.1f}ms, min: ${a.imin:4}ms, max: ${a.imax:4}ms, runs:${a.values.len:3}, nmins:${a.nmins:2}, nmaxs:${a.nmaxs:2}'
}
@@ -346,7 +349,7 @@ fn (mut context Context) show_diff_summary() {
first_marker = ' '
cpercent := (r.atiming.average / base) * 100 - 100
if r.icmd == 0 {
first_marker = util.bold('>')
first_marker = bold('>')
first_cmd_percentage = cpercent
}
println(' $first_marker${(i + 1):3} | ${cpercent:5.1f}% slower | ${r.cmd:-57s} | $r.atiming')

View File

@@ -1,6 +1,7 @@
import os
import time
import v.util
import term
import v.util.version
import runtime
struct App {
@@ -109,7 +110,7 @@ fn (mut a App) collect_info() {
a.line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str())
a.line('is vroot writable', is_writable_dir(vroot).str())
a.line('is vmodules writable', is_writable_dir(vmodules).str())
a.line('V full version', util.full_v_version(true))
a.line('V full version', version.full_v_version(true))
vtmp := os.getenv('VTMP')
if vtmp != '' {
a.line('env VTMP', '"$vtmp"')
@@ -149,7 +150,7 @@ fn (mut a App) cmd(c CmdConfig) string {
}
fn (mut a App) line(label string, value string) {
a.println('$label: ${util.bold(value)}')
a.println('$label: ${term.colorize(term.bold, value)}')
}
fn (app &App) parse(config string, sep string) map[string]string {

View File

@@ -8,7 +8,7 @@ import term
import rand
import readline
import os.cmdline
import v.util
import v.util.version
struct Repl {
mut:
@@ -102,7 +102,7 @@ fn (r &Repl) current_source_code(should_add_temp_lines bool, not_add_print bool)
}
fn repl_help() {
println(util.full_v_version(false))
println(version.full_v_version(false))
println('
|help Displays this information.
|list Show the program so far.
@@ -114,8 +114,8 @@ fn repl_help() {
fn run_repl(workdir string, vrepl_prefix string) {
if !is_stdin_a_pipe {
println(util.full_v_version(false))
println('Use Ctrl-C or ${util.pretty_print('exit')} to exit, or ${util.pretty_print('help')} to see other available commands')
println(version.full_v_version(false))
println('Use Ctrl-C or ${term.highlight_command('exit')} to exit, or ${term.highlight_command('help')} to see other available commands')
}
if vstartup != '' {

View File

@@ -2,7 +2,7 @@ module main
import os
import v.pref
import v.util
import v.util.version
import v.util.recompilation
struct App {
@@ -29,8 +29,8 @@ fn main() {
os.chdir(app.vroot)
println('Updating V...')
app.update_from_master()
v_hash := util.githash(false)
current_hash := util.githash(true)
v_hash := version.githash(false)
current_hash := version.githash(true)
// println(v_hash)
// println(current_hash)
if v_hash == current_hash {