Skip to content

Commit e1cf85f

Browse files
authored
tools.vpm: fix install paths, only normalize relevant, restore assign install_path_fmted, add input tests (#19984)
1 parent bc62c5c commit e1cf85f

File tree

5 files changed

+108
-10
lines changed

5 files changed

+108
-10
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env expect
2+
3+
set timeout 3
4+
5+
set vexe [lindex $argv 0]
6+
set mod [lindex $argv 1]
7+
set cur_tag [lindex $argv 2]
8+
set new_tag [lindex $argv 3]
9+
set install_path [lindex $argv 4]
10+
11+
spawn $vexe install $mod@$new_tag
12+
13+
expect "Scanning `$mod`..." {} timeout { exit 1 }
14+
expect "Module `$mod@$cur_tag` is already installed at `$install_path`." {} timeout { exit 1 }
15+
expect "Replace it with `$mod@$new_tag`? \\\[Y/n\\\]: " { send "\r" } timeout { exit 1 }
16+
expect "Installing `$mod`..." {} timeout { exit 1 }
17+
expect "Skipping download count increment for `$mod`." {} timeout { exit 1 }
18+
expect "Installed `$mod`." {} timeout { exit 1 }
19+
20+
expect eof
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env expect
2+
3+
set timeout 3
4+
5+
set vexe [lindex $argv 0]
6+
set mod [lindex $argv 1]
7+
set cur_tag [lindex $argv 2]
8+
set new_tag [lindex $argv 3]
9+
set install_path [lindex $argv 4]
10+
11+
spawn $vexe install $mod@$new_tag
12+
13+
expect "Scanning `$mod`..." {} timeout { exit 1 }
14+
expect "Module `$mod@$cur_tag` is already installed at `$install_path`." {} timeout { exit 1 }
15+
expect "Replace it with `$mod@$new_tag`? \\\[Y/n\\\]: " { send "n\r" } timeout { exit 1 }
16+
17+
expect eof

cmd/tools/vpm/install.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ fn (m Module) confirm_install() bool {
141141
println('Module `${m.name}${at_version(m.installed_version)}` is already installed, use --force to overwrite.')
142142
return false
143143
} else {
144-
install_version := at_version(if m.version == '' { 'latest' } else { m.version })
145144
println('Module `${m.name}${at_version(m.installed_version)}` is already installed at `${m.install_path_fmted}`.')
146145
if settings.fail_on_prompt {
147146
vpm_error('VPM should not have entered a confirmation prompt.')
148147
exit(1)
149148
}
149+
install_version := at_version(if m.version == '' { 'latest' } else { m.version })
150150
input := os.input('Replace it with `${m.name}${install_version}`? [Y/n]: ')
151-
match input.to_lower() {
151+
match input.trim_space().to_lower() {
152152
'', 'y' {
153153
return true
154154
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// vtest retry: 3
2+
import os
3+
import v.vmod
4+
5+
const vexe = os.quoted_path(@VEXE)
6+
const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_version_input_test')
7+
const expect_tests_path = os.join_path(@VEXEROOT, 'cmd', 'tools', 'vpm', 'expect')
8+
const expect_exe = os.quoted_path(os.find_abs_path_of_executable('expect') or {
9+
eprintln('skipping test, since expect is missing')
10+
exit(0)
11+
})
12+
13+
fn testsuite_begin() {
14+
os.setenv('VMODULES', test_path, true)
15+
os.setenv('VPM_NO_INCREMENT', '1', true)
16+
os.setenv('VPM_DEBUG', '', true)
17+
// Explicitly disable fail on prompt.
18+
os.setenv('VPM_FAIL_ON_PROMPT', '', true)
19+
os.mkdir_all(test_path) or {}
20+
os.chdir(test_path)!
21+
}
22+
23+
fn testsuite_end() {
24+
os.rmdir_all(test_path) or {}
25+
}
26+
27+
fn get_mod_name_and_version(path string) (string, string) {
28+
mod := vmod.from_file(os.join_path(test_path, path, 'v.mod')) or {
29+
eprintln(err)
30+
return '', ''
31+
}
32+
return mod.name, mod.version
33+
}
34+
35+
// Test installing another version of a module of which an explicit version is already installed.
36+
fn test_reinstall_mod_with_version_installation() {
37+
// Install version.
38+
mod := 'vsl'
39+
tag := 'v0.1.47'
40+
os.execute_or_exit('${vexe} install ${mod}@${tag}')
41+
mut name, mut version := get_mod_name_and_version(mod)
42+
assert name == mod
43+
assert version == tag.trim_left('v')
44+
45+
// Try reinstalling.
46+
new_tag := 'v0.1.50'
47+
install_path := os.real_path(os.join_path(test_path, mod))
48+
expect_args := [vexe, mod, tag, new_tag, install_path].join(' ')
49+
50+
// Decline.
51+
decline_test := os.join_path(expect_tests_path, 'decline_reinstall_mod_with_version_installation.expect')
52+
manifest_path := os.join_path(install_path, 'v.mod')
53+
last_modified := os.file_last_mod_unix(manifest_path)
54+
os.execute_or_exit('${expect_exe} ${decline_test} ${expect_args}')
55+
assert last_modified == os.file_last_mod_unix(manifest_path)
56+
57+
// Accept.
58+
accept_test := os.join_path(expect_tests_path, 'accept_reinstall_mod_with_version_installation.expect')
59+
os.execute_or_exit('${expect_exe} ${accept_test} ${expect_args}')
60+
name, version = get_mod_name_and_version(mod)
61+
assert name == mod, name
62+
assert version == new_tag.trim_left('v'), version
63+
}

cmd/tools/vpm/parse.v

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,12 @@ fn parse_query(query []string) []Module {
5858
continue
5959
}
6060
// Resolve path.
61-
base := if is_http { publisher } else { '' }
62-
install_path := normalize_mod_path(os.real_path(os.join_path(settings.vmodules_path,
63-
base, manifest.name)))
61+
mod_path := normalize_mod_path(os.join_path(if is_http { publisher } else { '' },
62+
manifest.name))
6463
Module{
6564
name: manifest.name
6665
url: ident
67-
install_path: install_path
66+
install_path: os.real_path(os.join_path(settings.vmodules_path, mod_path))
6867
is_external: true
6968
manifest: manifest
7069
}
@@ -113,17 +112,16 @@ fn parse_query(query []string) []Module {
113112
vmod.Manifest{}
114113
}
115114
// Resolve path.
116-
ident_as_path := info.name.replace('.', os.path_separator)
117-
install_path := normalize_mod_path(os.real_path(os.join_path(settings.vmodules_path,
118-
ident_as_path)))
115+
mod_path := normalize_mod_path(info.name.replace('.', os.path_separator))
119116
Module{
120117
name: info.name
121118
url: info.url
122119
vcs: vcs
123-
install_path: install_path
120+
install_path: os.real_path(os.join_path(settings.vmodules_path, mod_path))
124121
manifest: manifest
125122
}
126123
}
124+
mod.install_path_fmted = fmt_mod_path(mod.install_path)
127125
mod.version = version
128126
mod.get_installed()
129127
modules << mod

0 commit comments

Comments
 (0)