From 9ea039e6fc536e72d9123b6bdbcb688efa41568a Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Tue, 19 Dec 2023 22:47:37 +0100 Subject: [PATCH] tools.vpm: improve detection of already parsed modules (#20223) --- cmd/tools/vpm/dependency_test.v | 10 +++++++++- cmd/tools/vpm/parse.v | 32 ++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/cmd/tools/vpm/dependency_test.v b/cmd/tools/vpm/dependency_test.v index 4ba9a5c2f7cd57..06370cdfb0ce0a 100644 --- a/cmd/tools/vpm/dependency_test.v +++ b/cmd/tools/vpm/dependency_test.v @@ -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() } diff --git a/cmd/tools/vpm/parse.v b/cmd/tools/vpm/parse.v index f8063efa6638bb..ea1dbca40c111c 100644 --- a/cmd/tools/vpm/parse.v +++ b/cmd/tools/vpm/parse.v @@ -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.' @@ -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++ @@ -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 {