Skip to content

Commit

Permalink
tools.vpm: improve detection of already parsed modules (#20223)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Dec 19, 2023
1 parent 4bab3e7 commit 9ea039e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
10 changes: 9 additions & 1 deletion cmd/tools/vpm/dependency_test.v
Expand Up @@ -84,6 +84,14 @@ fn test_install_with_recursive_dependencies() {
eprintln('Timeout while testing installation with recursive dependencies.')
exit(1)
}()
res := os.execute('${v} install https://gitlab.com/tobealive/a')
mut res := os.execute('${v} install https://gitlab.com/tobealive/a')
assert res.exit_code == 0, res.str()

// Test the installation of a module when passing its URL with the `.git` extension.
// One of the modules dependencies `https://gitlab.com/tobealive/c` has the
// `https://gitlab.com/tobealive/a` dependency without `.git`.
res = os.execute('${v} remove a b c')
assert res.exit_code == 0, res.str()
res = os.execute('${v} install https://gitlab.com/tobealive/a.git')
assert res.exit_code == 0, res.str()
}
32 changes: 18 additions & 14 deletions cmd/tools/vpm/parse.v
Expand Up @@ -45,27 +45,32 @@ fn parse_query(query []string) []Module {
}

fn (mut p Parser) parse_module(m string) {
if m in p.modules {
return
}
kind := match true {
m.starts_with('https://') { ModuleKind.https }
m.starts_with('git@') { ModuleKind.ssh }
m.starts_with('http://') { ModuleKind.http }
else { ModuleKind.registered }
}
ident, version := if kind == .ssh {
if m.count('@') > 1 {
m.all_before_last('@'), m.all_after_last('@')
} else {
m, ''
}
} else {
m.rsplit_once('@') or { m, '' }
}
key := match kind {
.registered { m }
.ssh { ident.replace(':', '/') + at_version(version) }
else { ident.all_after('//').trim_string_right('.git') + at_version(version) }
}
if key in p.modules {
return
}
println('Scanning `${m}`...')
mut mod := if kind != ModuleKind.registered {
// External module. The identifier is an URL.
ident, version := if kind == .ssh {
if m.count('@') > 1 {
m.all_before_last('@'), m.all_after_last('@')
} else {
m, ''
}
} else {
m.rsplit_once('@') or { m, '' }
}
if kind == .http {
vpm_warn('installing `${ident}` via http.',
details: 'Support for `http` is deprecated, use `https` to ensure future compatibility.'
Expand Down Expand Up @@ -119,7 +124,6 @@ fn (mut p Parser) parse_module(m string) {
}
} else {
// VPM registered module.
ident, version := m.rsplit_once('@') or { m, '' }
info := get_mod_vpm_info(ident) or {
vpm_error('failed to retrieve metadata for `${ident}`.', details: err.msg())
p.errors++
Expand Down Expand Up @@ -177,7 +181,7 @@ fn (mut p Parser) parse_module(m string) {
}
mod.install_path_fmted = fmt_mod_path(mod.install_path)
mod.get_installed()
p.modules[m] = mod
p.modules[key] = 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 {
Expand Down

0 comments on commit 9ea039e

Please sign in to comment.