main.v: remove hardcoded path ~/code/v and allow V to be installed anywhere
parent
e285311290
commit
5a469c2e37
|
@ -759,12 +759,31 @@ fn new_v(args[]string) *V {
|
|||
'option.v',
|
||||
'string_builder.v',
|
||||
]
|
||||
// Location of all vlib files TODO allow custom location
|
||||
mut lang_dir = os.home_dir() + '/code/v/'
|
||||
if !os.dir_exists(lang_dir) {
|
||||
println('$lang_dir not found. Run:')
|
||||
println('git clone https://github.com/vlang/v ~/code/v')
|
||||
exit(1)
|
||||
// Location of all vlib files
|
||||
mut lang_dir = ''
|
||||
// First try fetching it from VROOT if it's defined
|
||||
vroot_path := TmpPath + '/VROOT'
|
||||
if os.file_exists(vroot_path) {
|
||||
vroot := os.read_file(vroot_path).trim_space()
|
||||
if os.dir_exists(vroot) && os.dir_exists(vroot + '/builtin') {
|
||||
lang_dir = vroot
|
||||
}
|
||||
}
|
||||
// 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"
|
||||
cur_dir := os.getwd()
|
||||
lang_dir = cur_dir.all_before_last('/')
|
||||
if os.dir_exists('$lang_dir/builtin') {
|
||||
println('Setting VROOT to "$lang_dir".')
|
||||
os.write_file(TmpPath + '/VROOT', lang_dir)
|
||||
} else {
|
||||
println('Please do it from "v/compiler" directory.')
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
out_name_c := out_name.all_after('/') + '.c'
|
||||
mut files := []string
|
||||
|
|
Loading…
Reference in New Issue