1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builder: module caching fixes

This commit is contained in:
Alexander Medvednikov 2020-04-27 14:46:25 +02:00
parent f005079e0b
commit eb8973c362
4 changed files with 17 additions and 12 deletions

View File

@ -165,8 +165,8 @@ fn parse_args(args []string) (&pref.Preferences, string) {
'-showcc' {
res.show_cc = true
}
'-cache' {
res.is_cache = true
'-usecache' {
res.use_cache = true
}
'-keepc' {
res.keep_c = true

View File

@ -215,7 +215,7 @@ fn (mut v Builder) cc() {
mut libs := '' // builtin.o os.o http.o etc
if v.pref.build_mode == .build_module {
a << '-c'
} else if v.pref.is_cache {
} else if v.pref.use_cache {
/*
QTODO
builtin_o_path := os.join_path(pref.default_module_path, 'cache', 'vlib', 'builtin.o')
@ -305,13 +305,18 @@ fn (mut v Builder) cc() {
// add all flags (-I -l -L etc) not .o files
a << cflags.c_options_without_object_files()
a << libs
if v.pref.is_cache {
cached_files := [ 'builtin.o', 'math.o']
for cfile in cached_files {
ofile := os.join_path(pref.default_module_path, 'cache', 'vlib', cfile)
if os.exists(ofile) {
a << ofile
if v.pref.use_cache {
//vexe := pref.vexe_path()
cached_modules:= [ 'builtin', 'os' ]//, 'math']
for cfile in cached_modules{
ofile := os.join_path(pref.default_module_path, 'cache', 'vlib', cfile + '.o')
if !os.exists(ofile) {
println('${cfile}.o is missing. Building...')
println('$vexe build-module vlib/$cfile')
os.system('$vexe build-module vlib/$cfile')
}
a << ofile
}
if !is_cc_tcc {
$if linux {

View File

@ -71,7 +71,7 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
*/
//
g.fn_args(it.args, it.is_variadic)
if it.no_body || (g.pref.is_cache && it.is_builtin) {
if it.no_body || (g.pref.use_cache && it.is_builtin) {
// Just a function header.
// Builtin function bodies are defined in builtin.o
g.definitions.writeln(');')
@ -104,7 +104,7 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
}
// Profiling mode? Start counting at the beginning of the function (save current time).
if g.pref.is_prof {
g.profile_fn( it.name, is_main )
g.profile_fn(it.name, is_main)
}
g.stmts(it.stmts)
// ////////////

View File

@ -44,7 +44,7 @@ pub mut:
show_cc bool // -showcc, print cc command
// NB: passing -cg instead of -g will set is_vlines to false and is_g to true, thus making v generate cleaner C files,
// which are sometimes easier to debug / inspect manually than the .tmp.c files by plain -g (when/if v line number generation breaks).
is_cache bool // turns on v usage of the module cache to speed up compilation.
use_cache bool // turns on v usage of the module cache to speed up compilation.
is_stats bool // `v -stats file_test.v` will produce more detailed statistics for the tests that were run
no_auto_free bool // `v -nofree` disable automatic `free()` insertion for better performance in some applications (e.g. compilers)
// TODO Convert this into a []string