mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
tools: fix resolving external dependencies in vpm, add test (#19772)
This commit is contained in:
parent
e7f0c6bc3d
commit
9fa1f8e275
3 changed files with 71 additions and 3 deletions
|
@ -265,12 +265,13 @@ fn resolve_dependencies(name string, module_path string, module_names []string)
|
|||
eprintln(err)
|
||||
return
|
||||
}
|
||||
// filter out dependencies that were already specified by the user
|
||||
// Filter out modules that are both contained in the input query and listed as
|
||||
// dependencies in the mod file of the module that is supposed to be installed.
|
||||
deps := manifest.dependencies.filter(it !in module_names)
|
||||
if deps.len > 0 {
|
||||
println('Resolving ${deps.len} dependencies for module "${name}" ...')
|
||||
verbose_println('Found dependencies: ${deps}')
|
||||
vpm_install_from_vpm(deps)
|
||||
vpm_install(deps)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
67
cmd/tools/vpm/dependency_test.v
Normal file
67
cmd/tools/vpm/dependency_test.v
Normal file
|
@ -0,0 +1,67 @@
|
|||
import os
|
||||
import v.vmod
|
||||
|
||||
const (
|
||||
v = os.quoted_path(@VEXE)
|
||||
test_path = os.join_path(os.vtmp_dir(), 'vpm_dependency_test')
|
||||
)
|
||||
|
||||
fn testsuite_begin() {
|
||||
os.setenv('VMODULES', test_path, true)
|
||||
os.setenv('VPM_NO_INCREMENT', '1', true)
|
||||
}
|
||||
|
||||
fn testsuite_end() {
|
||||
os.rmdir_all(test_path) or {}
|
||||
}
|
||||
|
||||
fn get_mod_name(path string) string {
|
||||
mod := vmod.from_file(path) or {
|
||||
eprintln(err)
|
||||
return ''
|
||||
}
|
||||
return mod.name
|
||||
}
|
||||
|
||||
// Case: running `v install` without specifying modules in a V project directory.
|
||||
fn test_install_dependencies_in_module_dir() {
|
||||
os.mkdir_all(test_path) or {}
|
||||
mod := 'my_module'
|
||||
mod_path := os.join_path(test_path, mod)
|
||||
os.mkdir(mod_path)!
|
||||
os.chdir(mod_path)!
|
||||
// Create a v.mod file that lists dependencies.
|
||||
vmod_path := os.join_path(mod_path, 'v.mod')
|
||||
vmod_contents := "Module {
|
||||
name: '${mod}'
|
||||
description: ''
|
||||
version: '0.0.0'
|
||||
license: 'MIT'
|
||||
dependencies: ['markdown', 'pcre', 'https://github.com/spytheman/vtray']
|
||||
}"
|
||||
os.write_file(vmod_path, vmod_contents)!
|
||||
v_mod := vmod.from_file(vmod_path) or {
|
||||
assert false, err.msg()
|
||||
return
|
||||
}
|
||||
assert v_mod.dependencies == ['markdown', 'pcre', 'https://github.com/spytheman/vtray']
|
||||
// Run `v install`
|
||||
res := os.execute_or_exit('${v} install')
|
||||
assert res.output.contains('Detected v.mod file inside the project directory. Using it...')
|
||||
assert res.output.contains('Installing module "markdown"')
|
||||
assert res.output.contains('Installing module "pcre"')
|
||||
assert res.output.contains('Installing module "vtray"')
|
||||
assert get_mod_name(os.join_path(test_path, 'markdown', 'v.mod')) == 'markdown'
|
||||
assert get_mod_name(os.join_path(test_path, 'pcre', 'v.mod')) == 'pcre'
|
||||
assert get_mod_name(os.join_path(test_path, 'vtray', 'v.mod')) == 'vtray'
|
||||
}
|
||||
|
||||
fn test_resolve_external_dependencies_during_module_install() {
|
||||
res := os.execute_or_exit('${v} install https://github.com/ttytm/emoji-mart-desktop')
|
||||
assert res.output.contains('Resolving 2 dependencies')
|
||||
assert res.output.contains('Installing module "webview"')
|
||||
assert res.output.contains('Installing module "miniaudio"')
|
||||
// The external dependencies should have been installed to `<vmodules_dir>/<dependency_name>`
|
||||
assert get_mod_name(os.join_path(test_path, 'webview', 'v.mod')) == 'webview'
|
||||
assert get_mod_name(os.join_path(test_path, 'miniaudio', 'v.mod')) == 'miniaudio'
|
||||
}
|
|
@ -5,7 +5,7 @@ const (
|
|||
v = os.quoted_path(@VEXE)
|
||||
// Running tests appends a tsession path to VTMP, which is automatically cleaned up after the test.
|
||||
// The following will result in e.g. `$VTMP/tsession_7fe8e93bd740_1612958707536/test-vmodules/`.
|
||||
test_path = os.join_path(os.vtmp_dir(), 'test-vmodules')
|
||||
test_path = os.join_path(os.vtmp_dir(), 'vpm_install_test')
|
||||
)
|
||||
|
||||
fn testsuite_begin() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue