Skip to content

Commit d0bb810

Browse files
committed
vpm: fix v install GIT_REPO_URL
1 parent 5756359 commit d0bb810

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

cmd/tools/vpm.v

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ fn vpm_search(keywords []string) {
140140
joined := search_keys.join(', ')
141141
mut index := 0
142142
for mod in modules {
143-
// TODO for some reason .filter results in substr error, so do it manually
144143
for k in search_keys {
145144
if !mod.contains(k) {
146145
continue
@@ -209,7 +208,7 @@ fn vpm_install_from_vpm(module_names []string) {
209208
vpm_update([name])
210209
continue
211210
}
212-
println('Installing module "$name" from $mod.url to $final_module_path ...')
211+
println('Installing module "$name" from "$mod.url" to "$final_module_path" ...')
213212
vcs_install_cmd := supported_vcs_install_cmds[vcs]
214213
cmd := '$vcs_install_cmd "$mod.url" "$final_module_path"'
215214
verbose_println(' command: $cmd')
@@ -250,7 +249,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
250249

251250
first_cut_pos := url.last_index('/') or {
252251
errors++
253-
println('Errors while retrieving name for module $url:')
252+
println('Errors while retrieving name for module "$url" :')
254253
println(err)
255254
continue
256255
}
@@ -259,7 +258,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
259258

260259
second_cut_pos := url.substr(0, first_cut_pos).last_index('/') or {
261260
errors++
262-
println('Errors while retrieving name for module $url:')
261+
println('Errors while retrieving name for module "$url" :')
263262
println(err)
264263
continue
265264
}
@@ -277,7 +276,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
277276
println('VPM needs `$vcs_key` to be installed.')
278277
continue
279278
}
280-
println('Installing module "$name" from $url to $final_module_path ...')
279+
println('Installing module "$name" from "$url" to "$final_module_path" ...')
281280
vcs_install_cmd := supported_vcs_install_cmds[vcs_key]
282281
cmd := '$vcs_install_cmd "$url" "$final_module_path"'
283282
verbose_println(' command: $cmd')
@@ -294,7 +293,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
294293
vmod := parse_vmod(data)
295294
mod_path := os.real_path(os.join_path(settings.vmodules_path, vmod.name.replace('.',
296295
os.path_separator)))
297-
println('Relocating module from "$name" to "$vmod.name" ( $mod_path ) ...')
296+
println('Relocating module from "$name" to "$vmod.name" ( "$mod_path" ) ...')
298297
if os.exists(mod_path) {
299298
println('Warning module "$mod_path" already exsits!')
300299
println('Removing module "$mod_path" ...')
@@ -359,11 +358,14 @@ fn vpm_update(m []string) {
359358
module_names = get_installed_modules()
360359
}
361360
mut errors := 0
362-
for name in module_names {
363-
final_module_path := valid_final_path_of_existing_module(name) or { continue }
361+
for modulename in module_names {
362+
mut zname := modulename
363+
if mod := get_mod_by_url(modulename) {
364+
zname = mod.name
365+
}
366+
final_module_path := valid_final_path_of_existing_module(modulename) or { continue }
364367
os.chdir(final_module_path) or {}
365-
println('Updating module "$name"...')
366-
verbose_println(' work folder: $final_module_path')
368+
println('Updating module "$zname" in "$final_module_path" ...')
367369
vcs := vcs_used_in_dir(final_module_path) or { continue }
368370
if !ensure_vcs_is_installed(vcs[0]) {
369371
errors++
@@ -375,13 +377,13 @@ fn vpm_update(m []string) {
375377
vcs_res := os.execute('$vcs_cmd')
376378
if vcs_res.exit_code != 0 {
377379
errors++
378-
println('Failed updating module "$name".')
380+
println('Failed updating module "$zname" in "$final_module_path" .')
379381
print_failed_cmd(vcs_cmd, vcs_res)
380382
continue
381383
} else {
382384
verbose_println(' $vcs_res.output.trim_space()')
383385
}
384-
resolve_dependencies(name, final_module_path, module_names)
386+
resolve_dependencies(modulename, final_module_path, module_names)
385387
}
386388
if errors > 0 {
387389
exit(1)
@@ -402,7 +404,7 @@ fn get_outdated() ?[]string {
402404
if res.exit_code < 0 {
403405
verbose_println('Error command: $step')
404406
verbose_println('Error details:\n$res.output')
405-
return error('Error while checking latest commits for "$name".')
407+
return error('Error while checking latest commits for "$name" .')
406408
}
407409
if vcs[0] == 'hg' {
408410
if res.exit_code == 1 {
@@ -463,7 +465,7 @@ fn vpm_remove(module_names []string) {
463465
}
464466
for name in module_names {
465467
final_module_path := valid_final_path_of_existing_module(name) or { continue }
466-
println('Removing module "$name"...')
468+
println('Removing module "$name" ...')
467469
verbose_println('removing folder $final_module_path')
468470
os.rmdir_all(final_module_path) or {
469471
verbose_println('error while removing "$final_module_path": $err.msg')
@@ -483,7 +485,11 @@ fn vpm_remove(module_names []string) {
483485
}
484486
}
485487

486-
fn valid_final_path_of_existing_module(name string) ?string {
488+
fn valid_final_path_of_existing_module(modulename string) ?string {
489+
mut name := modulename
490+
if mod := get_mod_by_url(name) {
491+
name = mod.name
492+
}
487493
mod_name_as_path := name.replace('.', os.path_separator).replace('-', '_').to_lower()
488494
name_of_vmodules_folder := os.join_path(settings.vmodules_path, mod_name_as_path)
489495
final_module_path := os.real_path(name_of_vmodules_folder)
@@ -504,7 +510,7 @@ fn valid_final_path_of_existing_module(name string) ?string {
504510

505511
fn ensure_vmodules_dir_exist() {
506512
if !os.is_dir(settings.vmodules_path) {
507-
println('Creating $settings.vmodules_path/ ...')
513+
println('Creating "$settings.vmodules_path/" ...')
508514
os.mkdir(settings.vmodules_path) or { panic(err) }
509515
}
510516
}
@@ -601,7 +607,7 @@ fn resolve_dependencies(name string, module_path string, module_names []string)
601607
}
602608
}
603609
if deps.len > 0 {
604-
println('Resolving $deps.len dependencies for module "$name"...')
610+
println('Resolving $deps.len dependencies for module "$name" ...')
605611
verbose_println('Found dependencies: $deps')
606612
vpm_install(deps, Source.vpm)
607613
}
@@ -663,39 +669,44 @@ fn verbose_println(s string) {
663669
}
664670
}
665671

666-
fn get_module_meta_info(name string) ?Mod {
667-
mut errors := []string{}
668-
672+
fn get_mod_by_url(name string) ?Mod {
669673
if purl := urllib.parse(name) {
670674
verbose_println('purl: $purl')
671675
mod := Mod{
672-
name: purl.path.trim_left('/').trim_right('/')
676+
name: purl.path.trim_left('/').trim_right('/').replace('/', '.')
673677
url: name
674678
}
675679
verbose_println(mod.str())
676680
return mod
677681
}
682+
return error('invalid url: $name')
683+
}
678684

685+
fn get_module_meta_info(name string) ?Mod {
686+
if mod := get_mod_by_url(name) {
687+
return mod
688+
}
689+
mut errors := []string{}
679690
for server_url in default_vpm_server_urls {
680691
modurl := server_url + '/jsmod/$name'
681-
verbose_println('Retrieving module metadata from: $modurl ...')
692+
verbose_println('Retrieving module metadata from: "$modurl" ...')
682693
r := http.get(modurl) or {
683-
errors << 'Http server did not respond to our request for ${modurl}.'
694+
errors << 'Http server did not respond to our request for "${modurl}" .'
684695
errors << 'Error details: $err'
685696
continue
686697
}
687698
if r.status_code == 404 || r.text.trim_space() == '404' {
688-
errors << 'Skipping module "$name", since $server_url reported that "$name" does not exist.'
699+
errors << 'Skipping module "$name", since "$server_url" reported that "$name" does not exist.'
689700
continue
690701
}
691702
if r.status_code != 200 {
692-
errors << 'Skipping module "$name", since $server_url responded with $r.status_code http status code. Please try again later.'
703+
errors << 'Skipping module "$name", since "$server_url" responded with $r.status_code http status code. Please try again later.'
693704
continue
694705
}
695706
s := r.text
696707
if s.len > 0 && s[0] != `{` {
697708
errors << 'Invalid json data'
698-
errors << s.trim_space().limit(100) + '...'
709+
errors << s.trim_space().limit(100) + ' ...'
699710
continue
700711
}
701712
mod := json.decode(Mod, s) or {

0 commit comments

Comments
 (0)