1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

make and vself: cleanup make based on the new 'v self'

This commit is contained in:
Delyan Angelov
2020-02-28 17:04:22 +02:00
committed by GitHub
parent ccf4f61521
commit 10e15e5de7
4 changed files with 47 additions and 39 deletions

View File

@@ -8,29 +8,24 @@ import (
fn main() {
println('V Self Compiling...')
vroot := filepath.dir(pref.vexe_path())
vexe := pref.vexe_path()
vroot := filepath.dir(vexe)
os.chdir(vroot)
s2 := os.exec('v -o v2 cmd/v') or {
s2 := os.exec('$vexe -o v2 cmd/v') or {
panic(err)
}
println(s2.output)
$if windows {
bak_file := 'v_old.exe'
if os.exists(bak_file) {
os.rm(bak_file)
}
os.mv('v.exe', bak_file)
os.mv('v2.exe', 'v.exe')
} $else {
bak_file := 'v_old'
if os.exists(bak_file) {
os.rm(bak_file)
}
os.mv('v', bak_file)
os.mv('v2', 'v')
if s2.output.len > 0 {
println(s2.output)
}
if s2.exit_code != 0 {
exit(1)
}
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.mv(v_file, bak_file)
os.mv(v2_file, v_file)
}

View File

@@ -39,9 +39,18 @@ fn launch_tool(is_verbose bool, tname string, cmdname string) {
// v was recompiled, maybe after v up ...
// rebuild the tool too just in case
should_compile = true
if tname == 'vself' || tname == 'vup' {
// The purpose of vself/up is to update and recompile v itself.
// After the first 'v self' execution, v will be modified, so
// then a second 'v self' will detect, that v is newer than the
// vself executable, and try to recompile vself/up again, which
// will slow down the next v recompilation needlessly.
should_compile = false
}
}
if os.file_last_mod_unix(tool_exe) <= os.file_last_mod_unix(tool_source) {
// the user changed the source code of the tool
// the user changed the source code of the tool, or git updated it:
should_compile = true
}
}