Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools.vpm: improve detection of already parsed modules #20223

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion cmd/tools/vpm/dependency_test.v
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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