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

main.v: remove hardcoded path ~/code/v and allow V to be installed anywhere

This commit is contained in:
Alexander Medvednikov 2019-06-25 01:38:58 +02:00
parent e285311290
commit 5a469c2e37

View File

@ -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