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:
parent
e285311290
commit
5a469c2e37
@ -759,12 +759,31 @@ 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) {
|
||||||
exit(1)
|
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'
|
out_name_c := out_name.all_after('/') + '.c'
|
||||||
mut files := []string
|
mut files := []string
|
||||||
|
Loading…
Reference in New Issue
Block a user