mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vup: support -v
This commit is contained in:
parent
1bbfc271c5
commit
b6dc2d9106
@ -4,43 +4,51 @@ import os
|
|||||||
import v.pref
|
import v.pref
|
||||||
import v.util
|
import v.util
|
||||||
|
|
||||||
fn main() {
|
struct App {
|
||||||
|
is_verbose bool
|
||||||
|
vexe string
|
||||||
|
vroot string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_app() App {
|
||||||
vexe := pref.vexe_path()
|
vexe := pref.vexe_path()
|
||||||
vroot := os.dir(vexe)
|
return App{
|
||||||
os.chdir(vroot)
|
is_verbose: '-v' in os.args
|
||||||
|
vexe: vexe
|
||||||
|
vroot: os.dir(vexe)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
app := new_app()
|
||||||
|
os.chdir(app.vroot)
|
||||||
println('Updating V...')
|
println('Updating V...')
|
||||||
|
|
||||||
if !os.exists('.git') {
|
if !os.exists('.git') {
|
||||||
// initialize as if it had been cloned
|
// initialize as if it had been cloned
|
||||||
git_command('init')
|
app.git_command('init')
|
||||||
git_command('remote add origin https://github.com/vlang/v')
|
app.git_command('remote add origin https://github.com/vlang/v')
|
||||||
git_command('fetch')
|
app.git_command('fetch')
|
||||||
git_command('reset --hard origin/master')
|
app.git_command('reset --hard origin/master')
|
||||||
git_command('clean --quiet -xdf --exclude v.exe --exclude cmd/tools/vup.exe')
|
app.git_command('clean --quiet -xdf --exclude v.exe --exclude cmd/tools/vup.exe')
|
||||||
} else {
|
} else {
|
||||||
// pull latest
|
// pull latest
|
||||||
git_command('pull origin master')
|
app.git_command('pull origin master')
|
||||||
}
|
}
|
||||||
|
|
||||||
v_hash := util.githash(false)
|
v_hash := util.githash(false)
|
||||||
current_hash := util.githash(true)
|
current_hash := util.githash(true)
|
||||||
// println(v_hash)
|
// println(v_hash)
|
||||||
// println(current_hash)
|
// println(current_hash)
|
||||||
if v_hash == current_hash {
|
if v_hash == current_hash {
|
||||||
show_current_v_version(vexe)
|
app.show_current_v_version()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
$if windows {
|
$if windows {
|
||||||
backup('v.exe')
|
app.backup('v.exe')
|
||||||
|
|
||||||
make_result := os.exec('make.bat') or {
|
make_result := os.exec('make.bat') or {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
println(make_result.output)
|
println(make_result.output)
|
||||||
|
app.backup('cmd/tools/vup.exe')
|
||||||
backup('cmd/tools/vup.exe')
|
|
||||||
} $else {
|
} $else {
|
||||||
self_result := os.exec('./v self') or {
|
self_result := os.exec('./v self') or {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -55,19 +63,18 @@ fn main() {
|
|||||||
println(make_result.output)
|
println(make_result.output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
os.exec('v cmd/tools/vup.v') or {
|
os.exec('v cmd/tools/vup.v') or {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
show_current_v_version(vexe)
|
app.show_current_v_version()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_current_v_version(vexe string){
|
fn (app App) show_current_v_version() {
|
||||||
println('Current V version:')
|
println('Current V version:')
|
||||||
os.system('$vexe version')
|
os.system('$app.vexe version')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backup(file string) {
|
fn (app App) backup(file string) {
|
||||||
backup_file := '${file}_old.exe'
|
backup_file := '${file}_old.exe'
|
||||||
if os.exists(backup_file) {
|
if os.exists(backup_file) {
|
||||||
os.rm(backup_file)
|
os.rm(backup_file)
|
||||||
@ -75,20 +82,20 @@ fn backup(file string) {
|
|||||||
os.mv(file, backup_file)
|
os.mv(file, backup_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn git_command(command string) {
|
fn (app App) git_command(command string) {
|
||||||
vexe := pref.vexe_path()
|
|
||||||
vroot := os.dir(vexe)
|
|
||||||
|
|
||||||
git_result := os.exec('git $command') or {
|
git_result := os.exec('git $command') or {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if git_result.exit_code != 0 {
|
if git_result.exit_code != 0 {
|
||||||
if git_result.output.contains('Permission denied') {
|
if git_result.output.contains('Permission denied') {
|
||||||
eprintln('have no access `$vroot`: Permission denied')
|
eprintln('have no access `$app.vroot`: Permission denied')
|
||||||
} else {
|
} else {
|
||||||
eprintln(git_result.output)
|
eprintln(git_result.output)
|
||||||
}
|
}
|
||||||
exit(1)
|
exit(1)
|
||||||
|
} else {
|
||||||
|
if app.is_verbose {
|
||||||
|
println(git_result.output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user