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
|
2019-11-01 13:14:59 +03:00
|
|
|
|
2020-06-08 14:45:51 +03:00
|
|
|
struct App {
|
|
|
|
is_verbose bool
|
|
|
|
vexe string
|
|
|
|
vroot string
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_app() App {
|
2020-05-29 05:42:19 +03:00
|
|
|
vexe := pref.vexe_path()
|
2020-06-08 14:45:51 +03:00
|
|
|
return App{
|
|
|
|
is_verbose: '-v' in os.args
|
|
|
|
vexe: vexe
|
|
|
|
vroot: os.dir(vexe)
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 17:56:33 +03:00
|
|
|
|
2020-06-08 14:45:51 +03:00
|
|
|
fn main() {
|
|
|
|
app := new_app()
|
|
|
|
os.chdir(app.vroot)
|
2020-04-07 17:56:33 +03:00
|
|
|
println('Updating V...')
|
2020-06-07 23:59:15 +03:00
|
|
|
if !os.exists('.git') {
|
|
|
|
// initialize as if it had been cloned
|
2020-06-08 14:45:51 +03:00
|
|
|
app.git_command('init')
|
|
|
|
app.git_command('remote add origin https://github.com/vlang/v')
|
|
|
|
app.git_command('fetch')
|
|
|
|
app.git_command('reset --hard origin/master')
|
|
|
|
app.git_command('clean --quiet -xdf --exclude v.exe --exclude cmd/tools/vup.exe')
|
2020-06-07 23:59:15 +03:00
|
|
|
} else {
|
|
|
|
// pull latest
|
2020-06-08 14:45:51 +03:00
|
|
|
app.git_command('pull origin master')
|
2020-02-20 19:41:55 +03:00
|
|
|
}
|
2020-04-14 04:32:32 +03:00
|
|
|
v_hash := util.githash(false)
|
|
|
|
current_hash := util.githash(true)
|
|
|
|
// println(v_hash)
|
|
|
|
// println(current_hash)
|
2020-05-06 09:10:40 +03:00
|
|
|
if v_hash == current_hash {
|
2020-06-08 14:45:51 +03:00
|
|
|
app.show_current_v_version()
|
2020-05-06 09:10:40 +03:00
|
|
|
return
|
2020-04-14 04:32:32 +03:00
|
|
|
}
|
2019-11-01 13:14:59 +03:00
|
|
|
$if windows {
|
2020-06-08 14:45:51 +03:00
|
|
|
app.backup('v.exe')
|
2020-04-07 17:56:33 +03:00
|
|
|
make_result := os.exec('make.bat') or {
|
2020-02-20 19:41:55 +03:00
|
|
|
panic(err)
|
2019-11-01 13:14:59 +03:00
|
|
|
}
|
2020-04-07 17:56:33 +03:00
|
|
|
println(make_result.output)
|
2020-06-08 14:45:51 +03:00
|
|
|
app.backup('cmd/tools/vup.exe')
|
2019-11-01 13:14:59 +03:00
|
|
|
} $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)
|
|
|
|
}
|
2019-11-01 13:14:59 +03:00
|
|
|
}
|
2020-06-08 01:47:04 +03:00
|
|
|
os.exec('v cmd/tools/vup.v') or {
|
2020-04-22 20:54:39 +03:00
|
|
|
panic(err)
|
|
|
|
}
|
2020-06-08 14:45:51 +03:00
|
|
|
app.show_current_v_version()
|
2020-05-16 22:16:39 +03:00
|
|
|
}
|
|
|
|
|
2020-06-08 14:45:51 +03:00
|
|
|
fn (app App) show_current_v_version() {
|
2020-05-16 22:16:39 +03:00
|
|
|
println('Current V version:')
|
2020-06-08 14:45:51 +03:00
|
|
|
os.system('$app.vexe version')
|
2020-04-22 20:54:39 +03:00
|
|
|
}
|
|
|
|
|
2020-06-08 14:45:51 +03:00
|
|
|
fn (app App) backup(file string) {
|
2020-04-22 20:54:39 +03:00
|
|
|
backup_file := '${file}_old.exe'
|
|
|
|
if os.exists(backup_file) {
|
|
|
|
os.rm(backup_file)
|
|
|
|
}
|
|
|
|
os.mv(file, backup_file)
|
2019-11-01 13:14:59 +03:00
|
|
|
}
|
2020-06-07 23:59:15 +03:00
|
|
|
|
2020-06-08 14:45:51 +03:00
|
|
|
fn (app App) git_command(command string) {
|
2020-06-07 23:59:15 +03:00
|
|
|
git_result := os.exec('git $command') or {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if git_result.exit_code != 0 {
|
|
|
|
if git_result.output.contains('Permission denied') {
|
2020-06-08 14:45:51 +03:00
|
|
|
eprintln('have no access `$app.vroot`: Permission denied')
|
2020-06-07 23:59:15 +03:00
|
|
|
} else {
|
|
|
|
eprintln(git_result.output)
|
|
|
|
}
|
|
|
|
exit(1)
|
2020-06-08 14:45:51 +03:00
|
|
|
} else {
|
|
|
|
if app.is_verbose {
|
|
|
|
println(git_result.output)
|
|
|
|
}
|
2020-06-07 23:59:15 +03:00
|
|
|
}
|
|
|
|
}
|