tools: bugfixes and new features for oldv and performance_compare

This commit is contained in:
Delyan Angelov 2020-01-08 22:45:47 +02:00 committed by Alexander Medvednikov
parent 0d93eeb3fe
commit c1cc203c17
8 changed files with 489 additions and 381 deletions

View file

@ -2,17 +2,27 @@ module scripting
import os
pub fn verbose_trace(label string, message string){
pub fn set_verbose(on bool) {
// setting a global here would be the obvious solution,
// but V does not have globals normally.
if on {
os.setenv('VERBOSE', '1', true)
}
else {
os.unsetenv('VERBOSE')
}
}
pub fn verbose_trace(label string, message string) {
if os.getenv('VERBOSE').len > 0 {
slabel := 'scripting.${label}'
println('# ${slabel:30s} : $message')
println('# ${slabel:-25s} : $message')
}
}
pub fn verbose_trace_exec_result(x os.Result) {
if os.getenv('VERBOSE').len > 0 {
println('# cmd.exit_code : ${x.exit_code.str()}')
println('# cmd.output :')
println('# cmd.exit_code : ${x.exit_code.str():-4s} cmd.output:')
println('# ----------------------------------- #')
mut lnum := 1
lines := x.output.split_into_lines()
@ -21,33 +31,45 @@ pub fn verbose_trace_exec_result(x os.Result) {
lnum++
}
println('# ----------------------------------- #')
}
}
}
pub fn chdir(path string) {
verbose_trace(@FN, 'cd $path')
os.chdir( path )
os.chdir(path)
}
pub fn run(cmd string) string {
verbose_trace(@FN, cmd)
x := os.exec(cmd) or { return '' }
verbose_trace_exec_result( x )
if x.exit_code == 0 { return x.output }
x := os.exec(cmd) or {
verbose_trace(@FN, '## failed.')
return ''
}
verbose_trace_exec_result(x)
if x.exit_code == 0 {
return x.output
}
return ''
}
pub fn command_exits_with_zero_status(cmd string) bool {
pub fn exit_0_status(cmd string) bool {
verbose_trace(@FN, cmd)
x := os.exec(cmd) or { return false }
verbose_trace_exec_result( x )
if x.exit_code == 0 { return true }
x := os.exec(cmd) or {
verbose_trace(@FN, '## failed.')
return false
}
verbose_trace_exec_result(x)
if x.exit_code == 0 {
return true
}
return false
}
pub fn tool_must_exist(toolcmd string) {
pub fn tool_must_exist (toolcmd string) {
verbose_trace(@FN, toolcmd)
if command_exits_with_zero_status( 'type $toolcmd' ) { return }
if exit_0_status('type $toolcmd') {
return
}
eprintln('Missing tool: $toolcmd')
eprintln('Please try again after you install it.')
exit(1)
@ -59,14 +81,9 @@ pub fn used_tools_must_exist(tools []string) {
}
}
pub fn check_v_commit_timestamp_before_self_rebuilding(v_timestamp int) {
if v_timestamp >= 1561805697 { return }
eprintln('##################################################################')
eprintln('# WARNING: v self rebuilding, before 5b7a1e8 (2019-06-29 12:21) #')
eprintln('# required the v executable to be built *inside* #')
eprintln('# the toplevel compiler/ folder. #')
eprintln('# #')
eprintln('# That is not supported by this tool. #')
eprintln('# You will have to build it manually there. #')
eprintln('##################################################################')
pub fn show_sizes_of_files(files []string) {
for f in files {
size := os.file_size(f)
println('${size:10d} $f')
}
}