Skip to content

Commit

Permalink
tools.vpm: add support for env variable VPM_FAIL_ON_PROMPT, to prev…
Browse files Browse the repository at this point in the history
…ent getting stuck in test scenarios with conflicting module dir names (#19960)
  • Loading branch information
ttytm committed Nov 21, 2023
1 parent e3d306d commit b60ef55
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/tools/vpm/install.v
Expand Up @@ -233,6 +233,10 @@ fn (m Module) confirm_install() bool {
} else {
install_version := at_version(if m.version == '' { 'latest' } else { m.version })
println('Module `${m.name}${at_version(m.installed_version)}` is already installed at `${m.install_path_fmted}`.')
if settings.fail_on_prompt {
vpm_error('VPM should not have entered a confirmation prompt.')
exit(1)
}
input := os.input('Replace it with `${m.name}${install_version}`? [Y/n]: ')
match input.to_lower() {
'', 'y' {
Expand Down
1 change: 1 addition & 0 deletions cmd/tools/vpm/install_test.v
Expand Up @@ -16,6 +16,7 @@ fn testsuite_begin() {
os.setenv('VMODULES', test_path, true)
os.setenv('VPM_DEBUG', '', true)
os.setenv('VPM_NO_INCREMENT', '1', true)
os.setenv('VPM_FAIL_ON_PROMPT', '1', true)
}

fn testsuite_end() {
Expand Down
1 change: 1 addition & 0 deletions cmd/tools/vpm/install_version_test.v
Expand Up @@ -14,6 +14,7 @@ fn testsuite_begin() {
os.setenv('VMODULES', test_path, true)
os.setenv('VPM_DEBUG', '', true)
os.setenv('VPM_NO_INCREMENT', '1', true)
os.setenv('VPM_FAIL_ON_PROMPT', '1', true)
}

fn testsuite_end() {
Expand Down
4 changes: 4 additions & 0 deletions cmd/tools/vpm/settings.v
Expand Up @@ -13,6 +13,9 @@ mut:
server_urls []string
vmodules_path string
no_dl_count_increment bool
// To ensure that some test scenarios with conflicting module directory names do not get stuck in prompts.
// It is intended that VPM does not display a prompt when `VPM_FAIL_ON_PROMPT` is set.
fail_on_prompt bool
// git is used by default. URL installations can specify `--hg`. For already installed modules
// and VPM modules that specify a different VCS in their `v.mod`, the VCS is validated separately.
vcs VCS
Expand All @@ -35,5 +38,6 @@ fn init_settings() VpmSettings {
vcs: supported_vcs[if '--hg' in opts { 'hg' } else { 'git' }]
vmodules_path: os.vmodules_dir()
no_dl_count_increment: os.getenv('CI') != '' || (no_inc_env != '' && no_inc_env != '0')
fail_on_prompt: os.getenv('VPM_FAIL_ON_PROMPT') != ''
}
}

0 comments on commit b60ef55

Please sign in to comment.