mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: cached modules - windows fixes & organise cached module path (#2302)
compiler: cached modules - windows fixes & organise cached module path (#2302)
This commit is contained in:
parent
dd053d79b0
commit
40156392f8
@ -64,17 +64,14 @@ fn (v mut V) cc() {
|
||||
}
|
||||
if v.pref.build_mode == .build_module {
|
||||
// Create the modules & out directory if it's not there.
|
||||
out_dir := '$v_modules_path${os.PathSeparator}$v.dir'
|
||||
if !os.dir_exists(out_dir) {
|
||||
// create recursive
|
||||
mut mkpath := v_modules_path
|
||||
for subdir in v.dir.split(os.PathSeparator) {
|
||||
mkpath += os.PathSeparator + subdir
|
||||
if !os.dir_exists(mkpath) {
|
||||
os.mkdir(mkpath)
|
||||
}
|
||||
}
|
||||
//os.mkdir(out_dir)
|
||||
mut out_dir := if v.dir.starts_with('vlib') {
|
||||
'$v_modules_path${os.PathSeparator}cache${os.PathSeparator}$v.dir'
|
||||
} else {
|
||||
'$v_modules_path${os.PathSeparator}$v.dir'
|
||||
}
|
||||
pdir := out_dir.all_before_last(os.PathSeparator)
|
||||
if !os.dir_exists(pdir) {
|
||||
os.mkdir_all(pdir)
|
||||
}
|
||||
v.out_name = '${out_dir}.o' //v.out_name
|
||||
println('Building ${v.out_name}...')
|
||||
@ -120,25 +117,25 @@ fn (v mut V) cc() {
|
||||
}
|
||||
else if v.pref.is_debug {
|
||||
vexe := os.executable()
|
||||
builtin_o_path := '$v_modules_path/cache/builtin.o'
|
||||
builtin_o_path := '$v_modules_path${os.PathSeparator}cache${os.PathSeparator}vlib${os.PathSeparator}builtin.o'
|
||||
if os.file_exists(builtin_o_path) {
|
||||
libs = builtin_o_path
|
||||
} else {
|
||||
println('$builtin_o_path not found... building module builtin')
|
||||
os.system('$vexe build module vlib/builtin')
|
||||
os.system('$vexe build module vlib${os.PathSeparator}builtin')
|
||||
}
|
||||
for imp in v.table.imports {
|
||||
if imp.contains('vweb') { continue } // not working
|
||||
if imp == 'webview' { continue }
|
||||
|
||||
imp_path := imp.replace('.', os.PathSeparator)
|
||||
path := '$v_modules_path/cache/${imp_path}.o'
|
||||
path := '$v_modules_path${os.PathSeparator}cache${os.PathSeparator}vlib${os.PathSeparator}${imp_path}.o'
|
||||
println('adding ${imp_path}.o')
|
||||
if os.file_exists(path) {
|
||||
libs += ' ' + path
|
||||
} else {
|
||||
println('$path not found... building module $imp')
|
||||
os.system('$vexe build module vlib/$imp_path')
|
||||
os.system('$vexe build module vlib${os.PathSeparator}$imp_path')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,13 +94,6 @@ CommonCHeaders = '
|
||||
#define OPTION_CAST(x)
|
||||
#endif
|
||||
|
||||
void pthread_mutex_lock(HANDLE *m) {
|
||||
WaitForSingleObject(*m, INFINITE);
|
||||
}
|
||||
|
||||
void pthread_mutex_unlock(HANDLE *m) {
|
||||
ReleaseMutex(*m);
|
||||
}
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
@ -131,6 +131,14 @@ int load_so(byteptr path) {
|
||||
}
|
||||
else {
|
||||
cgen.genln('
|
||||
void pthread_mutex_lock(HANDLE *m) {
|
||||
WaitForSingleObject(*m, INFINITE);
|
||||
}
|
||||
|
||||
void pthread_mutex_unlock(HANDLE *m) {
|
||||
ReleaseMutex(*m);
|
||||
}
|
||||
|
||||
void* live_lib=0;
|
||||
int load_so(byteptr path) {
|
||||
char cpath[1024];
|
||||
|
@ -400,6 +400,9 @@ fn (v mut V) generate_init() {
|
||||
if v.pref.build_mode == .default_mode {
|
||||
mut call_mod_init := ''
|
||||
mut call_mod_init_consts := ''
|
||||
if 'builtin' in v.cached_mods {
|
||||
call_mod_init_consts += 'builtin__init_consts();\n'
|
||||
}
|
||||
for mod in v.table.imports {
|
||||
init_fn_name := mod_gen_name(mod) + '__init'
|
||||
if v.table.known_fn(init_fn_name) {
|
||||
@ -610,8 +613,9 @@ fn (v &V) v_files_from_dir(dir string) []string {
|
||||
fn (v mut V) add_v_files_to_compile() {
|
||||
mut builtin_files := v.get_builtin_files()
|
||||
// Builtin cache exists? Use it.
|
||||
builtin_vh := '$v_modules_path${os.PathSeparator}builtin.vh'
|
||||
builtin_vh := '$v_modules_path${os.PathSeparator}vlib${os.PathSeparator}builtin.vh'
|
||||
if v.pref.is_debug && os.file_exists(builtin_vh) {
|
||||
v.cached_mods << 'builtin'
|
||||
builtin_files = [builtin_vh]
|
||||
}
|
||||
// Parse builtin imports
|
||||
@ -653,7 +657,7 @@ fn (v mut V) add_v_files_to_compile() {
|
||||
// use cached built module if exists
|
||||
if v.pref.build_mode != .build_module && !mod.contains('vweb') {
|
||||
mod_path := mod.replace('.', os.PathSeparator)
|
||||
vh_path := '$v_modules_path/${mod_path}.vh'
|
||||
vh_path := '$v_modules_path${os.PathSeparator}vlib${os.PathSeparator}${mod_path}.vh'
|
||||
if v.pref.is_debug && os.file_exists(vh_path) {
|
||||
println('using cached module `$mod`: $vh_path')
|
||||
v.cached_mods << mod
|
||||
@ -822,6 +826,9 @@ fn new_v(args[]string) &V {
|
||||
if dir.ends_with(os.PathSeparator) {
|
||||
dir = dir.all_before_last(os.PathSeparator)
|
||||
}
|
||||
if dir.starts_with('.$os.PathSeparator') {
|
||||
dir = dir.right(2)
|
||||
}
|
||||
adir := os.realpath(dir)
|
||||
if args.len < 2 {
|
||||
dir = ''
|
||||
@ -918,7 +925,7 @@ fn new_v(args[]string) &V {
|
||||
println('Go to https://vlang.io to install V.')
|
||||
exit(1)
|
||||
}
|
||||
//println('out_name:$out_name')
|
||||
// println('out_name:$out_name')
|
||||
mut out_name_c := os.realpath('${out_name}.tmp.c')
|
||||
|
||||
cflags := get_cmdline_cflags(args)
|
||||
|
@ -107,17 +107,15 @@ fn v_type_str(typ_ string) string {
|
||||
fn (v &V) generate_vh() {
|
||||
println('\n\n\n\nGenerating a V header file for module `$v.mod`')
|
||||
mod_path := v.mod.replace('.', os.PathSeparator)
|
||||
dir := '$v_modules_path${os.PathSeparator}$mod_path'
|
||||
dir := if v.dir.starts_with('vlib') {
|
||||
'$v_modules_path${os.PathSeparator}$v.dir'
|
||||
} else {
|
||||
'$v_modules_path${os.PathSeparator}$mod_path'
|
||||
}
|
||||
path := dir + '.vh'
|
||||
if !os.dir_exists(dir) {
|
||||
// create recursive
|
||||
mut mkpath := v_modules_path
|
||||
for subdir in mod_path.split(os.PathSeparator) {
|
||||
mkpath += os.PathSeparator + subdir
|
||||
if !os.dir_exists(mkpath) {
|
||||
os.mkdir(mkpath)
|
||||
}
|
||||
}
|
||||
pdir := dir.all_before_last(os.PathSeparator)
|
||||
if !os.dir_exists(pdir) {
|
||||
os.mkdir_all(pdir)
|
||||
// os.mkdir(os.realpath(dir))
|
||||
}
|
||||
file := os.create(path) or { panic(err) }
|
||||
|
@ -859,12 +859,11 @@ pub fn print_backtrace() {
|
||||
}
|
||||
|
||||
pub fn mkdir_all(path string) {
|
||||
mut p := ''
|
||||
mut p := if path.starts_with(os.PathSeparator) { os.PathSeparator } else { '' }
|
||||
for subdir in path.split(os.PathSeparator) {
|
||||
p += os.PathSeparator + subdir
|
||||
p += subdir + os.PathSeparator
|
||||
if !os.dir_exists(p) {
|
||||
os.mkdir(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user