do not create ~/.vlang directory

pull/1182/head
Alexander Medvednikov 2019-07-16 17:42:04 +02:00
parent e638e47af5
commit 1748632144
2 changed files with 28 additions and 21 deletions

View File

@ -99,7 +99,7 @@ fn (f mut Fn) clear_vars() {
// vlib header file?
fn (p mut Parser) is_sig() bool {
return (p.pref.build_mode == .default_mode || p.pref.build_mode == .build) &&
(p.file_path.contains(TmpPath))
(p.file_path.contains(ModPath))
}
fn new_fn(pkg string, is_public bool) *Fn {

View File

@ -24,13 +24,13 @@ enum BuildMode {
build //TODO a better name would be smth like `.build_module` I think
}
fn vtmp_path() string {
return os.home_dir() + '/.vlang/'
fn modules_path() string {
return os.home_dir() + '/.vmodules/'
}
const (
SupportedPlatforms = ['windows', 'mac', 'linux', 'freebsd', 'openbsd', 'netbsd', 'dragonfly']
TmpPath = vtmp_path()
ModPath = modules_path()
)
enum OS {
@ -109,10 +109,6 @@ fn main() {
}
// TODO quit if the compiler is too old
// u := os.file_last_mod_unix('v')
// Create a temp directory if it's not there.
if !os.file_exists(TmpPath) {
os.mkdir(TmpPath)
}
// If there's no tmp path with current version yet, the user must be using a pre-built package
// Copy the `vlib` directory to the tmp path.
/*
@ -134,6 +130,13 @@ fn main() {
println('vfmt is temporarily disabled')
return
}
// v get sqlite
if 'get' in args {
// Create the modules directory if it's not there.
if !os.file_exists(ModPath) {
os.mkdir(ModPath)
}
}
// No args? REPL
if args.len < 2 || (args.len == 2 && args[1] == '-') {
run_repl()
@ -460,13 +463,13 @@ fn (c &V) cc_windows_cross() {
}
mut libs := ''
if c.pref.build_mode == .default_mode {
libs = '"$TmpPath/vlib/builtin.o"'
libs = '"$ModPath/vlib/builtin.o"'
if !os.file_exists(libs) {
println('`builtin.o` not found')
exit(1)
}
for imp in c.table.imports {
libs += ' "$TmpPath/vlib/${imp}.o"'
libs += ' "$ModPath/vlib/${imp}.o"'
}
}
args += ' $c.out_name_c '
@ -478,10 +481,10 @@ fn (c &V) cc_windows_cross() {
}
}
println('Cross compiling for Windows...')
winroot := '$TmpPath/winroot'
winroot := '$ModPath/winroot'
if !os.dir_exists(winroot) {
winroot_url := 'https://github.com/vlang/v/releases/download/v0.1.10/winroot.zip'
println('"$winroot" not found. Download it from $winroot_url and save in $TmpPath')
println('"$winroot" not found. Download it from $winroot_url and save in $ModPath')
exit(1)
}
@ -489,7 +492,7 @@ fn (c &V) cc_windows_cross() {
obj_name = obj_name.replace('.exe', '')
obj_name = obj_name.replace('.o.o', '.o')
mut include := '-I $winroot/include '
cmd := 'clang -o $obj_name -w $include -m32 -c -target x86_64-win32 $TmpPath/$c.out_name_c'
cmd := 'clang -o $obj_name -w $include -m32 -c -target x86_64-win32 $ModPath/$c.out_name_c'
if c.pref.show_c_cmd {
println(cmd)
}
@ -556,7 +559,7 @@ fn (v mut V) cc() {
//
}
else if v.pref.build_mode == .default_mode {
libs = '"$TmpPath/vlib/builtin.o"'
libs = '"$ModPath/vlib/builtin.o"'
if !os.file_exists(libs) {
println('`builtin.o` not found')
exit(1)
@ -565,7 +568,7 @@ fn (v mut V) cc() {
if imp == 'webview' {
continue
}
libs += ' "$TmpPath/vlib/${imp}.o"'
libs += ' "$ModPath/vlib/${imp}.o"'
}
}
// -I flags
@ -748,7 +751,7 @@ fn (v mut V) add_user_v_files() {
if v.pref.build_mode == .default_mode {
for i := 0; i < v.table.imports.len; i++ {
pkg := v.module_path(v.table.imports[i])
vfiles := v.v_files_from_dir('$TmpPath/vlib/$pkg')
vfiles := v.v_files_from_dir('$ModPath/vlib/$pkg')
// Add all imports referenced by these libs
for file in vfiles {
mut p := v.new_parser(file, Pass.imports)
@ -787,7 +790,7 @@ fn (v mut V) add_user_v_files() {
// TmpPath/vlib
// These were generated by vfmt
if v.pref.build_mode == .default_mode || v.pref.build_mode == .build {
module_path = '$TmpPath/vlib/$pkg'
module_path = '$ModPath/vlib/$pkg'
}
if(!os.file_exists(module_path)) {
module_path = '$v.lang_dir/vlib/$pkg'
@ -1000,8 +1003,12 @@ fn new_v(args[]string) *V {
fn run_repl() []string {
println('V $Version')
println('Use Ctrl-C or `exit` to exit')
file := TmpPath + '/vrepl.v'
temp_file := TmpPath + '/vrepl_temp.v'
file := '.vrepl.v'
temp_file := '.vrepl_temp.v'
defer {
os.rm(file)
os.rm(temp_file)
}
mut lines := []string
for {
print('>>> ')
@ -1019,7 +1026,7 @@ fn run_repl() []string {
if line.starts_with('print') {
source_code := lines.join('\n') + '\n' + line
os.write_file(file, source_code)
s := os.exec('v run '+TmpPath+'/vrepl.v -repl')
s := os.exec('v run $file -repl')
mut vals := s.split('\n')
if s.contains('panic: ') {
if !s.contains('declared and not used') {
@ -1046,7 +1053,7 @@ fn run_repl() []string {
}
temp_source_code := lines.join('\n') + '\n' + temp_line
os.write_file(temp_file, temp_source_code)
s := os.exec('v run '+TmpPath+'/vrepl_temp.v -repl')
s := os.exec('v run $temp_file -repl')
if s.contains('panic: ') {
if !s.contains('declared and not used') {
mut vals := s.split('\n')