do not create ~/.vlang directory
parent
e638e47af5
commit
1748632144
|
@ -99,7 +99,7 @@ fn (f mut Fn) clear_vars() {
|
||||||
// vlib header file?
|
// vlib header file?
|
||||||
fn (p mut Parser) is_sig() bool {
|
fn (p mut Parser) is_sig() bool {
|
||||||
return (p.pref.build_mode == .default_mode || p.pref.build_mode == .build) &&
|
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 {
|
fn new_fn(pkg string, is_public bool) *Fn {
|
||||||
|
|
|
@ -24,13 +24,13 @@ enum BuildMode {
|
||||||
build //TODO a better name would be smth like `.build_module` I think
|
build //TODO a better name would be smth like `.build_module` I think
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vtmp_path() string {
|
fn modules_path() string {
|
||||||
return os.home_dir() + '/.vlang/'
|
return os.home_dir() + '/.vmodules/'
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SupportedPlatforms = ['windows', 'mac', 'linux', 'freebsd', 'openbsd', 'netbsd', 'dragonfly']
|
SupportedPlatforms = ['windows', 'mac', 'linux', 'freebsd', 'openbsd', 'netbsd', 'dragonfly']
|
||||||
TmpPath = vtmp_path()
|
ModPath = modules_path()
|
||||||
)
|
)
|
||||||
|
|
||||||
enum OS {
|
enum OS {
|
||||||
|
@ -109,10 +109,6 @@ fn main() {
|
||||||
}
|
}
|
||||||
// TODO quit if the compiler is too old
|
// TODO quit if the compiler is too old
|
||||||
// u := os.file_last_mod_unix('v')
|
// 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
|
// 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.
|
// Copy the `vlib` directory to the tmp path.
|
||||||
/*
|
/*
|
||||||
|
@ -134,6 +130,13 @@ fn main() {
|
||||||
println('vfmt is temporarily disabled')
|
println('vfmt is temporarily disabled')
|
||||||
return
|
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
|
// No args? REPL
|
||||||
if args.len < 2 || (args.len == 2 && args[1] == '-') {
|
if args.len < 2 || (args.len == 2 && args[1] == '-') {
|
||||||
run_repl()
|
run_repl()
|
||||||
|
@ -460,13 +463,13 @@ fn (c &V) cc_windows_cross() {
|
||||||
}
|
}
|
||||||
mut libs := ''
|
mut libs := ''
|
||||||
if c.pref.build_mode == .default_mode {
|
if c.pref.build_mode == .default_mode {
|
||||||
libs = '"$TmpPath/vlib/builtin.o"'
|
libs = '"$ModPath/vlib/builtin.o"'
|
||||||
if !os.file_exists(libs) {
|
if !os.file_exists(libs) {
|
||||||
println('`builtin.o` not found')
|
println('`builtin.o` not found')
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
for imp in c.table.imports {
|
for imp in c.table.imports {
|
||||||
libs += ' "$TmpPath/vlib/${imp}.o"'
|
libs += ' "$ModPath/vlib/${imp}.o"'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
args += ' $c.out_name_c '
|
args += ' $c.out_name_c '
|
||||||
|
@ -478,10 +481,10 @@ fn (c &V) cc_windows_cross() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println('Cross compiling for Windows...')
|
println('Cross compiling for Windows...')
|
||||||
winroot := '$TmpPath/winroot'
|
winroot := '$ModPath/winroot'
|
||||||
if !os.dir_exists(winroot) {
|
if !os.dir_exists(winroot) {
|
||||||
winroot_url := 'https://github.com/vlang/v/releases/download/v0.1.10/winroot.zip'
|
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)
|
exit(1)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -489,7 +492,7 @@ fn (c &V) cc_windows_cross() {
|
||||||
obj_name = obj_name.replace('.exe', '')
|
obj_name = obj_name.replace('.exe', '')
|
||||||
obj_name = obj_name.replace('.o.o', '.o')
|
obj_name = obj_name.replace('.o.o', '.o')
|
||||||
mut include := '-I $winroot/include '
|
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 {
|
if c.pref.show_c_cmd {
|
||||||
println(cmd)
|
println(cmd)
|
||||||
}
|
}
|
||||||
|
@ -556,7 +559,7 @@ fn (v mut V) cc() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
else if v.pref.build_mode == .default_mode {
|
else if v.pref.build_mode == .default_mode {
|
||||||
libs = '"$TmpPath/vlib/builtin.o"'
|
libs = '"$ModPath/vlib/builtin.o"'
|
||||||
if !os.file_exists(libs) {
|
if !os.file_exists(libs) {
|
||||||
println('`builtin.o` not found')
|
println('`builtin.o` not found')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -565,7 +568,7 @@ fn (v mut V) cc() {
|
||||||
if imp == 'webview' {
|
if imp == 'webview' {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
libs += ' "$TmpPath/vlib/${imp}.o"'
|
libs += ' "$ModPath/vlib/${imp}.o"'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// -I flags
|
// -I flags
|
||||||
|
@ -748,7 +751,7 @@ fn (v mut V) add_user_v_files() {
|
||||||
if v.pref.build_mode == .default_mode {
|
if v.pref.build_mode == .default_mode {
|
||||||
for i := 0; i < v.table.imports.len; i++ {
|
for i := 0; i < v.table.imports.len; i++ {
|
||||||
pkg := v.module_path(v.table.imports[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
|
// Add all imports referenced by these libs
|
||||||
for file in vfiles {
|
for file in vfiles {
|
||||||
mut p := v.new_parser(file, Pass.imports)
|
mut p := v.new_parser(file, Pass.imports)
|
||||||
|
@ -787,7 +790,7 @@ fn (v mut V) add_user_v_files() {
|
||||||
// TmpPath/vlib
|
// TmpPath/vlib
|
||||||
// These were generated by vfmt
|
// These were generated by vfmt
|
||||||
if v.pref.build_mode == .default_mode || v.pref.build_mode == .build {
|
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)) {
|
if(!os.file_exists(module_path)) {
|
||||||
module_path = '$v.lang_dir/vlib/$pkg'
|
module_path = '$v.lang_dir/vlib/$pkg'
|
||||||
|
@ -1000,8 +1003,12 @@ fn new_v(args[]string) *V {
|
||||||
fn run_repl() []string {
|
fn run_repl() []string {
|
||||||
println('V $Version')
|
println('V $Version')
|
||||||
println('Use Ctrl-C or `exit` to exit')
|
println('Use Ctrl-C or `exit` to exit')
|
||||||
file := TmpPath + '/vrepl.v'
|
file := '.vrepl.v'
|
||||||
temp_file := TmpPath + '/vrepl_temp.v'
|
temp_file := '.vrepl_temp.v'
|
||||||
|
defer {
|
||||||
|
os.rm(file)
|
||||||
|
os.rm(temp_file)
|
||||||
|
}
|
||||||
mut lines := []string
|
mut lines := []string
|
||||||
for {
|
for {
|
||||||
print('>>> ')
|
print('>>> ')
|
||||||
|
@ -1019,7 +1026,7 @@ fn run_repl() []string {
|
||||||
if line.starts_with('print') {
|
if line.starts_with('print') {
|
||||||
source_code := lines.join('\n') + '\n' + line
|
source_code := lines.join('\n') + '\n' + line
|
||||||
os.write_file(file, source_code)
|
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')
|
mut vals := s.split('\n')
|
||||||
if s.contains('panic: ') {
|
if s.contains('panic: ') {
|
||||||
if !s.contains('declared and not used') {
|
if !s.contains('declared and not used') {
|
||||||
|
@ -1046,7 +1053,7 @@ fn run_repl() []string {
|
||||||
}
|
}
|
||||||
temp_source_code := lines.join('\n') + '\n' + temp_line
|
temp_source_code := lines.join('\n') + '\n' + temp_line
|
||||||
os.write_file(temp_file, temp_source_code)
|
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('panic: ') {
|
||||||
if !s.contains('declared and not used') {
|
if !s.contains('declared and not used') {
|
||||||
mut vals := s.split('\n')
|
mut vals := s.split('\n')
|
||||||
|
|
Loading…
Reference in New Issue