tools: ensure `git` is installed, when doing vpm operations that require it

pull/13010/head
Delyan Angelov 2022-01-01 15:40:19 +02:00
parent 908296cdfb
commit 697eca5ddf
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 38 additions and 7 deletions

View File

@ -29,6 +29,10 @@ const (
'git': ['git fetch', 'git rev-parse @', 'git rev-parse @{u}'] 'git': ['git fetch', 'git rev-parse @', 'git rev-parse @{u}']
'hg': ['hg incoming'] 'hg': ['hg incoming']
} }
supported_vcs_version_cmds = {
'git': 'git version'
'hg': 'hg version'
}
) )
struct Mod { struct Mod {
@ -193,7 +197,11 @@ fn vpm_install_from_vpm(module_names []string) {
println('Skipping module "$name", since it uses an unsupported VCS {$vcs} .') println('Skipping module "$name", since it uses an unsupported VCS {$vcs} .')
continue continue
} }
if !ensure_vcs_is_installed(vcs) {
errors++
println('VPM needs `$vcs` to be installed.')
continue
}
mod_name_as_path := mod.name.replace('.', os.path_separator).replace('-', '_').to_lower() mod_name_as_path := mod.name.replace('.', os.path_separator).replace('-', '_').to_lower()
final_module_path := os.real_path(os.join_path(settings.vmodules_path, mod_name_as_path)) final_module_path := os.real_path(os.join_path(settings.vmodules_path, mod_name_as_path))
if os.exists(final_module_path) { if os.exists(final_module_path) {
@ -208,8 +216,7 @@ fn vpm_install_from_vpm(module_names []string) {
if cmdres.exit_code != 0 { if cmdres.exit_code != 0 {
errors++ errors++
println('Failed installing module "$name" to "$final_module_path" .') println('Failed installing module "$name" to "$final_module_path" .')
verbose_println('Failed command: $cmd') print_failed_cmd(cmd, cmdres)
verbose_println('Failed command output:\n$cmdres.output')
continue continue
} }
resolve_dependencies(name, final_module_path, module_names) resolve_dependencies(name, final_module_path, module_names)
@ -219,6 +226,22 @@ fn vpm_install_from_vpm(module_names []string) {
} }
} }
fn print_failed_cmd(cmd string, cmdres os.Result) {
verbose_println('Failed command: $cmd')
verbose_println('Failed command output:\n$cmdres.output')
}
fn ensure_vcs_is_installed(vcs string) bool {
mut res := true
cmd := supported_vcs_version_cmds[vcs]
cmdres := os.execute(cmd)
if cmdres.exit_code != 0 {
print_failed_cmd(cmd, cmdres)
res = false
}
return res
}
fn vpm_install_from_vcs(module_names []string, vcs_key string) { fn vpm_install_from_vcs(module_names []string, vcs_key string) {
mut errors := 0 mut errors := 0
for n in module_names { for n in module_names {
@ -248,6 +271,11 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
vpm_update([name.replace('-', '_')]) vpm_update([name.replace('-', '_')])
continue continue
} }
if !ensure_vcs_is_installed(vcs_key) {
errors++
println('VPM needs `$vcs_key` to be installed.')
continue
}
println('Installing module "$name" from $url to $final_module_path ...') println('Installing module "$name" from $url to $final_module_path ...')
vcs_install_cmd := supported_vcs_install_cmds[vcs_key] vcs_install_cmd := supported_vcs_install_cmds[vcs_key]
cmd := '$vcs_install_cmd "$url" "$final_module_path"' cmd := '$vcs_install_cmd "$url" "$final_module_path"'
@ -256,8 +284,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
if cmdres.exit_code != 0 { if cmdres.exit_code != 0 {
errors++ errors++
println('Failed installing module "$name" to "$final_module_path" .') println('Failed installing module "$name" to "$final_module_path" .')
verbose_println('Failed command: $cmd') print_failed_cmd(cmd, cmdres)
verbose_println('Failed command output:\n$cmdres.output')
continue continue
} }
vmod_path := os.join_path(final_module_path, 'v.mod') vmod_path := os.join_path(final_module_path, 'v.mod')
@ -337,14 +364,18 @@ fn vpm_update(m []string) {
println('Updating module "$name"...') println('Updating module "$name"...')
verbose_println(' work folder: $final_module_path') verbose_println(' work folder: $final_module_path')
vcs := vcs_used_in_dir(final_module_path) or { continue } vcs := vcs_used_in_dir(final_module_path) or { continue }
if !ensure_vcs_is_installed(vcs[0]) {
errors++
println('VPM needs `$vcs` to be installed.')
continue
}
vcs_cmd := supported_vcs_update_cmds[vcs[0]] vcs_cmd := supported_vcs_update_cmds[vcs[0]]
verbose_println(' command: $vcs_cmd') verbose_println(' command: $vcs_cmd')
vcs_res := os.execute('$vcs_cmd') vcs_res := os.execute('$vcs_cmd')
if vcs_res.exit_code != 0 { if vcs_res.exit_code != 0 {
errors++ errors++
println('Failed updating module "$name".') println('Failed updating module "$name".')
verbose_println('Failed command: $vcs_cmd') print_failed_cmd(vcs_cmd, vcs_res)
verbose_println('Failed details:\n$vcs_res.output')
continue continue
} else { } else {
verbose_println(' $vcs_res.output.trim_space()') verbose_println(' $vcs_res.output.trim_space()')