fix and simplify VROOT

pull/1168/head
Alexander Medvednikov 2019-07-15 23:33:31 +02:00
parent 24a1e0e24a
commit edbcefb811
1 changed files with 12 additions and 34 deletions

View File

@ -933,44 +933,22 @@ fn new_v(args[]string) *V {
'option.v', 'option.v',
] ]
// Location of all vlib files // Location of all vlib files
mut lang_dir := '' vroot := os.executable().all_before_last('/')
// First try fetching it from VROOT if it's defined println('VROOT=$vroot')
for { // TODO tmp hack for optionals // v.exe's parent directory should contain vlib
vroot_path := TmpPath + '/VROOT'
if os.file_exists(vroot_path) {
mut vroot := os.read_file(vroot_path) or {
break
}
//mut vroot := os.read_file(vroot_path)
vroot=vroot.trim_space()
if os.dir_exists(vroot) && os.dir_exists(vroot + '/vlib/builtin') { if os.dir_exists(vroot) && os.dir_exists(vroot + '/vlib/builtin') {
lang_dir = vroot
}
}
break
}
// no "~/.vlang/VROOT" file, so the user must be running V for the first
// time.
if lang_dir == '' {
println('Looks like you are running V for the first time.')
// The parent directory should contain vlib if V is run
// from "v/compiler"
lang_dir = os.getwd()
if os.dir_exists('$lang_dir/vlib/builtin') {
println('Setting VROOT to "$lang_dir".')
os.write_file(TmpPath + '/VROOT', lang_dir)
} else { } else {
println('V repo not found. Go to https://vlang.io to download V.zip ') println('vlib not found. It should be next to V executable. ')
println('or install V from source.') println('Go to https://vlang.io to install V.')
exit(1) exit(1)
} }
}
mut out_name_c := out_name.all_after('/') + '.c' mut out_name_c := out_name.all_after('/') + '.c'
mut files := []string mut files := []string
// Add builtin files // Add builtin files
if !out_name.contains('builtin.o') { if !out_name.contains('builtin.o') {
for builtin in builtins { for builtin in builtins {
mut f := '$lang_dir/vlib/builtin/$builtin' mut f := '$vroot/vlib/builtin/$builtin'
// In default mode we use precompiled vlib.o, point to .vh files with signatures // In default mode we use precompiled vlib.o, point to .vh files with signatures
if build_mode == .default_mode || build_mode == .build { if build_mode == .default_mode || build_mode == .build {
//f = '$TmpPath/vlib/builtin/${builtin}h' //f = '$TmpPath/vlib/builtin/${builtin}h'
@ -1008,12 +986,12 @@ fn new_v(args[]string) *V {
out_name: out_name out_name: out_name
files: files files: files
dir: dir dir: dir
lang_dir: lang_dir lang_dir: vroot
table: new_table(obfuscate) table: new_table(obfuscate)
out_name: out_name out_name: out_name
out_name_c: out_name_c out_name_c: out_name_c
cgen: new_cgen(out_name_c) cgen: new_cgen(out_name_c)
vroot: lang_dir vroot: vroot
pref: pref pref: pref
} }
} }