mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
bring back local modules
This commit is contained in:
parent
9eb385d9ee
commit
01531369f7
@ -981,15 +981,7 @@ fn (v mut V) add_v_files_to_compile() {
|
|||||||
// for mod in v.table.imports {
|
// for mod in v.table.imports {
|
||||||
for i := 0; i < v.table.imports.len; i++ {
|
for i := 0; i < v.table.imports.len; i++ {
|
||||||
mod := v.table.imports[i]
|
mod := v.table.imports[i]
|
||||||
mod_path := v.module_path(mod)
|
import_path := v.find_module_path(mod)
|
||||||
mut import_path := '$ModPath/$mod_path'
|
|
||||||
//println('ip=$import_path')
|
|
||||||
if !os.dir_exists(import_path){
|
|
||||||
import_path = '$v.lang_dir/vlib/$mod_path'
|
|
||||||
if !os.dir_exists(import_path){
|
|
||||||
panic('module "$mod" not found')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vfiles := v.v_files_from_dir(import_path)
|
vfiles := v.v_files_from_dir(import_path)
|
||||||
if vfiles.len == 0 {
|
if vfiles.len == 0 {
|
||||||
panic('cannot import module $mod (no .v files in "$import_path").')
|
panic('cannot import module $mod (no .v files in "$import_path").')
|
||||||
@ -1019,18 +1011,16 @@ fn (v mut V) add_v_files_to_compile() {
|
|||||||
if mod == v.mod {
|
if mod == v.mod {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mod_p := v.module_path(mod)
|
mod_path := v.find_module_path(mod)
|
||||||
mut module_path := '$ModPath/$mod_p'
|
|
||||||
// If we are in default mode, we don't parse vlib .v files, but header .vh files in
|
// If we are in default mode, we don't parse vlib .v files, but header .vh files in
|
||||||
// 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 = '$ModPath/vlib/$mod_p'
|
module_path = '$ModPath/vlib/$mod_p'
|
||||||
}
|
}
|
||||||
if !os.dir_exists(module_path) {
|
*/
|
||||||
module_path = '$v.lang_dir/vlib/$mod_p'
|
vfiles := v.v_files_from_dir(mod_path)
|
||||||
}
|
|
||||||
vfiles := v.v_files_from_dir(module_path)
|
|
||||||
for file in vfiles {
|
for file in vfiles {
|
||||||
if !file in v.files {
|
if !file in v.files {
|
||||||
v.files << file
|
v.files << file
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
module main
|
module main
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
struct ModDepGraphNode {
|
struct ModDepGraphNode {
|
||||||
mut:
|
mut:
|
||||||
name string
|
name string
|
||||||
@ -145,3 +147,25 @@ pub fn(graph &ModDepGraph) display() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 'strings' => 'VROOT/vlib/strings'
|
||||||
|
// 'installed_mod' => '~/.vmodules/installed_mod'
|
||||||
|
// 'local_mod' => '/path/to/current/dir/local_mod'
|
||||||
|
fn (v &V) find_module_path(mod string) string {
|
||||||
|
mod_path := v.module_path(mod)
|
||||||
|
// First check for local modules in the same directory
|
||||||
|
mut import_path := os.getwd() + '/$mod_path'
|
||||||
|
// Now search in vlib/
|
||||||
|
if !os.dir_exists(import_path) {
|
||||||
|
import_path = '$v.lang_dir/vlib/$mod_path'
|
||||||
|
}
|
||||||
|
//println('ip=$import_path')
|
||||||
|
// Finally try modules installed with vpm (~/.vmodules)
|
||||||
|
if !os.dir_exists(import_path) {
|
||||||
|
import_path = '$ModPath/$mod_path'
|
||||||
|
if !os.dir_exists(import_path){
|
||||||
|
panic('module "$mod" not found')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return import_path
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user