Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools.vpm: extract outdated logic into outdated.v, fix outdated hg, e…
…xtend tests (#20116)
- Loading branch information
Showing
9 changed files
with
122 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module main | ||
|
||
import os | ||
import sync.pool | ||
|
||
pub struct OutdatedResult { | ||
name string | ||
mut: | ||
outdated bool | ||
} | ||
|
||
fn vpm_outdated() { | ||
outdated := get_outdated() | ||
if outdated.len > 0 { | ||
println('Outdated modules:') | ||
for m in outdated { | ||
println(' ${m}') | ||
} | ||
} else { | ||
println('Modules are up to date.') | ||
} | ||
} | ||
|
||
fn get_outdated() []string { | ||
installed := get_installed_modules() | ||
if installed.len == 0 { | ||
println('No modules installed.') | ||
exit(0) | ||
} | ||
mut pp := pool.new_pool_processor( | ||
callback: fn (mut pp pool.PoolProcessor, idx int, wid int) &OutdatedResult { | ||
mut result := &OutdatedResult{ | ||
name: pp.get_item[string](idx) | ||
} | ||
path := get_path_of_existing_module(result.name) or { return result } | ||
result.outdated = is_outdated(path) | ||
return result | ||
} | ||
) | ||
pp.work_on_items(installed) | ||
mut outdated := []string{} | ||
for res in pp.get_results[OutdatedResult]() { | ||
if res.outdated { | ||
outdated << res.name | ||
} | ||
} | ||
return outdated | ||
} | ||
|
||
fn is_outdated(path string) bool { | ||
vcs := vcs_used_in_dir(path) or { return false } | ||
args := vcs_info[vcs].args | ||
mut outputs := []string{} | ||
for step in args.outdated { | ||
cmd := [vcs.str(), args.path, os.quoted_path(path), step].join(' ') | ||
vpm_log(@FILE_LINE, @FN, 'cmd: ${cmd}') | ||
res := os.execute(cmd) | ||
vpm_log(@FILE_LINE, @FN, 'output: ${res.output}') | ||
if vcs == .hg { | ||
return res.exit_code == 0 | ||
} | ||
outputs << res.output | ||
} | ||
// Compare the current and latest origin commit sha. | ||
return vcs == .git && outputs[1] != outputs[2] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// vtest retry: 3 | ||
module main | ||
|
||
import os | ||
import rand | ||
import test_utils | ||
|
||
const test_path = os.join_path(os.vtmp_dir(), 'vpm_outdated_test_${rand.ulid()}') | ||
|
||
fn testsuite_begin() { | ||
test_utils.set_test_env(test_path) | ||
os.mkdir_all(test_path)! | ||
os.chdir(test_path)! | ||
} | ||
|
||
fn testsuite_end() { | ||
os.rmdir_all(test_path) or {} | ||
} | ||
|
||
fn test_is_outdated_git_module() { | ||
os.execute_or_exit('git clone https://github.com/vlang/libsodium.git') | ||
assert !is_outdated('libsodium') | ||
os.execute_or_exit('git -C libsodium reset --hard HEAD~1') | ||
assert is_outdated('libsodium') | ||
os.execute_or_exit('git -C libsodium pull') | ||
assert !is_outdated('libsodium') | ||
} | ||
|
||
fn test_is_outdated_hg_module() { | ||
os.find_abs_path_of_executable('hg') or { | ||
eprintln('skipping test, since `hg` is not executable.') | ||
return | ||
} | ||
os.execute_or_exit('hg clone https://www.mercurial-scm.org/repo/hello') | ||
assert !is_outdated('hello') | ||
os.execute_or_exit('hg --config extensions.strip= -R hello strip -r tip') | ||
assert is_outdated('hello') | ||
os.execute_or_exit('hg -R hello pull') | ||
assert !is_outdated('hello') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters