2020-02-28 15:02:56 +03:00
|
|
|
|
module main
|
|
|
|
|
|
2020-04-26 09:32:05 +03:00
|
|
|
|
import os
|
|
|
|
|
import v.pref
|
2020-02-28 15:02:56 +03:00
|
|
|
|
|
|
|
|
|
fn main() {
|
2020-02-28 18:04:22 +03:00
|
|
|
|
vexe := pref.vexe_path()
|
2020-03-08 00:26:26 +03:00
|
|
|
|
vroot := os.dir(vexe)
|
2020-02-28 15:02:56 +03:00
|
|
|
|
os.chdir(vroot)
|
2020-03-16 17:46:38 +03:00
|
|
|
|
|
2020-04-24 13:36:27 +03:00
|
|
|
|
self_idx := os.args.index('self')
|
|
|
|
|
args := os.args[1..self_idx]
|
|
|
|
|
args_str := args.join(' ')
|
|
|
|
|
options := if args.len > 0 { '($args_str)' } else { '' }
|
|
|
|
|
println('V self compiling ${options}...')
|
2020-03-16 17:46:38 +03:00
|
|
|
|
|
2020-04-24 13:36:27 +03:00
|
|
|
|
cmd := '$vexe -o v2 $args_str cmd/v'
|
2020-04-07 17:56:33 +03:00
|
|
|
|
result := os.exec(cmd) or { panic(err) }
|
|
|
|
|
if result.exit_code != 0 {
|
|
|
|
|
mut err := 'Permission denied'
|
|
|
|
|
if !result.output.contains('Permission denied') {
|
|
|
|
|
err = '\n$result.output'
|
|
|
|
|
}
|
|
|
|
|
eprintln('cannot compile to ‘$vroot: $err')
|
2020-02-28 18:04:22 +03:00
|
|
|
|
exit(1)
|
|
|
|
|
}
|
2020-04-07 17:56:33 +03:00
|
|
|
|
if result.output.len > 0 {
|
|
|
|
|
println(result.output)
|
|
|
|
|
}
|
2020-03-16 17:46:38 +03:00
|
|
|
|
|
2020-02-28 18:04:22 +03:00
|
|
|
|
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' }
|
2020-03-16 17:46:38 +03:00
|
|
|
|
|
2020-02-28 18:04:22 +03:00
|
|
|
|
if os.exists(bak_file) {
|
|
|
|
|
os.rm(bak_file)
|
2020-02-28 15:02:56 +03:00
|
|
|
|
}
|
2020-02-28 18:04:22 +03:00
|
|
|
|
os.mv(v_file, bak_file)
|
|
|
|
|
os.mv(v2_file, v_file)
|
2020-02-28 15:02:56 +03:00
|
|
|
|
}
|