builder: a small -usecache fix, when v is run in subfolders

pull/6779/head
Delyan Angelov 2020-11-08 09:18:05 +02:00
parent 4b35495fbe
commit 6da8454b3b
1 changed files with 5 additions and 0 deletions

View File

@ -127,6 +127,10 @@ fn (mut v Builder) post_process_c_compiler_output(res os.Result) {
fn (mut v Builder) rebuild_cached_module(vexe string, imp_path string) string {
res := v.pref.cache_manager.exists('.o', imp_path) or {
println('Cached $imp_path .o file not found... Building .o file for $imp_path')
// do run `v build-module x` always in main vfolder; x can be a relative path
pwd := os.getwd()
vroot := os.dir(vexe)
os.chdir(vroot)
boptions := v.pref.build_options.join(' ')
rebuild_cmd := '$vexe $boptions build-module $imp_path'
// eprintln('>> rebuild_cmd: $rebuild_cmd')
@ -134,6 +138,7 @@ fn (mut v Builder) rebuild_cached_module(vexe string, imp_path string) string {
rebuilded_o := v.pref.cache_manager.exists('.o', imp_path) or {
panic('could not rebuild cache module for $imp_path, error: $err')
}
os.chdir(pwd)
return rebuilded_o
}
return res