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

79 lines
1.4 KiB
V
Raw Normal View History

2019-12-23 13:22:06 +03:00
module main
2020-04-26 09:32:05 +03:00
import os
import v.pref
import v.util
fn main() {
2020-03-08 00:26:26 +03:00
vroot := os.dir(pref.vexe_path())
os.chdir(vroot)
println('Updating V...')
2020-02-20 19:41:55 +03:00
// git pull
git_result := os.exec('git pull --rebase origin master') or {
2020-02-20 19:41:55 +03:00
panic(err)
}
if git_result.exit_code != 0 {
if git_result.output.contains('Permission denied') {
eprintln('have no access `$vroot`: Permission denied')
} else {
eprintln(git_result.output)
}
exit(1)
}
println(git_result.output)
2020-04-14 04:32:32 +03:00
v_hash := util.githash(false)
current_hash := util.githash(true)
// println(v_hash)
// println(current_hash)
if v_hash == current_hash {
show_current_v_version()
return
2020-04-14 04:32:32 +03:00
}
2020-02-20 19:41:55 +03:00
$if windows {
backup('v.exe')
2020-03-08 00:26:26 +03:00
make_result := os.exec('make.bat') or {
2020-02-20 19:41:55 +03:00
panic(err)
}
println(make_result.output)
backup('cmd/tools/vup.exe')
} $else {
2020-05-13 16:15:37 +03:00
self_result := os.exec('./v self') or {
2020-02-20 19:41:55 +03:00
panic(err)
}
2020-05-13 16:15:37 +03:00
println(self_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)
}
show_current_v_version()
}
fn show_current_v_version(){
println('Current V version:')
os.system('v version')
}
fn backup(file string) {
backup_file := '${file}_old.exe'
if os.exists(backup_file) {
os.rm(backup_file)
}
os.mv(file, backup_file)
}