tools: fix `v install https://github.com/nedpals/vex.git` (fix #14483)
parent
29fc96c040
commit
16bcfa7da3
|
@ -208,24 +208,24 @@ fn vpm_install_from_vpm(module_names []string) {
|
||||||
println('VPM needs `$vcs` to be installed.')
|
println('VPM needs `$vcs` to be installed.')
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
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))
|
minfo := mod_name_info(mod.name)
|
||||||
if os.exists(final_module_path) {
|
if os.exists(minfo.final_module_path) {
|
||||||
vpm_update([name])
|
vpm_update([name])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
println('Installing module "$name" from "$mod.url" to "$final_module_path" ...')
|
println('Installing module "$name" from "$mod.url" to "$minfo.final_module_path" ...')
|
||||||
vcs_install_cmd := supported_vcs_install_cmds[vcs]
|
vcs_install_cmd := supported_vcs_install_cmds[vcs]
|
||||||
cmd := '$vcs_install_cmd "$mod.url" "$final_module_path"'
|
cmd := '$vcs_install_cmd "$mod.url" "$minfo.final_module_path"'
|
||||||
verbose_println(' command: $cmd')
|
verbose_println(' command: $cmd')
|
||||||
cmdres := os.execute(cmd)
|
cmdres := os.execute(cmd)
|
||||||
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 "$minfo.final_module_path" .')
|
||||||
print_failed_cmd(cmd, cmdres)
|
print_failed_cmd(cmd, cmdres)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resolve_dependencies(name, final_module_path, module_names)
|
resolve_dependencies(name, minfo.final_module_path, module_names)
|
||||||
}
|
}
|
||||||
if errors > 0 {
|
if errors > 0 {
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -270,7 +270,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
repo_name := url.substr(second_cut_pos + 1, first_cut_pos)
|
repo_name := url.substr(second_cut_pos + 1, first_cut_pos)
|
||||||
mut name := repo_name + os.path_separator + mod_name
|
mut name := os.join_path(repo_name, mod_name)
|
||||||
mod_name_as_path := name.replace('-', '_').to_lower()
|
mod_name_as_path := name.replace('-', '_').to_lower()
|
||||||
mut final_module_path := os.real_path(os.join_path(settings.vmodules_path, mod_name_as_path))
|
mut 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) {
|
||||||
|
@ -297,20 +297,19 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
|
||||||
if os.exists(vmod_path) {
|
if os.exists(vmod_path) {
|
||||||
data := os.read_file(vmod_path) or { return }
|
data := os.read_file(vmod_path) or { return }
|
||||||
vmod := parse_vmod(data)
|
vmod := parse_vmod(data)
|
||||||
mod_path := os.real_path(os.join_path(settings.vmodules_path, vmod.name.replace('.',
|
minfo := mod_name_info(vmod.name)
|
||||||
os.path_separator)))
|
println('Relocating module from "$name" to "$vmod.name" ( "$minfo.final_module_path" ) ...')
|
||||||
println('Relocating module from "$name" to "$vmod.name" ( "$mod_path" ) ...')
|
if os.exists(minfo.final_module_path) {
|
||||||
if os.exists(mod_path) {
|
println('Warning module "$minfo.final_module_path" already exsits!')
|
||||||
println('Warning module "$mod_path" already exsits!')
|
println('Removing module "$minfo.final_module_path" ...')
|
||||||
println('Removing module "$mod_path" ...')
|
os.rmdir_all(minfo.final_module_path) or {
|
||||||
os.rmdir_all(mod_path) or {
|
|
||||||
errors++
|
errors++
|
||||||
println('Errors while removing "$mod_path" :')
|
println('Errors while removing "$minfo.final_module_path" :')
|
||||||
println(err)
|
println(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os.mv(final_module_path, mod_path) or {
|
os.mv(final_module_path, minfo.final_module_path) or {
|
||||||
errors++
|
errors++
|
||||||
println('Errors while relocating module "$name" :')
|
println('Errors while relocating module "$name" :')
|
||||||
println(err)
|
println(err)
|
||||||
|
@ -323,7 +322,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
println('Module "$name" relocated to "$vmod.name" successfully.')
|
println('Module "$name" relocated to "$vmod.name" successfully.')
|
||||||
final_module_path = mod_path
|
final_module_path = minfo.final_module_path
|
||||||
name = vmod.name
|
name = vmod.name
|
||||||
}
|
}
|
||||||
resolve_dependencies(name, final_module_path, module_names)
|
resolve_dependencies(name, final_module_path, module_names)
|
||||||
|
@ -377,10 +376,7 @@ fn vpm_update(m []string) {
|
||||||
}
|
}
|
||||||
mut errors := 0
|
mut errors := 0
|
||||||
for modulename in module_names {
|
for modulename in module_names {
|
||||||
mut zname := modulename
|
zname := url_to_module_name( modulename )
|
||||||
if mod := get_mod_by_url(modulename) {
|
|
||||||
zname = mod.name
|
|
||||||
}
|
|
||||||
final_module_path := valid_final_path_of_existing_module(modulename) or { continue }
|
final_module_path := valid_final_path_of_existing_module(modulename) or { continue }
|
||||||
os.chdir(final_module_path) or {}
|
os.chdir(final_module_path) or {}
|
||||||
println('Updating module "$zname" in "$final_module_path" ...')
|
println('Updating module "$zname" in "$final_module_path" ...')
|
||||||
|
@ -503,26 +499,21 @@ fn vpm_remove(module_names []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn valid_final_path_of_existing_module(modulename string) ?string {
|
fn valid_final_path_of_existing_module(modulename string) ?string {
|
||||||
mut name := modulename
|
name := if mod := get_mod_by_url(modulename) { mod.name } else { modulename }
|
||||||
if mod := get_mod_by_url(name) {
|
minfo := mod_name_info(name)
|
||||||
name = mod.name
|
if !os.exists(minfo.final_module_path) {
|
||||||
}
|
println('No module with name "$minfo.mname_normalised" exists at $minfo.final_module_path')
|
||||||
mod_name_as_path := name.replace('.', os.path_separator).replace('-', '_').to_lower()
|
|
||||||
name_of_vmodules_folder := os.join_path(settings.vmodules_path, mod_name_as_path)
|
|
||||||
final_module_path := os.real_path(name_of_vmodules_folder)
|
|
||||||
if !os.exists(final_module_path) {
|
|
||||||
println('No module with name "$name" exists at $name_of_vmodules_folder')
|
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
if !os.is_dir(final_module_path) {
|
if !os.is_dir(minfo.final_module_path) {
|
||||||
println('Skipping "$name_of_vmodules_folder", since it is not a folder.')
|
println('Skipping "$minfo.final_module_path", since it is not a folder.')
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
vcs_used_in_dir(final_module_path) or {
|
vcs_used_in_dir(minfo.final_module_path) or {
|
||||||
println('Skipping "$name_of_vmodules_folder", since it does not use a supported vcs.')
|
println('Skipping "$minfo.final_module_path", since it does not use a supported vcs.')
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
return final_module_path
|
return minfo.final_module_path
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_vmodules_dir_exist() {
|
fn ensure_vmodules_dir_exist() {
|
||||||
|
@ -573,6 +564,31 @@ fn get_installed_modules() []string {
|
||||||
return modules
|
return modules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ModNameInfo {
|
||||||
|
mut:
|
||||||
|
mname string // The-user.The-mod , *never* The-user.The-mod.git
|
||||||
|
mname_normalised string // the_user.the_mod
|
||||||
|
mname_as_path string // the_user/the_mod
|
||||||
|
final_module_path string // ~/.vmodules/the_user/the_mod
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mod_name_info(mod_name string) ModNameInfo {
|
||||||
|
mut info := ModNameInfo{}
|
||||||
|
info.mname = if mod_name.ends_with('.git') { mod_name.replace('.git', '') } else { mod_name }
|
||||||
|
info.mname_normalised = info.mname.replace('-', '_').to_lower()
|
||||||
|
info.mname_as_path = info.mname_normalised.replace('.', os.path_separator)
|
||||||
|
info.final_module_path = os.real_path(os.join_path(settings.vmodules_path, info.mname_as_path))
|
||||||
|
return info
|
||||||
|
}
|
||||||
|
|
||||||
|
fn url_to_module_name( modulename string ) string {
|
||||||
|
mut res := if mod := get_mod_by_url(modulename) { mod.name } else { modulename }
|
||||||
|
if res.ends_with('.git') {
|
||||||
|
res = res.replace('.git', '')
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
fn get_all_modules() []string {
|
fn get_all_modules() []string {
|
||||||
url := get_working_server_url()
|
url := get_working_server_url()
|
||||||
r := http.get(url) or { panic(err) }
|
r := http.get(url) or { panic(err) }
|
||||||
|
|
Loading…
Reference in New Issue