2019-12-23 11:22:06 +01:00
|
|
|
module main
|
|
|
|
|
2020-04-26 08:32:05 +02:00
|
|
|
import os
|
|
|
|
import v.pref
|
|
|
|
import v.util
|
2019-11-01 11:14:59 +01:00
|
|
|
|
|
|
|
fn main() {
|
2020-05-29 04:42:19 +02:00
|
|
|
vexe := pref.vexe_path()
|
|
|
|
vroot := os.dir(vexe)
|
2019-11-01 11:14:59 +01:00
|
|
|
os.chdir(vroot)
|
2020-04-07 16:56:33 +02:00
|
|
|
|
|
|
|
println('Updating V...')
|
|
|
|
|
2020-06-07 22:59:15 +02:00
|
|
|
if !os.exists('.git') {
|
|
|
|
// initialize as if it had been cloned
|
|
|
|
git_command('init')
|
|
|
|
git_command('remote add origin https://github.com/vlang/v')
|
|
|
|
git_command('fetch')
|
|
|
|
git_command('reset --hard origin/master')
|
|
|
|
git_command('clean --quiet -xdf --exclude v.exe --exclude cmd/tools/vup.exe')
|
|
|
|
} else {
|
|
|
|
// pull latest
|
|
|
|
git_command('pull origin master')
|
2020-02-20 17:41:55 +01:00
|
|
|
}
|
2020-04-07 16:56:33 +02:00
|
|
|
|
2020-04-14 03:32:32 +02:00
|
|
|
v_hash := util.githash(false)
|
|
|
|
current_hash := util.githash(true)
|
|
|
|
// println(v_hash)
|
|
|
|
// println(current_hash)
|
2020-05-06 08:10:40 +02:00
|
|
|
if v_hash == current_hash {
|
2020-05-29 04:42:19 +02:00
|
|
|
show_current_v_version(vexe)
|
2020-05-06 08:10:40 +02:00
|
|
|
return
|
2020-04-14 03:32:32 +02:00
|
|
|
}
|
2020-02-20 17:41:55 +01:00
|
|
|
|
2019-11-01 11:14:59 +01:00
|
|
|
$if windows {
|
2020-04-22 19:54:39 +02:00
|
|
|
backup('v.exe')
|
2020-03-07 22:26:26 +01:00
|
|
|
|
2020-04-07 16:56:33 +02:00
|
|
|
make_result := os.exec('make.bat') or {
|
2020-02-20 17:41:55 +01:00
|
|
|
panic(err)
|
2019-11-01 11:14:59 +01:00
|
|
|
}
|
2020-04-07 16:56:33 +02:00
|
|
|
println(make_result.output)
|
2020-04-22 19:54:39 +02:00
|
|
|
|
|
|
|
backup('cmd/tools/vup.exe')
|
2019-11-01 11:14:59 +01:00
|
|
|
} $else {
|
2020-05-13 15:15:37 +02:00
|
|
|
self_result := os.exec('./v self') or {
|
2020-02-20 17:41:55 +01:00
|
|
|
panic(err)
|
|
|
|
}
|
2020-05-13 15:15:37 +02: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)
|
|
|
|
}
|
2019-11-01 11:14:59 +01:00
|
|
|
}
|
2020-04-22 19:54:39 +02:00
|
|
|
|
2020-04-23 12:06:46 +02:00
|
|
|
_ := os.exec('v cmd/tools/vup.v') or {
|
2020-04-22 19:54:39 +02:00
|
|
|
panic(err)
|
|
|
|
}
|
2020-05-29 04:42:19 +02:00
|
|
|
show_current_v_version(vexe)
|
2020-05-16 21:16:39 +02:00
|
|
|
}
|
|
|
|
|
2020-05-29 04:42:19 +02:00
|
|
|
fn show_current_v_version(vexe string){
|
2020-05-16 21:16:39 +02:00
|
|
|
println('Current V version:')
|
2020-05-29 04:42:19 +02:00
|
|
|
os.system('$vexe version')
|
2020-04-22 19:54:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn backup(file string) {
|
|
|
|
backup_file := '${file}_old.exe'
|
|
|
|
if os.exists(backup_file) {
|
|
|
|
os.rm(backup_file)
|
|
|
|
}
|
|
|
|
os.mv(file, backup_file)
|
2019-11-01 11:14:59 +01:00
|
|
|
}
|
2020-06-07 22:59:15 +02:00
|
|
|
|
|
|
|
fn git_command(command string) {
|
|
|
|
vexe := pref.vexe_path()
|
|
|
|
vroot := os.dir(vexe)
|
|
|
|
|
|
|
|
git_result := os.exec('git $command') or {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|