mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.vcache, v.builder: use the module name inside the usecache paths (for more readable cache entries at a glance) (#15476)
This commit is contained in:
@@ -456,11 +456,12 @@ fn (mut v Builder) setup_output_name() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v.pref.build_mode == .build_module {
|
if v.pref.build_mode == .build_module {
|
||||||
v.pref.out_name = v.pref.cache_manager.postfix_with_key2cpath('.o', v.pref.path) // v.out_name
|
v.pref.out_name = v.pref.cache_manager.mod_postfix_with_key2cpath(v.pref.path,
|
||||||
|
'.o', v.pref.path) // v.out_name
|
||||||
if v.pref.is_verbose {
|
if v.pref.is_verbose {
|
||||||
println('Building $v.pref.path to $v.pref.out_name ...')
|
println('Building $v.pref.path to $v.pref.out_name ...')
|
||||||
}
|
}
|
||||||
v.pref.cache_manager.save('.description.txt', v.pref.path, '${v.pref.path:-30} @ $v.pref.cache_manager.vopts\n') or {
|
v.pref.cache_manager.mod_save(v.pref.path, '.description.txt', v.pref.path, '${v.pref.path:-30} @ $v.pref.cache_manager.vopts\n') or {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
// println('v.ast.imports:')
|
// println('v.ast.imports:')
|
||||||
@@ -889,19 +890,19 @@ fn (mut b Builder) build_thirdparty_obj_files() {
|
|||||||
rest_of_module_flags := b.get_rest_of_module_cflags(flag)
|
rest_of_module_flags := b.get_rest_of_module_cflags(flag)
|
||||||
$if windows {
|
$if windows {
|
||||||
if b.pref.ccompiler == 'msvc' {
|
if b.pref.ccompiler == 'msvc' {
|
||||||
b.build_thirdparty_obj_file_with_msvc(flag.value, rest_of_module_flags)
|
b.build_thirdparty_obj_file_with_msvc(flag.mod, flag.value, rest_of_module_flags)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
b.build_thirdparty_obj_file(flag.value, rest_of_module_flags)
|
b.build_thirdparty_obj_file(flag.mod, flag.value, rest_of_module_flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CFlag) {
|
fn (mut v Builder) build_thirdparty_obj_file(mod string, path string, moduleflags []cflag.CFlag) {
|
||||||
obj_path := os.real_path(path)
|
obj_path := os.real_path(path)
|
||||||
cfile := '${obj_path[..obj_path.len - 2]}.c'
|
cfile := '${obj_path[..obj_path.len - 2]}.c'
|
||||||
opath := v.pref.cache_manager.postfix_with_key2cpath('.o', obj_path)
|
opath := v.pref.cache_manager.mod_postfix_with_key2cpath(mod, '.o', obj_path)
|
||||||
mut rebuild_reason_message := '$obj_path not found, building it in $opath ...'
|
mut rebuild_reason_message := '$obj_path not found, building it in $opath ...'
|
||||||
if os.exists(opath) {
|
if os.exists(opath) {
|
||||||
if os.exists(cfile) && os.file_last_mod_unix(opath) < os.file_last_mod_unix(cfile) {
|
if os.exists(cfile) && os.file_last_mod_unix(opath) < os.file_last_mod_unix(cfile) {
|
||||||
@@ -943,7 +944,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF
|
|||||||
verror(res.output)
|
verror(res.output)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
v.pref.cache_manager.save('.description.txt', obj_path, '${obj_path:-30} @ $cmd\n') or {
|
v.pref.cache_manager.mod_save(mod, '.description.txt', obj_path, '${obj_path:-30} @ $cmd\n') or {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if res.output != '' {
|
if res.output != '' {
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ fn (mut v Builder) get_os_cflags() []cflag.CFlag {
|
|||||||
}
|
}
|
||||||
for mut flag in v.table.cflags {
|
for mut flag in v.table.cflags {
|
||||||
if flag.value.ends_with('.o') {
|
if flag.value.ends_with('.o') {
|
||||||
flag.cached = v.pref.cache_manager.postfix_with_key2cpath('.o', os.real_path(flag.value))
|
flag.cached = v.pref.cache_manager.mod_postfix_with_key2cpath(flag.mod, '.o',
|
||||||
|
os.real_path(flag.value))
|
||||||
}
|
}
|
||||||
if flag.os == '' || flag.os in ctimedefines {
|
if flag.os == '' || flag.os in ctimedefines {
|
||||||
flags << flag
|
flags << flag
|
||||||
|
|||||||
@@ -388,7 +388,7 @@ pub fn (mut v Builder) cc_msvc() {
|
|||||||
os.rm(out_name_obj) or {}
|
os.rm(out_name_obj) or {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut v Builder) build_thirdparty_obj_file_with_msvc(path string, moduleflags []cflag.CFlag) {
|
fn (mut v Builder) build_thirdparty_obj_file_with_msvc(mod string, path string, moduleflags []cflag.CFlag) {
|
||||||
msvc := v.cached_msvc
|
msvc := v.cached_msvc
|
||||||
if msvc.valid == false {
|
if msvc.valid == false {
|
||||||
verror('Cannot find MSVC on this OS')
|
verror('Cannot find MSVC on this OS')
|
||||||
|
|||||||
@@ -193,12 +193,12 @@ fn (mut b Builder) v_build_module(vexe string, imp_path string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (mut b Builder) rebuild_cached_module(vexe string, imp_path string) string {
|
fn (mut b Builder) rebuild_cached_module(vexe string, imp_path string) string {
|
||||||
res := b.pref.cache_manager.exists('.o', imp_path) or {
|
res := b.pref.cache_manager.mod_exists(imp_path, '.o', imp_path) or {
|
||||||
if b.pref.is_verbose {
|
if b.pref.is_verbose {
|
||||||
println('Cached $imp_path .o file not found... Building .o file for $imp_path')
|
println('Cached $imp_path .o file not found... Building .o file for $imp_path')
|
||||||
}
|
}
|
||||||
b.v_build_module(vexe, imp_path)
|
b.v_build_module(vexe, imp_path)
|
||||||
rebuilded_o := b.pref.cache_manager.exists('.o', imp_path) or {
|
rebuilded_o := b.pref.cache_manager.mod_exists(imp_path, '.o', imp_path) or {
|
||||||
panic('could not rebuild cache module for $imp_path, error: $err.msg()')
|
panic('could not rebuild cache module for $imp_path, error: $err.msg()')
|
||||||
}
|
}
|
||||||
return rebuilded_o
|
return rebuilded_o
|
||||||
|
|||||||
@@ -107,6 +107,16 @@ pub fn (mut cm CacheManager) postfix_with_key2cpath(postfix string, key string)
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn normalise_mod(mod string) string {
|
||||||
|
return mod.replace('/', '.').replace('\\', '.').replace('vlib.', '').trim('.')
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut cm CacheManager) mod_postfix_with_key2cpath(mod string, postfix string, key string) string {
|
||||||
|
prefix := cm.key2cpath(key)
|
||||||
|
res := '${prefix}.module.${normalise_mod(mod)}$postfix'
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
pub fn (mut cm CacheManager) exists(postfix string, key string) ?string {
|
pub fn (mut cm CacheManager) exists(postfix string, key string) ?string {
|
||||||
fpath := cm.postfix_with_key2cpath(postfix, key)
|
fpath := cm.postfix_with_key2cpath(postfix, key)
|
||||||
dlog(@FN, 'postfix: $postfix | key: $key | fpath: $fpath')
|
dlog(@FN, 'postfix: $postfix | key: $key | fpath: $fpath')
|
||||||
@@ -116,6 +126,17 @@ pub fn (mut cm CacheManager) exists(postfix string, key string) ?string {
|
|||||||
return fpath
|
return fpath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn (mut cm CacheManager) mod_exists(mod string, postfix string, key string) ?string {
|
||||||
|
fpath := cm.mod_postfix_with_key2cpath(mod, postfix, key)
|
||||||
|
dlog(@FN, 'mod: $mod | postfix: $postfix | key: $key | fpath: $fpath')
|
||||||
|
if !os.exists(fpath) {
|
||||||
|
return error('does not exist yet')
|
||||||
|
}
|
||||||
|
return fpath
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
pub fn (mut cm CacheManager) save(postfix string, key string, content string) ?string {
|
pub fn (mut cm CacheManager) save(postfix string, key string, content string) ?string {
|
||||||
fpath := cm.postfix_with_key2cpath(postfix, key)
|
fpath := cm.postfix_with_key2cpath(postfix, key)
|
||||||
os.write_file(fpath, content)?
|
os.write_file(fpath, content)?
|
||||||
@@ -123,6 +144,15 @@ pub fn (mut cm CacheManager) save(postfix string, key string, content string) ?s
|
|||||||
return fpath
|
return fpath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn (mut cm CacheManager) mod_save(mod string, postfix string, key string, content string) ?string {
|
||||||
|
fpath := cm.mod_postfix_with_key2cpath(mod, postfix, key)
|
||||||
|
os.write_file(fpath, content)?
|
||||||
|
dlog(@FN, 'mod: $mod | postfix: $postfix | key: $key | fpath: $fpath')
|
||||||
|
return fpath
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
pub fn (mut cm CacheManager) load(postfix string, key string) ?string {
|
pub fn (mut cm CacheManager) load(postfix string, key string) ?string {
|
||||||
fpath := cm.exists(postfix, key)?
|
fpath := cm.exists(postfix, key)?
|
||||||
content := os.read_file(fpath)?
|
content := os.read_file(fpath)?
|
||||||
@@ -130,6 +160,13 @@ pub fn (mut cm CacheManager) load(postfix string, key string) ?string {
|
|||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn (mut cm CacheManager) mod_load(mod string, postfix string, key string) ?string {
|
||||||
|
fpath := cm.mod_exists(mod, postfix, key)?
|
||||||
|
content := os.read_file(fpath)?
|
||||||
|
dlog(@FN, 'mod: $mod | postfix: $postfix | key: $key | fpath: $fpath')
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
[if trace_usecache ?]
|
[if trace_usecache ?]
|
||||||
pub fn dlog(fname string, s string) {
|
pub fn dlog(fname string, s string) {
|
||||||
xlog(fname, s)
|
xlog(fname, s)
|
||||||
|
|||||||
Reference in New Issue
Block a user