Skip to content

Commit

Permalink
main.v: remove hardcoded path ~/code/v and allow V to be installed an…
Browse files Browse the repository at this point in the history
…ywhere
  • Loading branch information
medvednikov committed Jun 24, 2019
1 parent e285311 commit 5a469c2
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions compiler/main.v
Expand Up @@ -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
Expand Down

0 comments on commit 5a469c2

Please sign in to comment.