Skip to content

Commit

Permalink
tools: make v up more informative on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Apr 30, 2022
1 parent dab649e commit dcdfdf4
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions cmd/tools/vup.v
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ fn main() {
// println(v_hash)
// println(current_hash)
if v_hash == current_hash {
println('V is already updated.')
app.show_current_v_version()
return
}
$if windows {
app.backup('cmd/tools/vup.exe')
}
app.recompile_v()
if !app.recompile_v() {
app.show_current_v_version()
eprintln('Recompiling V *failed*.')
eprintln('Try running `$get_make_cmd_name()` .')
exit(1)
}
app.recompile_vup()
app.show_current_v_version()
}
Expand All @@ -66,43 +72,43 @@ fn (app App) update_from_master() {
}
}

fn (app App) recompile_v() {
fn (app App) recompile_v() bool {
// Note: app.vexe is more reliable than just v (which may be a symlink)
opts := if app.is_prod { '-prod' } else { '' }
vself := '${os.quoted_path(app.vexe)} $opts self'
app.vprintln('> recompiling v itself with `$vself` ...')
self_result := os.execute(vself)
if self_result.exit_code == 0 {
println(self_result.output.trim_space())
return
return true
} else {
app.vprintln('`$vself` failed, running `make`...')
app.vprintln(self_result.output.trim_space())
}
app.make(vself)
return app.make(vself)
}

fn (app App) recompile_vup() {
fn (app App) recompile_vup() bool {
vup_result := os.execute('${os.quoted_path(app.vexe)} -g cmd/tools/vup.v')
if vup_result.exit_code != 0 {
eprintln('recompiling vup.v failed:')
eprintln(vup_result.output)
return false
}
return true
}

fn (app App) make(vself string) {
mut make := 'make'
$if windows {
make = 'make.bat'
}
fn (app App) make(vself string) bool {
make := get_make_cmd_name()
make_result := os.execute(make)
if make_result.exit_code != 0 {
eprintln('> $make failed:')
eprintln('> make output:')
eprintln(make_result.output)
return
return false
}
app.vprintln(make_result.output)
return true
}

fn (app App) show_current_v_version() {
Expand All @@ -116,8 +122,7 @@ fn (app App) show_current_v_version() {
vversion += ', timestamp: ' + latest_v_commit_time.output.trim_space()
}
}
println('Current V version:')
println(vversion)
println('Current V version: $vversion')
}
}

Expand Down Expand Up @@ -162,3 +167,11 @@ fn (app App) get_git() {
eprintln("error: Install `git` using your system's package manager")
}
}

fn get_make_cmd_name() string {
$if windows {
return 'make.bat'
} $else {
return 'make'
}
}

0 comments on commit dcdfdf4

Please sign in to comment.