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

vup: use '$app.vexe self'

This commit is contained in:
Delyan Angelov 2020-08-25 19:17:41 +03:00
parent a55bea44da
commit b9e408c499

View File

@ -11,7 +11,7 @@ struct App {
} }
fn new_app() App { fn new_app() App {
vexe := pref.vexe_path() vexe := os.real_path(pref.vexe_path())
return App{ return App{
is_verbose: '-v' in os.args is_verbose: '-v' in os.args
vexe: vexe vexe: vexe
@ -23,6 +23,26 @@ fn main() {
app := new_app() app := new_app()
os.chdir(app.vroot) os.chdir(app.vroot)
println('Updating V...') println('Updating V...')
app.update_from_master()
v_hash := util.githash(false)
current_hash := util.githash(true)
// println(v_hash)
// println(current_hash)
if v_hash == current_hash {
app.show_current_v_version()
return
}
$if windows {
app.backup('cmd/tools/vup.exe')
}
app.recompile_v()
os.exec('$app.vexe cmd/tools/vup.v') or {
panic(err)
}
app.show_current_v_version()
}
fn (app App) update_from_master() {
if !os.exists('.git') { if !os.exists('.git') {
// initialize as if it had been cloned // initialize as if it had been cloned
app.git_command('init') app.git_command('init')
@ -34,37 +54,30 @@ fn main() {
// pull latest // pull latest
app.git_command('pull origin master') app.git_command('pull origin master')
} }
v_hash := util.githash(false) }
current_hash := util.githash(true)
// println(v_hash) fn (app App) recompile_v() {
// println(current_hash) // NB: app.vexe is more reliable than just v (which may be a symlink)
if v_hash == current_hash { vself := '$app.vexe self'
app.show_current_v_version() if self_result := os.exec(vself) {
return println(self_result.output)
if self_result.exit_code == 0 {
return
}
} }
mut vself := 'v self' app.make(vself)
}
fn (app App) make(vself string) {
mut make := 'make' mut make := 'make'
$if windows { $if windows {
vself = 'v.exe self'
make = 'make.bat' make = 'make.bat'
app.backup('cmd/tools/vup.exe')
} }
self_result := os.exec(vself) or { println('`$vself` failed, running `$make`...')
make_result := os.exec(make) or {
panic(err) panic(err)
} }
println(self_result.output) println(make_result.output)
if self_result.exit_code != 0 {
// v self failed, have to use make
println('v self failed, running make...')
make_result := os.exec(make) or {
panic(err)
}
println(make_result.output)
}
os.exec('v cmd/tools/vup.v') or {
panic(err)
}
app.show_current_v_version()
} }
fn (app App) show_current_v_version() { fn (app App) show_current_v_version() {