mirror of
https://github.com/vlang/v.git
synced 2025-09-18 11:56:57 -04:00
tools.vpm: extend recursive dependency fix for module installation (#20015)
This commit is contained in:
parent
920be09c7e
commit
50f3ac4968
@ -1,6 +1,7 @@
|
||||
// vtest retry: 3
|
||||
import os
|
||||
import v.vmod
|
||||
import time
|
||||
|
||||
const v = os.quoted_path(@VEXE)
|
||||
const test_path = os.join_path(os.vtmp_dir(), 'vpm_dependency_test')
|
||||
@ -72,3 +73,11 @@ fn test_resolve_external_dependencies_during_module_install() {
|
||||
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'
|
||||
}
|
||||
|
||||
fn test_install_with_recursive_dependencies() {
|
||||
spawn fn () {
|
||||
time.sleep(2 * time.minute)
|
||||
exit(1)
|
||||
}()
|
||||
os.execute_or_exit('${v} install https://gitlab.com/tobealive/a')
|
||||
}
|
||||
|
@ -18,13 +18,31 @@ mut:
|
||||
manifest vmod.Manifest
|
||||
}
|
||||
|
||||
struct Parser {
|
||||
mut:
|
||||
modules map[string]Module
|
||||
checked_settings_vcs bool
|
||||
is_git_setting bool
|
||||
errors int
|
||||
}
|
||||
|
||||
fn parse_query(query []string) []Module {
|
||||
mut modules := []Module{}
|
||||
mut dependencies := map[string]bool{}
|
||||
mut checked_settings_vcs := false
|
||||
mut errors := 0
|
||||
is_git_setting := settings.vcs.cmd == 'git'
|
||||
mut p := Parser{
|
||||
is_git_setting: settings.vcs.cmd == 'git'
|
||||
}
|
||||
for m in query {
|
||||
p.parse_module(m)
|
||||
}
|
||||
if p.errors > 0 && p.errors == query.len {
|
||||
exit(1)
|
||||
}
|
||||
return p.modules.values()
|
||||
}
|
||||
|
||||
fn (mut p Parser) parse_module(m string) {
|
||||
if m in p.modules {
|
||||
return
|
||||
}
|
||||
ident, version := m.rsplit_once('@') or { m, '' }
|
||||
println('Scanning `${ident}`...')
|
||||
is_http := if ident.starts_with('http://') {
|
||||
@ -39,24 +57,24 @@ fn parse_query(query []string) []Module {
|
||||
// External module. The idenifier is an URL.
|
||||
publisher, name := get_ident_from_url(ident) or {
|
||||
vpm_error(err.msg())
|
||||
errors++
|
||||
continue
|
||||
p.errors++
|
||||
return
|
||||
}
|
||||
// Verify VCS. Only needed once for external modules.
|
||||
if !checked_settings_vcs {
|
||||
checked_settings_vcs = true
|
||||
if !p.checked_settings_vcs {
|
||||
p.checked_settings_vcs = true
|
||||
settings.vcs.is_executable() or {
|
||||
vpm_error(err.msg())
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
// Fetch manifest.
|
||||
manifest := fetch_manifest(name, ident, version, is_git_setting) or {
|
||||
manifest := fetch_manifest(name, ident, version, p.is_git_setting) or {
|
||||
vpm_error('failed to find `v.mod` for `${ident}${at_version(version)}`.',
|
||||
details: err.msg()
|
||||
)
|
||||
errors++
|
||||
continue
|
||||
p.errors++
|
||||
return
|
||||
}
|
||||
// Resolve path.
|
||||
mod_path := normalize_mod_path(os.join_path(if is_http { publisher } else { '' },
|
||||
@ -72,22 +90,22 @@ fn parse_query(query []string) []Module {
|
||||
// VPM registered module.
|
||||
info := get_mod_vpm_info(ident) or {
|
||||
vpm_error('failed to retrieve metadata for `${ident}`.', details: err.msg())
|
||||
errors++
|
||||
continue
|
||||
p.errors++
|
||||
return
|
||||
}
|
||||
// Verify VCS.
|
||||
mut is_git_module := true
|
||||
vcs := if info.vcs != '' {
|
||||
info_vcs := supported_vcs[info.vcs] or {
|
||||
vpm_error('skipping `${info.name}`, since it uses an unsupported version control system `${info.vcs}`.')
|
||||
errors++
|
||||
continue
|
||||
p.errors++
|
||||
return
|
||||
}
|
||||
is_git_module = info.vcs == 'git'
|
||||
if !is_git_module && version != '' {
|
||||
vpm_error('skipping `${info.name}`, version installs are currently only supported for projects using `git`.')
|
||||
errors++
|
||||
continue
|
||||
p.errors++
|
||||
return
|
||||
}
|
||||
info_vcs
|
||||
} else {
|
||||
@ -95,8 +113,8 @@ fn parse_query(query []string) []Module {
|
||||
}
|
||||
vcs.is_executable() or {
|
||||
vpm_error(err.msg())
|
||||
errors++
|
||||
continue
|
||||
p.errors++
|
||||
return
|
||||
}
|
||||
// Fetch manifest.
|
||||
manifest := fetch_manifest(info.name, info.url, version, is_git_module) or {
|
||||
@ -125,27 +143,13 @@ fn parse_query(query []string) []Module {
|
||||
mod.install_path_fmted = fmt_mod_path(mod.install_path)
|
||||
mod.version = version
|
||||
mod.get_installed()
|
||||
modules << mod
|
||||
p.modules[m] = mod
|
||||
if mod.manifest.dependencies.len > 0 {
|
||||
verbose_println('Found ${mod.manifest.dependencies.len} dependencies for `${mod.name}`: ${mod.manifest.dependencies}.')
|
||||
for d in mod.manifest.dependencies {
|
||||
if !dependencies[d] {
|
||||
dependencies[d] = true
|
||||
p.parse_module(d)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if errors > 0 && errors == query.len {
|
||||
exit(1)
|
||||
}
|
||||
if dependencies.len > 0 {
|
||||
vpm_log(@FILE_LINE, @FN, 'dependencies: ${dependencies}')
|
||||
deps := dependencies.keys().filter(it !in query)
|
||||
vpm_log(@FILE_LINE, @FN, 'dependencies filtered: ${deps}')
|
||||
println('Scanning dependencies...')
|
||||
modules << parse_query(deps)
|
||||
}
|
||||
return modules
|
||||
}
|
||||
|
||||
// TODO: add unit test
|
||||
|
Loading…
x
Reference in New Issue
Block a user