tools/vself: minor optimization (#7877)

pull/7882/head
yuyi 2021-01-05 10:00:15 +08:00 committed by GitHub
parent 5c1981379e
commit c66ee8aa61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 8 deletions

View File

@ -23,13 +23,12 @@ fn main() {
// The user just wants an independent copy of v, and so we are done.
return
}
backup_old_version_and_rename_newer()
backup_old_version_and_rename_newer() or { panic(err) }
println('V built successfully!')
}
fn compile(vroot string, cmd string) {
result := os.exec(cmd) or {
panic(err)
}
result := os.exec(cmd) or { panic(err) }
if result.exit_code != 0 {
eprintln('cannot compile to `$vroot`: \n$result.output')
exit(1)
@ -39,13 +38,13 @@ fn compile(vroot string, cmd string) {
}
}
fn backup_old_version_and_rename_newer() {
fn backup_old_version_and_rename_newer() ? {
v_file := if os.user_os() == 'windows' { 'v.exe' } else { 'v' }
v2_file := if os.user_os() == 'windows' { 'v2.exe' } else { 'v2' }
bak_file := if os.user_os() == 'windows' { 'v_old.exe' } else { 'v_old' }
if os.exists(bak_file) {
os.rm(bak_file)
os.rm(bak_file) ?
}
os.mv(v_file, bak_file)
os.mv(v2_file, v_file)
os.mv(v_file, bak_file) ?
os.mv(v2_file, v_file) ?
}