From 01531369f738f624f2239ec98c1af561c9fd054e Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 4 Aug 2019 00:03:52 +0200 Subject: [PATCH] bring back local modules --- compiler/main.v | 20 +++++--------------- compiler/modules.v | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/compiler/main.v b/compiler/main.v index 4cb36c891b..8c535dde00 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -981,15 +981,7 @@ fn (v mut V) add_v_files_to_compile() { // for mod in v.table.imports { for i := 0; i < v.table.imports.len; i++ { mod := v.table.imports[i] - mod_path := v.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') - } - } + import_path := v.find_module_path(mod) vfiles := v.v_files_from_dir(import_path) if vfiles.len == 0 { 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 { continue } - mod_p := v.module_path(mod) - mut module_path := '$ModPath/$mod_p' + mod_path := v.find_module_path(mod) // If we are in default mode, we don't parse vlib .v files, but header .vh files in // TmpPath/vlib // These were generated by vfmt +/* if v.pref.build_mode == .default_mode || v.pref.build_mode == .build { 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(module_path) +*/ + vfiles := v.v_files_from_dir(mod_path) for file in vfiles { if !file in v.files { v.files << file diff --git a/compiler/modules.v b/compiler/modules.v index 8e4e396af5..09dde6fa85 100644 --- a/compiler/modules.v +++ b/compiler/modules.v @@ -4,6 +4,8 @@ module main +import os + struct ModDepGraphNode { mut: 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 +}