mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tools: improve the default performance/behaviour of oldv
This commit is contained in:
@ -46,26 +46,25 @@ pub fn cprintln_strong(omessage string) {
|
||||
|
||||
pub fn verbose_trace(label string, message string) {
|
||||
if os.getenv('VERBOSE').len > 0 {
|
||||
slabel := '$time.now().format_ss_milli() scripting.$label'
|
||||
cprintln('# ${slabel:-40s} : $message')
|
||||
slabel := '$time.now().format_ss_milli() $label'
|
||||
cprintln('# ${slabel:-43s} : $message')
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verbose_trace_strong(label string, omessage string) {
|
||||
if os.getenv('VERBOSE').len > 0 {
|
||||
slabel := '$time.now().format_ss_milli() scripting.$label'
|
||||
slabel := '$time.now().format_ss_milli() $label'
|
||||
mut message := omessage
|
||||
if scripting.term_colors {
|
||||
message = term.bright_green(message)
|
||||
}
|
||||
cprintln('# ${slabel:-40s} : $message')
|
||||
cprintln('# ${slabel:-43s} : $message')
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verbose_trace_exec_result(x os.Result) {
|
||||
if os.getenv('VERBOSE').len > 0 {
|
||||
cprintln('# cmd.exit_code : ${x.exit_code.str():-4s} cmd.output:')
|
||||
cprintln('# ----------------------------------- #')
|
||||
mut lnum := 1
|
||||
lines := x.output.split_into_lines()
|
||||
for oline in lines {
|
||||
@ -76,17 +75,37 @@ pub fn verbose_trace_exec_result(x os.Result) {
|
||||
cprintln('# ${lnum:3d}: $line')
|
||||
lnum++
|
||||
}
|
||||
cprintln('# ----------------------------------- #')
|
||||
cprintln('# ----------------------------------------------------------------------')
|
||||
}
|
||||
}
|
||||
|
||||
fn modfn(mname string, fname string) string {
|
||||
return '${mname}.$fname'
|
||||
}
|
||||
|
||||
pub fn chdir(path string) {
|
||||
verbose_trace_strong(@FN, 'cd $path')
|
||||
verbose_trace_strong(modfn(@MOD, @FN), 'cd $path')
|
||||
os.chdir(path)
|
||||
}
|
||||
|
||||
pub fn mkdir(path string) ? {
|
||||
verbose_trace_strong(modfn(@MOD, @FN), 'mkdir $path')
|
||||
os.mkdir(path) or {
|
||||
verbose_trace(modfn(@MOD, @FN), '## failed.')
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mkdir_all(path string) ? {
|
||||
verbose_trace_strong(modfn(@MOD, @FN), 'mkdir -p $path')
|
||||
os.mkdir_all(path) or {
|
||||
verbose_trace(modfn(@MOD, @FN), '## failed.')
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rmrf(path string) {
|
||||
verbose_trace_strong(@FN, 'rm -rf $path')
|
||||
verbose_trace_strong(modfn(@MOD, @FN), 'rm -rf $path')
|
||||
if os.exists(path) {
|
||||
if os.is_dir(path) {
|
||||
os.rmdir_all(path) or { panic(err) }
|
||||
@ -98,10 +117,10 @@ pub fn rmrf(path string) {
|
||||
|
||||
// execute a command, and return a result, or an error, if it failed in any way.
|
||||
pub fn exec(cmd string) ?os.Result {
|
||||
verbose_trace_strong(@FN, cmd)
|
||||
verbose_trace_strong(modfn(@MOD, @FN), cmd)
|
||||
x := os.execute(cmd)
|
||||
if x.exit_code != 0 {
|
||||
verbose_trace(@FN, '## failed.')
|
||||
verbose_trace(modfn(@MOD, @FN), '## failed.')
|
||||
return error(x.output)
|
||||
}
|
||||
verbose_trace_exec_result(x)
|
||||
@ -110,10 +129,10 @@ pub fn exec(cmd string) ?os.Result {
|
||||
|
||||
// run a command, tracing its results, and returning ONLY its output
|
||||
pub fn run(cmd string) string {
|
||||
verbose_trace_strong(@FN, cmd)
|
||||
verbose_trace_strong(modfn(@MOD, @FN), cmd)
|
||||
x := os.execute(cmd)
|
||||
if x.exit_code < 0 {
|
||||
verbose_trace(@FN, '## failed.')
|
||||
verbose_trace(modfn(@MOD, @FN), '## failed.')
|
||||
return ''
|
||||
}
|
||||
verbose_trace_exec_result(x)
|
||||
@ -124,10 +143,10 @@ pub fn run(cmd string) string {
|
||||
}
|
||||
|
||||
pub fn exit_0_status(cmd string) bool {
|
||||
verbose_trace_strong(@FN, cmd)
|
||||
verbose_trace_strong(modfn(@MOD, @FN), cmd)
|
||||
x := os.execute(cmd)
|
||||
if x.exit_code < 0 {
|
||||
verbose_trace(@FN, '## failed.')
|
||||
verbose_trace(modfn(@MOD, @FN), '## failed.')
|
||||
return false
|
||||
}
|
||||
verbose_trace_exec_result(x)
|
||||
@ -138,7 +157,7 @@ pub fn exit_0_status(cmd string) bool {
|
||||
}
|
||||
|
||||
pub fn tool_must_exist(toolcmd string) {
|
||||
verbose_trace(@FN, toolcmd)
|
||||
verbose_trace(modfn(@MOD, @FN), toolcmd)
|
||||
if exit_0_status('type $toolcmd') {
|
||||
return
|
||||
}
|
||||
|
@ -4,11 +4,6 @@ import os
|
||||
import flag
|
||||
import scripting
|
||||
|
||||
const (
|
||||
remote_v_repo_url = 'https://github.com/vlang/v'
|
||||
remote_vc_repo_url = 'https://github.com/vlang/vc'
|
||||
)
|
||||
|
||||
pub fn check_v_commit_timestamp_before_self_rebuilding(v_timestamp int) {
|
||||
if v_timestamp >= 1561805697 {
|
||||
return
|
||||
@ -164,9 +159,9 @@ pub mut:
|
||||
|
||||
pub fn add_common_tool_options(mut context VGitOptions, mut fp flag.FlagParser) []string {
|
||||
tdir := os.temp_dir()
|
||||
context.workdir = os.real_path(fp.string('workdir', `w`, tdir, 'A writable base folder. Default: $tdir'))
|
||||
context.v_repo_url = fp.string('vrepo', 0, vgit.remote_v_repo_url, 'The url of the V repository. You can clone it locally too. See also --vcrepo below.')
|
||||
context.vc_repo_url = fp.string('vcrepo', 0, vgit.remote_vc_repo_url, 'The url of the vc repository. You can clone it
|
||||
context.workdir = os.real_path(fp.string('workdir', `w`, context.workdir, 'A writable base folder. Default: $tdir'))
|
||||
context.v_repo_url = fp.string('vrepo', 0, context.v_repo_url, 'The url of the V repository. You can clone it locally too. See also --vcrepo below.')
|
||||
context.vc_repo_url = fp.string('vcrepo', 0, context.vc_repo_url, 'The url of the vc repository. You can clone it
|
||||
${flag.space}beforehand, and then just give the local folder
|
||||
${flag.space}path here. That will eliminate the network ops
|
||||
${flag.space}done by this tool, which is useful, if you want
|
||||
|
Reference in New Issue
Block a user