mirror of
https://github.com/vlang/v.git
synced 2025-09-18 03:46:36 -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
|
// vtest retry: 3
|
||||||
import os
|
import os
|
||||||
import v.vmod
|
import v.vmod
|
||||||
|
import time
|
||||||
|
|
||||||
const v = os.quoted_path(@VEXE)
|
const v = os.quoted_path(@VEXE)
|
||||||
const test_path = os.join_path(os.vtmp_dir(), 'vpm_dependency_test')
|
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, 'webview', 'v.mod')) == 'webview'
|
||||||
assert get_mod_name(os.join_path(test_path, 'miniaudio', 'v.mod')) == 'miniaudio'
|
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
|
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 {
|
fn parse_query(query []string) []Module {
|
||||||
mut modules := []Module{}
|
mut p := Parser{
|
||||||
mut dependencies := map[string]bool{}
|
is_git_setting: settings.vcs.cmd == 'git'
|
||||||
mut checked_settings_vcs := false
|
}
|
||||||
mut errors := 0
|
|
||||||
is_git_setting := settings.vcs.cmd == 'git'
|
|
||||||
for m in query {
|
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, '' }
|
ident, version := m.rsplit_once('@') or { m, '' }
|
||||||
println('Scanning `${ident}`...')
|
println('Scanning `${ident}`...')
|
||||||
is_http := if ident.starts_with('http://') {
|
is_http := if ident.starts_with('http://') {
|
||||||
@ -39,24 +57,24 @@ fn parse_query(query []string) []Module {
|
|||||||
// External module. The idenifier is an URL.
|
// External module. The idenifier is an URL.
|
||||||
publisher, name := get_ident_from_url(ident) or {
|
publisher, name := get_ident_from_url(ident) or {
|
||||||
vpm_error(err.msg())
|
vpm_error(err.msg())
|
||||||
errors++
|
p.errors++
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
// Verify VCS. Only needed once for external modules.
|
// Verify VCS. Only needed once for external modules.
|
||||||
if !checked_settings_vcs {
|
if !p.checked_settings_vcs {
|
||||||
checked_settings_vcs = true
|
p.checked_settings_vcs = true
|
||||||
settings.vcs.is_executable() or {
|
settings.vcs.is_executable() or {
|
||||||
vpm_error(err.msg())
|
vpm_error(err.msg())
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Fetch manifest.
|
// 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)}`.',
|
vpm_error('failed to find `v.mod` for `${ident}${at_version(version)}`.',
|
||||||
details: err.msg()
|
details: err.msg()
|
||||||
)
|
)
|
||||||
errors++
|
p.errors++
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
// Resolve path.
|
// Resolve path.
|
||||||
mod_path := normalize_mod_path(os.join_path(if is_http { publisher } else { '' },
|
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.
|
// VPM registered module.
|
||||||
info := get_mod_vpm_info(ident) or {
|
info := get_mod_vpm_info(ident) or {
|
||||||
vpm_error('failed to retrieve metadata for `${ident}`.', details: err.msg())
|
vpm_error('failed to retrieve metadata for `${ident}`.', details: err.msg())
|
||||||
errors++
|
p.errors++
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
// Verify VCS.
|
// Verify VCS.
|
||||||
mut is_git_module := true
|
mut is_git_module := true
|
||||||
vcs := if info.vcs != '' {
|
vcs := if info.vcs != '' {
|
||||||
info_vcs := supported_vcs[info.vcs] or {
|
info_vcs := supported_vcs[info.vcs] or {
|
||||||
vpm_error('skipping `${info.name}`, since it uses an unsupported version control system `${info.vcs}`.')
|
vpm_error('skipping `${info.name}`, since it uses an unsupported version control system `${info.vcs}`.')
|
||||||
errors++
|
p.errors++
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
is_git_module = info.vcs == 'git'
|
is_git_module = info.vcs == 'git'
|
||||||
if !is_git_module && version != '' {
|
if !is_git_module && version != '' {
|
||||||
vpm_error('skipping `${info.name}`, version installs are currently only supported for projects using `git`.')
|
vpm_error('skipping `${info.name}`, version installs are currently only supported for projects using `git`.')
|
||||||
errors++
|
p.errors++
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
info_vcs
|
info_vcs
|
||||||
} else {
|
} else {
|
||||||
@ -95,8 +113,8 @@ fn parse_query(query []string) []Module {
|
|||||||
}
|
}
|
||||||
vcs.is_executable() or {
|
vcs.is_executable() or {
|
||||||
vpm_error(err.msg())
|
vpm_error(err.msg())
|
||||||
errors++
|
p.errors++
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
// Fetch manifest.
|
// Fetch manifest.
|
||||||
manifest := fetch_manifest(info.name, info.url, version, is_git_module) or {
|
manifest := fetch_manifest(info.name, info.url, version, is_git_module) or {
|
||||||
@ -125,28 +143,14 @@ fn parse_query(query []string) []Module {
|
|||||||
mod.install_path_fmted = fmt_mod_path(mod.install_path)
|
mod.install_path_fmted = fmt_mod_path(mod.install_path)
|
||||||
mod.version = version
|
mod.version = version
|
||||||
mod.get_installed()
|
mod.get_installed()
|
||||||
modules << mod
|
p.modules[m] = mod
|
||||||
if mod.manifest.dependencies.len > 0 {
|
if mod.manifest.dependencies.len > 0 {
|
||||||
verbose_println('Found ${mod.manifest.dependencies.len} dependencies for `${mod.name}`: ${mod.manifest.dependencies}.')
|
verbose_println('Found ${mod.manifest.dependencies.len} dependencies for `${mod.name}`: ${mod.manifest.dependencies}.')
|
||||||
for d in mod.manifest.dependencies {
|
for d in mod.manifest.dependencies {
|
||||||
if !dependencies[d] {
|
p.parse_module(d)
|
||||||
dependencies[d] = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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
|
// TODO: add unit test
|
||||||
fn (mut m Module) get_installed() {
|
fn (mut m Module) get_installed() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user