From 3560810c953f5bc5cea3a00492729f9dc342044f Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 10 Oct 2024 10:39:40 +0300 Subject: [PATCH] v.vcache: store the cache files in ~/.vmodules/_cache by default, allowing for user modules, that are named `cache` (fix #22459) --- vlib/v/tests/projects_that_should_compile_test.v | 3 +++ .../testdata/module_named_cache/src/cache/my_cache.v | 3 +++ vlib/v/tests/testdata/module_named_cache/src/main.v | 8 ++++++++ vlib/v/tests/testdata/module_named_cache/v.mod | 7 +++++++ vlib/v/vcache/vcache.v | 2 +- 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/testdata/module_named_cache/src/cache/my_cache.v create mode 100644 vlib/v/tests/testdata/module_named_cache/src/main.v create mode 100644 vlib/v/tests/testdata/module_named_cache/v.mod diff --git a/vlib/v/tests/projects_that_should_compile_test.v b/vlib/v/tests/projects_that_should_compile_test.v index baf9780447cd4f..bbd8e3c4f80ff0 100644 --- a/vlib/v/tests/projects_that_should_compile_test.v +++ b/vlib/v/tests/projects_that_should_compile_test.v @@ -28,4 +28,7 @@ fn test_projects_should_run() { res2 := vrun_ok('run', vroot_path('vlib/v/tests/testdata/modules_in_src/')) assert res2.trim_space() == 'somemodule somemoduletwo' + + res3 := vrun_ok('run', vroot_path('vlib/v/tests/testdata/module_named_cache/')) + assert res3.trim_space().ends_with('cache.a: 123') } diff --git a/vlib/v/tests/testdata/module_named_cache/src/cache/my_cache.v b/vlib/v/tests/testdata/module_named_cache/src/cache/my_cache.v new file mode 100644 index 00000000000000..ff345da98bc913 --- /dev/null +++ b/vlib/v/tests/testdata/module_named_cache/src/cache/my_cache.v @@ -0,0 +1,3 @@ +module cache + +pub const a = 123 diff --git a/vlib/v/tests/testdata/module_named_cache/src/main.v b/vlib/v/tests/testdata/module_named_cache/src/main.v new file mode 100644 index 00000000000000..2c476aa1e7de58 --- /dev/null +++ b/vlib/v/tests/testdata/module_named_cache/src/main.v @@ -0,0 +1,8 @@ +module main + +import cache + +fn main() { + println('Hello World!') + dump(cache.a) +} diff --git a/vlib/v/tests/testdata/module_named_cache/v.mod b/vlib/v/tests/testdata/module_named_cache/v.mod new file mode 100644 index 00000000000000..7dd2a885c3b05e --- /dev/null +++ b/vlib/v/tests/testdata/module_named_cache/v.mod @@ -0,0 +1,7 @@ +Module { + name: 'aa' + description: 'AA' + version: '0.0.0' + license: 'MIT' + dependencies: [] +} diff --git a/vlib/v/vcache/vcache.v b/vlib/v/vcache/vcache.v index aaf021886ee34f..6d07b1a323d3e1 100644 --- a/vlib/v/vcache/vcache.v +++ b/vlib/v/vcache/vcache.v @@ -37,7 +37,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.vmodules_dir(), 'cache') + vcache_basepath = os.join_path(os.vmodules_dir(), '_cache') // use a path, that would not conflict with a user installable module } nlog(@FN, 'vcache_basepath: ${vcache_basepath}\n opts: ${opts}\n os.args: ${os.args.join(' ')}') dlog(@FN, 'vcache_basepath: ${vcache_basepath} | opts:\n ${opts}')