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
|
|
|
|
2020-06-08 13:45:51 +02:00
|
|
|
struct App {
|
|
|
|
is_verbose bool
|
|
|
|
vexe string
|
|
|
|
vroot string
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_app() App {
|
2020-08-25 18:17:41 +02:00
|
|
|
vexe := os.real_path(pref.vexe_path())
|
2020-06-08 13:45:51 +02:00
|
|
|
return App{
|
|
|
|
is_verbose: '-v' in os.args
|
|
|
|
vexe: vexe
|
|
|
|
vroot: os.dir(vexe)
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 16:56:33 +02:00
|
|
|
|
2020-06-08 13:45:51 +02:00
|
|
|
fn main() {
|
|
|
|
app := new_app()
|
|
|
|
os.chdir(app.vroot)
|
2020-04-07 16:56:33 +02:00
|
|
|
println('Updating V...')
|
2020-08-25 18:17:41 +02:00
|
|
|
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() {
|
2020-08-25 18:54:27 +02:00
|
|
|
if app.is_verbose {
|
|
|
|
println('> updating from master ...')
|
|
|
|
}
|
2020-06-07 22:59:15 +02:00
|
|
|
if !os.exists('.git') {
|
|
|
|
// initialize as if it had been cloned
|
2020-06-08 13:45:51 +02: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 22:59:15 +02:00
|
|
|
} else {
|
|
|
|
// pull latest
|
2020-08-28 20:49:12 +02:00
|
|
|
app.git_command('pull https://github.com/vlang/v master')
|
2020-02-20 17:41:55 +01:00
|
|
|
}
|
2020-08-25 18:17:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn (app App) recompile_v() {
|
|
|
|
// NB: app.vexe is more reliable than just v (which may be a symlink)
|
|
|
|
vself := '$app.vexe self'
|
2020-08-25 18:54:27 +02:00
|
|
|
if app.is_verbose {
|
|
|
|
println('> recompiling v itself with `$vself` ...')
|
|
|
|
}
|
2020-08-25 18:17:41 +02:00
|
|
|
if self_result := os.exec(vself) {
|
2020-08-28 18:02:28 +02:00
|
|
|
println(self_result.output.trim_space())
|
2020-08-25 18:17:41 +02:00
|
|
|
if self_result.exit_code == 0 {
|
|
|
|
return
|
|
|
|
}
|
2020-04-14 03:32:32 +02:00
|
|
|
}
|
2020-08-25 18:17:41 +02:00
|
|
|
app.make(vself)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (app App) make(vself string) {
|
2020-08-25 18:12:53 +02:00
|
|
|
mut make := 'make'
|
2019-11-01 11:14:59 +01:00
|
|
|
$if windows {
|
2020-08-25 18:12:53 +02:00
|
|
|
make = 'make.bat'
|
2019-11-01 11:14:59 +01:00
|
|
|
}
|
2020-08-25 18:17:41 +02:00
|
|
|
println('`$vself` failed, running `$make`...')
|
|
|
|
make_result := os.exec(make) or {
|
2020-04-22 19:54:39 +02:00
|
|
|
panic(err)
|
|
|
|
}
|
2020-08-25 18:17:41 +02:00
|
|
|
println(make_result.output)
|
2020-05-16 21:16:39 +02:00
|
|
|
}
|
|
|
|
|
2020-06-08 13:45:51 +02:00
|
|
|
fn (app App) show_current_v_version() {
|
2020-05-16 21:16:39 +02:00
|
|
|
println('Current V version:')
|
2020-06-08 13:45:51 +02:00
|
|
|
os.system('$app.vexe version')
|
2020-04-22 19:54:39 +02:00
|
|
|
}
|
|
|
|
|
2020-06-08 13:45:51 +02:00
|
|
|
fn (app App) backup(file string) {
|
2020-04-22 19:54:39 +02:00
|
|
|
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
|
|
|
|
2020-06-08 13:45:51 +02:00
|
|
|
fn (app App) git_command(command string) {
|
2020-06-07 22:59:15 +02: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 13:45:51 +02:00
|
|
|
eprintln('have no access `$app.vroot`: Permission denied')
|
2020-06-07 22:59:15 +02:00
|
|
|
} else {
|
|
|
|
eprintln(git_result.output)
|
|
|
|
}
|
|
|
|
exit(1)
|
2020-06-08 13:45:51 +02:00
|
|
|
} else {
|
|
|
|
if app.is_verbose {
|
|
|
|
println(git_result.output)
|
|
|
|
}
|
2020-06-07 22:59:15 +02:00
|
|
|
}
|
|
|
|
}
|