mirror of
https://github.com/vlang/v.git
synced 2025-09-10 07:47:20 -04:00
vpm.tools: cleanup and make handling of the different VCS systems more robust (#19740)
This commit is contained in:
parent
ceb191d317
commit
be89cbf26f
@ -36,12 +36,11 @@ fn get_mod_date_info(mut pp pool.PoolProcessor, idx int, wid int) &ModDateInfo {
|
|||||||
}
|
}
|
||||||
final_module_path := valid_final_path_of_existing_module(result.name) or { return result }
|
final_module_path := valid_final_path_of_existing_module(result.name) or { return result }
|
||||||
vcs := vcs_used_in_dir(final_module_path) or { return result }
|
vcs := vcs_used_in_dir(final_module_path) or { return result }
|
||||||
is_hg := vcs[0] == 'hg'
|
is_hg := vcs.cmd == 'hg'
|
||||||
vcs_cmd_steps := supported_vcs_outdated_steps[vcs[0]]
|
|
||||||
mut outputs := []string{}
|
mut outputs := []string{}
|
||||||
for step in vcs_cmd_steps {
|
for step in vcs.outdated_steps {
|
||||||
path_flag := if is_hg { '-R' } else { '-C' }
|
path_flag := if is_hg { '-R' } else { '-C' }
|
||||||
cmd := '${vcs[0]} ${path_flag} "${final_module_path}" ${step}'
|
cmd := '${vcs.cmd} ${path_flag} "${final_module_path}" ${step}'
|
||||||
res := os.execute('${cmd}')
|
res := os.execute('${cmd}')
|
||||||
if res.exit_code < 0 {
|
if res.exit_code < 0 {
|
||||||
verbose_println('Error command: ${cmd}')
|
verbose_println('Error command: ${cmd}')
|
||||||
@ -55,7 +54,7 @@ fn get_mod_date_info(mut pp pool.PoolProcessor, idx int, wid int) &ModDateInfo {
|
|||||||
}
|
}
|
||||||
outputs << res.output
|
outputs << res.output
|
||||||
}
|
}
|
||||||
// vcs[0] == 'git'
|
// vcs.cmd == 'git'
|
||||||
if !is_hg && outputs[1] != outputs[2] {
|
if !is_hg && outputs[1] != outputs[2] {
|
||||||
result.outdated = true
|
result.outdated = true
|
||||||
}
|
}
|
||||||
@ -229,8 +228,8 @@ fn ensure_vmodules_dir_exist() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_vcs_is_installed(vcs string) ! {
|
fn ensure_vcs_is_installed(vcs &VCS) ! {
|
||||||
cmd := '${vcs} ${supported_vcs_version_cmds[vcs]}'
|
cmd := '${vcs.cmd} --version'
|
||||||
verbose_println(' command: ${cmd}')
|
verbose_println(' command: ${cmd}')
|
||||||
res := os.execute(cmd)
|
res := os.execute(cmd)
|
||||||
if res.exit_code != 0 {
|
if res.exit_code != 0 {
|
||||||
@ -284,18 +283,13 @@ fn url_to_module_name(modulename string) string {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vcs_used_in_dir(dir string) ?[]string {
|
fn vcs_used_in_dir(dir string) ?VCS {
|
||||||
mut vcs := []string{}
|
for vcs in supported_vcs.values() {
|
||||||
for repo_subfolder in supported_vcs_folders {
|
if os.is_dir(os.real_path(os.join_path(dir, vcs.dir))) {
|
||||||
checked_folder := os.real_path(os.join_path(dir, repo_subfolder))
|
return vcs
|
||||||
if os.is_dir(checked_folder) {
|
|
||||||
vcs << repo_subfolder.replace('.', '')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if vcs.len == 0 {
|
return none
|
||||||
return none
|
|
||||||
}
|
|
||||||
return vcs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn valid_final_path_of_existing_module(modulename string) ?string {
|
fn valid_final_path_of_existing_module(modulename string) ?string {
|
||||||
|
@ -79,13 +79,13 @@ fn vpm_install(requested_modules []string, opts []string) {
|
|||||||
vpm_install_from_vpm(vpm_modules)
|
vpm_install_from_vpm(vpm_modules)
|
||||||
}
|
}
|
||||||
if external_modules.len > 0 {
|
if external_modules.len > 0 {
|
||||||
source := if '--hg' in opts { Source.hg } else { Source.git }
|
vcs := if '--hg' in opts { supported_vcs['hd'] } else { supported_vcs['git'] }
|
||||||
vpm_install_from_vcs(external_modules, source)
|
vpm_install_from_vcs(external_modules, vcs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_module(vcs string, name string, url string, final_module_path string) ! {
|
fn install_module(vcs &VCS, name string, url string, final_module_path string) ! {
|
||||||
cmd := '${vcs} ${supported_vcs_install_cmds[vcs]} "${url}" "${final_module_path}"'
|
cmd := '${vcs.cmd} ${vcs.install_arg} "${url}" "${final_module_path}"'
|
||||||
verbose_println(' command: ${cmd}')
|
verbose_println(' command: ${cmd}')
|
||||||
println('Installing module "${name}" from "${url}" to "${final_module_path}" ...')
|
println('Installing module "${name}" from "${url}" to "${final_module_path}" ...')
|
||||||
res := os.execute(cmd)
|
res := os.execute(cmd)
|
||||||
@ -105,14 +105,14 @@ fn vpm_install_from_vpm(module_names []string) {
|
|||||||
eprintln(err)
|
eprintln(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mut vcs := mod.vcs
|
vcs := if mod.vcs != '' {
|
||||||
if vcs == '' {
|
supported_vcs[mod.vcs] or {
|
||||||
vcs = supported_vcs_systems[0]
|
errors++
|
||||||
}
|
eprintln('Skipping module "${name}", since it uses an unsupported VCS {${mod.vcs}} .')
|
||||||
if vcs !in supported_vcs_systems {
|
continue
|
||||||
errors++
|
}
|
||||||
eprintln('Skipping module "${name}", since it uses an unsupported VCS {${vcs}} .')
|
} else {
|
||||||
continue
|
supported_vcs['git']
|
||||||
}
|
}
|
||||||
ensure_vcs_is_installed(vcs) or {
|
ensure_vcs_is_installed(vcs) or {
|
||||||
errors++
|
errors++
|
||||||
@ -140,8 +140,7 @@ fn vpm_install_from_vpm(module_names []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vpm_install_from_vcs(modules []string, vcs_key Source) {
|
fn vpm_install_from_vcs(modules []string, vcs &VCS) {
|
||||||
vcs := vcs_key.str()
|
|
||||||
mut errors := 0
|
mut errors := 0
|
||||||
for raw_url in modules {
|
for raw_url in modules {
|
||||||
url := urllib.parse(raw_url) or {
|
url := urllib.parse(raw_url) or {
|
||||||
|
@ -18,14 +18,14 @@ fn update_module(mut pp pool.PoolProcessor, idx int, wid int) &ModUpdateInfo {
|
|||||||
zname := url_to_module_name(result.name)
|
zname := url_to_module_name(result.name)
|
||||||
result.final_path = valid_final_path_of_existing_module(result.name) or { return result }
|
result.final_path = valid_final_path_of_existing_module(result.name) or { return result }
|
||||||
println('Updating module "${zname}" in "${result.final_path}" ...')
|
println('Updating module "${zname}" in "${result.final_path}" ...')
|
||||||
vcs := vcs_used_in_dir(result.final_path) or { return result }[0]
|
vcs := vcs_used_in_dir(result.final_path) or { return result }
|
||||||
ensure_vcs_is_installed(vcs) or {
|
ensure_vcs_is_installed(vcs) or {
|
||||||
result.has_err = true
|
result.has_err = true
|
||||||
eprintln(err)
|
eprintln(err)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
path_flag := if vcs == 'hg' { '-R' } else { '-C' }
|
path_flag := if vcs.cmd == 'hg' { '-R' } else { '-C' }
|
||||||
cmd := '${vcs} ${path_flag} "${result.final_path}" ${supported_vcs_update_cmds[vcs]}'
|
cmd := '${vcs.cmd} ${path_flag} "${result.final_path}" ${vcs.update_arg}'
|
||||||
verbose_println(' command: ${cmd}')
|
verbose_println(' command: ${cmd}')
|
||||||
res := os.execute('${cmd}')
|
res := os.execute('${cmd}')
|
||||||
if res.exit_code != 0 {
|
if res.exit_code != 0 {
|
||||||
@ -70,14 +70,14 @@ fn vpm_update_verbose(module_names []string) {
|
|||||||
zname := url_to_module_name(name)
|
zname := url_to_module_name(name)
|
||||||
final_module_path := valid_final_path_of_existing_module(name) or { continue }
|
final_module_path := valid_final_path_of_existing_module(name) or { continue }
|
||||||
println('Updating module "${zname}" in "${final_module_path}" ...')
|
println('Updating module "${zname}" in "${final_module_path}" ...')
|
||||||
vcs := vcs_used_in_dir(final_module_path) or { continue }[0]
|
vcs := vcs_used_in_dir(final_module_path) or { continue }
|
||||||
ensure_vcs_is_installed(vcs) or {
|
ensure_vcs_is_installed(vcs) or {
|
||||||
errors++
|
errors++
|
||||||
eprintln(err)
|
eprintln(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
path_flag := if vcs == 'hg' { '-R' } else { '-C' }
|
path_flag := if vcs.cmd == 'hg' { '-R' } else { '-C' }
|
||||||
cmd := '${vcs} ${path_flag} "${final_module_path}" ${supported_vcs_update_cmds[vcs]}'
|
cmd := '${vcs.cmd} ${path_flag} "${final_module_path}" ${vcs.update_arg}'
|
||||||
verbose_println(' command: ${cmd}')
|
verbose_println(' command: ${cmd}')
|
||||||
res := os.execute('${cmd}')
|
res := os.execute('${cmd}')
|
||||||
if res.exit_code != 0 {
|
if res.exit_code != 0 {
|
||||||
|
@ -17,36 +17,36 @@ mut:
|
|||||||
vmodules_path string
|
vmodules_path string
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Source {
|
struct VCS {
|
||||||
git
|
cmd string
|
||||||
hg
|
dir string
|
||||||
vpm
|
update_arg string
|
||||||
|
install_arg string
|
||||||
|
outdated_steps []string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
settings = &VpmSettings{}
|
settings = &VpmSettings{}
|
||||||
default_vpm_server_urls = ['https://vpm.vlang.io', 'https://vpm.url4e.com']
|
default_vpm_server_urls = ['https://vpm.vlang.io', 'https://vpm.url4e.com']
|
||||||
vpm_server_urls = rand.shuffle_clone(default_vpm_server_urls) or { [] } // ensure that all queries are distributed fairly
|
vpm_server_urls = rand.shuffle_clone(default_vpm_server_urls) or { [] } // ensure that all queries are distributed fairly
|
||||||
valid_vpm_commands = ['help', 'search', 'install', 'update', 'upgrade', 'outdated',
|
valid_vpm_commands = ['help', 'search', 'install', 'update', 'upgrade', 'outdated', 'list',
|
||||||
'list', 'remove', 'show']
|
'remove', 'show']
|
||||||
excluded_dirs = ['cache', 'vlib']
|
excluded_dirs = ['cache', 'vlib']
|
||||||
supported_vcs_systems = ['git', 'hg']
|
supported_vcs = {
|
||||||
supported_vcs_folders = ['.git', '.hg']
|
'git': VCS{
|
||||||
supported_vcs_update_cmds = {
|
cmd: 'git'
|
||||||
'git': 'pull --recurse-submodules' // pulling with `--depth=1` leads to conflicts, when the upstream is more than 1 commit newer
|
dir: '.git'
|
||||||
'hg': 'pull --update'
|
update_arg: 'pull --recurse-submodules' // pulling with `--depth=1` leads to conflicts, when the upstream is more than 1 commit newer
|
||||||
}
|
install_arg: 'clone --depth=1 --recursive --shallow-submodules'
|
||||||
supported_vcs_install_cmds = {
|
outdated_steps: ['fetch', 'rev-parse @', 'rev-parse @{u}']
|
||||||
'git': 'clone --depth=1 --recursive --shallow-submodules'
|
}
|
||||||
'hg': 'clone'
|
'hg': VCS{
|
||||||
}
|
cmd: 'hg'
|
||||||
supported_vcs_outdated_steps = {
|
dir: '.hg'
|
||||||
'git': ['fetch', 'rev-parse @', 'rev-parse @{u}']
|
update_arg: 'pull --update'
|
||||||
'hg': ['incoming']
|
install_arg: 'clone'
|
||||||
}
|
outdated_steps: ['incoming']
|
||||||
supported_vcs_version_cmds = {
|
}
|
||||||
'git': 'version'
|
|
||||||
'hg': 'version'
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user