all: support VMODULES environment variable (defaulting to ~/.vmodules)

pull/6779/head
Delyan Angelov 2020-11-08 08:07:17 +02:00
parent 0ba5544446
commit 4b35495fbe
8 changed files with 19 additions and 13 deletions

View File

@ -552,7 +552,7 @@ fn init_settings() {
s.is_help = '-h' in os.args || '--help' in os.args || 'help' in os.args
s.is_verbose = '-v' in os.args
s.server_urls = cmdline.options(os.args, '-server-url')
s.vmodules_path = os.join_path(os.home_dir(), '.vmodules')
s.vmodules_path = os.vmodules_dir()
}
fn verbose_println(s string) {

View File

@ -54,7 +54,8 @@ The build flags are shared by the build and run commands:
separated by pipes (`|`). In addition to absolute paths, you can
also use these special strings too:
@vmodules - replaced with the location of the global ~/.vmodules/ folder
(modules installed with `v install` are there).
(modules installed with `v install` are there). You can change
its location by setting the environment variable VMODULES.
@vlib - replaced with the location of the v's vlib folder.
Using these, you can arrange for very flexible search orders for you project, for example:
-path "/v/my_project_private_modules|@vlib|@vmodules"

View File

@ -1355,6 +1355,15 @@ pub fn temp_dir() string {
return path
}
// vmodules_dir returns the path to a folder, where v stores its global modules.
pub fn vmodules_dir() string {
mut path := os.getenv('VMODULES')
if path == '' {
path = os.join_path(os.home_dir(), '.vmodules')
}
return path
}
// chmod change file access attributes of `path` to `mode`.
// Octals like `0o600` can be used.
pub fn chmod(path string, mode int) {

View File

@ -637,11 +637,11 @@ fn (mut v Builder) cc() {
}
fn (mut b Builder) cc_linux_cross() {
parent_dir := os.join_path(os.home_dir(), '.vmodules')
parent_dir := os.vmodules_dir()
if !os.exists(parent_dir) {
os.mkdir(parent_dir)
}
sysroot := os.join_path(os.home_dir(), '.vmodules', 'linuxroot')
sysroot := os.join_path(os.vmodules_dir(), 'linuxroot')
if !os.is_dir(sysroot) {
println('Downloading files for Linux cross compilation (~18 MB)...')
zip_url := 'https://github.com/vlang/v/releases/download/0.1.27/linuxroot.zip'

View File

@ -65,7 +65,7 @@ pub fn lookup_module_with_path(mod string, base_path string) ?string {
compile_dir := os.real_path(base_path)
modules_dir := os.join_path(compile_dir, 'modules', mod_path)
vlib_path := os.join_path(os.dir(@VEXE), 'vlib', mod_path)
vmodules_path := os.join_path(os.home_dir(), '.vmodules', mod_path)
vmodules_path := os.join_path(os.vmodules_dir(), mod_path)
paths := [modules_dir, vlib_path, vmodules_path]
for path in paths {
if !os.exists(path) || os.is_dir_empty(path) {

View File

@ -7,13 +7,9 @@ import os
import v.vcache
pub const (
default_module_path = mpath()
default_module_path = os.vmodules_dir()
)
fn mpath() string {
return os.join_path(os.home_dir(), '.vmodules')
}
pub fn new_preferences() Preferences {
mut p := Preferences{}
p.fill_with_defaults()

View File

@ -299,7 +299,7 @@ fn non_empty(arg []string) []string {
}
pub fn check_module_is_installed(modulename string, is_verbose bool) ?bool {
mpath := os.join_path(os.home_dir(), '.vmodules', modulename)
mpath := os.join_path(os.vmodules_dir(), modulename)
mod_v_file := os.join_path(mpath, 'v.mod')
murl := 'https://github.com/vlang/$modulename'
if is_verbose {

View File

@ -36,7 +36,7 @@ pub mut:
pub fn new_cache_manager(opts []string) CacheManager {
mut vcache_basepath := os.getenv('VCACHE')
if vcache_basepath == '' {
vcache_basepath = os.join_path(os.home_dir(), '.vmodules', 'cache')
vcache_basepath = os.join_path(os.vmodules_dir(), 'cache')
}
if !os.is_dir(vcache_basepath) {
os.mkdir_all(vcache_basepath)