From 208f67132d47c6d57bb3a8040c4f5cc9e76fbf37 Mon Sep 17 00:00:00 2001 From: prime31 Date: Thu, 28 Nov 2019 02:04:57 -0800 Subject: [PATCH] added -user_mod_path command line option to add a module search path --- vlib/compiler/main.v | 5 +++++ vlib/compiler/modules.v | 3 +++ 2 files changed, 8 insertions(+) diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index a492d6339e..0b1c66d924 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -125,6 +125,7 @@ pub mut: is_fmt bool is_bare bool + user_mod_path string // `v -user_mod_path /Users/user/modules` adds a new lookup path for imported modules vlib_path string vpath string x64 bool @@ -851,6 +852,9 @@ pub fn new_v(args[]string) &V { os.mkdir('$v_modules_path${os.path_separator}cache') or { panic(err) } } + // optional, custom modules search path + user_mod_path := get_cmdline_option(args, '-user_mod_path', '') + // Location of all vlib files vroot := os.dir(vexe_path()) vlib_path := get_cmdline_option(args, '-vlib-path', filepath.join(vroot, 'vlib')) @@ -1039,6 +1043,7 @@ pub fn new_v(args[]string) &V { building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v.v' || dir.contains('vlib')) comptime_define: comptime_define is_fmt: comptime_define == 'vfmt' + user_mod_path: user_mod_path vlib_path: vlib_path vpath: vpath } diff --git a/vlib/compiler/modules.v b/vlib/compiler/modules.v index 2b1d4adbe5..0506d1ae08 100644 --- a/vlib/compiler/modules.v +++ b/vlib/compiler/modules.v @@ -165,6 +165,9 @@ fn (v &V) find_module_path(mod string) ?string { tried_paths << filepath.join(v.compiled_dir, 'modules', mod_path) tried_paths << filepath.join(v.pref.vlib_path, mod_path) tried_paths << filepath.join(modules_lookup_path, mod_path) + if v.pref.user_mod_path.len > 0 { + tried_paths << v.pref.user_mod_path + } for try_path in tried_paths { if v.pref.is_verbose { println(' >> trying to find $mod in $try_path ...') } if os.dir_exists(try_path) {