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

pull/567/head
Alexander Medvednikov 2019-06-25 01:38:58 +02:00
parent e285311290
commit 5a469c2e37
1 changed files with 25 additions and 6 deletions

View File

@ -759,13 +759,32 @@ fn new_v(args[]string) *V {
'option.v', 'option.v',
'string_builder.v', 'string_builder.v',
] ]
// Location of all vlib files TODO allow custom location // Location of all vlib files
mut lang_dir = os.home_dir() + '/code/v/' mut lang_dir = ''
if !os.dir_exists(lang_dir) { // First try fetching it from VROOT if it's defined
println('$lang_dir not found. Run:') vroot_path := TmpPath + '/VROOT'
println('git clone https://github.com/vlang/v ~/code/v') 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) exit(1)
} }
}
out_name_c := out_name.all_after('/') + '.c' out_name_c := out_name.all_after('/') + '.c'
mut files := []string mut files := []string
// Add builtin files // Add builtin files