From eb8973c36293e1eaea7a258104afe25189ae3c21 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 27 Apr 2020 14:46:25 +0200 Subject: [PATCH] builder: module caching fixes --- cmd/v/v.v | 4 ++-- vlib/v/builder/cc.v | 19 ++++++++++++------- vlib/v/gen/fn.v | 4 ++-- vlib/v/pref/pref.v | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cmd/v/v.v b/cmd/v/v.v index 6799a3202d..8d99096370 100644 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -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 diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index a38c5f3e8f..e5a53d8243 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -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 { diff --git a/vlib/v/gen/fn.v b/vlib/v/gen/fn.v index 7ab6d5bdff..61e5400fec 100644 --- a/vlib/v/gen/fn.v +++ b/vlib/v/gen/fn.v @@ -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) // //////////// diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index c82b3a9636..9463c05ce6 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -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