all: get -usecache working with mods in ~/.vmodules (ui examples)

pull/7366/head
joe-conigliaro 2020-12-17 16:08:28 +11:00
parent 7022456c9d
commit f2f32626bc
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
4 changed files with 23 additions and 12 deletions

View File

@ -385,13 +385,6 @@ fn (mut v Builder) cc() {
if imp == 'webview' {
continue
}
// println('cache: import "$imp"')
mod_path := imp.replace('.', os.path_separator)
// TODO: to get import path all imports (even relative) we can use:
// import_path := v.find_module_path(imp, ast_file.path) or {
// verror('cannot import module "$imp" (not found)')
// break
// }
// The problem is cmd/v is in module main and imports
// the relative module named help, which is built as cmd.v.help not help
// currently this got this workign by building into main, see ast.FnDecl in cgen
@ -402,7 +395,11 @@ fn (mut v Builder) cc() {
// if os.is_dir(af_base_dir + os.path_separator + mod_path) {
// continue
// }
imp_path := os.join_path('vlib', mod_path)
// imp_path := os.join_path('vlib', mod_path)
imp_path := v.find_module_path(imp, ast_file.path) or {
verror('cannot import module "$imp" (not found)')
break
}
obj_path := v.rebuild_cached_module(vexe, imp_path)
libs += ' ' + obj_path
if obj_path.ends_with('vlib/ui.o') {

View File

@ -3,6 +3,7 @@
// that can be found in the LICENSE file.
module gen
import os
import strings
import v.ast
import v.table
@ -138,6 +139,18 @@ const (
pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string {
// println('start cgen2')
mut module_built := ''
if pref.build_mode == .build_module {
// TODO: detect this properly for all cases
// either get if from an earlier stage or use the lookup paths
if pref.path.contains('vlib' + os.path_separator) {
module_built = pref.path.after('vlib' + os.path_separator).replace(os.path_separator,
'.')
} else if pref.path.contains('.vmodules' + os.path_separator) {
module_built = pref.path.after('.vmodules' + os.path_separator).replace(os.path_separator,
'.')
}
}
mut g := Gen{
out: strings.new_builder(1000)
cheaders: strings.new_builder(8192)
@ -164,7 +177,7 @@ pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string
fn_decl: 0
autofree: true
indent: -1
module_built: pref.path.after('vlib/').replace('/', '.')
module_built: module_built
}
for mod in g.table.modules {
g.inits[mod] = strings.new_builder(100)

View File

@ -1622,7 +1622,7 @@ fn (mut p Parser) module_decl() ast.Module {
// is not imported.
// So here we fetch the name of the module by looking at the path that's being built.
word := p.pref.path.after('/')
if full_mod == word {
if full_mod == word && p.pref.path.contains('vlib') {
full_mod = p.pref.path.after('vlib/').replace('/', '.')
// println('new full mod =$full_mod')
}

View File

@ -678,8 +678,9 @@ pub fn (t &Table) mktyp(typ Type) Type {
}
}
// Once we have a module format we can read from module file instead
// this is not optimal
// TODO: Once we have a module format we can read from module file instead
// this is not optimal. it depends on the full import being in table.imports
// already, we can instead lookup the module path and then work it out
pub fn (table &Table) qualify_module(mod string, file_path string) string {
for m in table.imports {
// if m.contains('gen') { println('qm=$m') }