diff --git a/examples/hot_reload/message.v b/examples/hot_reload/message.v index 0539d0f7b2..2ef9c812c7 100644 --- a/examples/hot_reload/message.v +++ b/examples/hot_reload/message.v @@ -2,7 +2,7 @@ module main // Build this example with `v -live message.v` import time -import live +import v.live [live] fn print_message() { diff --git a/vlib/v/gen/live.v b/vlib/v/gen/live.v index 3be0d9feb9..fdbbd48c67 100644 --- a/vlib/v/gen/live.v +++ b/vlib/v/gen/live.v @@ -89,7 +89,7 @@ fn (mut g Gen) generate_hotcode_reloading_main_caller() { if g.pref.os == .windows { g.writeln('\t\tlive_fn_mutex = CreateMutexA(0, 0, 0);') } - g.writeln('\t\tlive__LiveReloadInfo* live_info = live__executable__new_live_reload_info(') + g.writeln('\t\tv__live__LiveReloadInfo* live_info = v__live__executable__new_live_reload_info(') g.writeln('\t\t\t\t\t tos2("$file"),') g.writeln('\t\t\t\t\t tos2("$vexe"),') g.writeln('\t\t\t\t\t tos2("$vopts"),') @@ -99,7 +99,7 @@ fn (mut g Gen) generate_hotcode_reloading_main_caller() { // g_live_info gives access to the LiveReloadInfo methods, // to the custom user code, through calling v_live_info() g.writeln('\t\t g_live_info = (void*)live_info;') - g.writeln('\t\tlive__executable__start_reloader(live_info);') + g.writeln('\t\tv__live__executable__start_reloader(live_info);') g.writeln('\t}\t// end of live code initialization section') g.writeln('') } diff --git a/vlib/live/common.v b/vlib/v/live/common.v similarity index 100% rename from vlib/live/common.v rename to vlib/v/live/common.v diff --git a/vlib/live/executable/reloader.v b/vlib/v/live/executable/reloader.v similarity index 98% rename from vlib/live/executable/reloader.v rename to vlib/v/live/executable/reloader.v index ffcab1faf4..be05797c6e 100644 --- a/vlib/live/executable/reloader.v +++ b/vlib/v/live/executable/reloader.v @@ -4,7 +4,7 @@ import os import time import dl import strconv -import live +import v.live pub const ( is_used = 1 @@ -50,9 +50,10 @@ pub fn start_reloader(mut r live.LiveReloadInfo) { go reloader(mut r) } -[if debuglive] fn elog(r &live.LiveReloadInfo, s string){ - eprintln(s) + $if debuglive ? { + eprintln(s) + } } fn compile_and_reload_shared_lib(mut r live.LiveReloadInfo) ?bool { diff --git a/vlib/v/tests/live_test.v b/vlib/v/live/live_test.v similarity index 81% rename from vlib/v/tests/live_test.v rename to vlib/v/live/live_test.v index 7f5dd69654..903c5fef61 100644 --- a/vlib/v/tests/live_test.v +++ b/vlib/v/live/live_test.v @@ -5,6 +5,7 @@ import time The goal of this test, is to simulate a developer, that has run a program, compiled with -live flag. It does so by writing a new generated program containing a [live] fn pmessage() string {...} function, +(that program is in `vlib/v/live/live_test_template.vv`) then runs the generated program at the start *in the background*, waits some time, so that the program could run a few iterations, then modifies its source (simulates a developer that has saved a new version of the program source), @@ -39,70 +40,15 @@ const ( res_stop_file = os.join_path(os.temp_dir(), 'STOP.txt') cleanup_files = [tmp_file, source_file, genexe_file, output_file, res_original_file, res_changed_file, res_another_file, res_stop_file] - live_program_source = " -module main - -import time -import os -import live - -fn append_to_file(fname string, s string) { - mut f := os.open_append(fname) or { - println('>>>> could not open file \$fname for appending, err: \$err ') - return - } - f.writeln('\$s') - //info := live.info() - //f.writeln('>>> reloads: \${info.reloads} | ok reloads: \${info.reloads_ok}') - f.close() -} - -fn myprintln(s string) { - append_to_file('$output_file', s) - println(s) - os.flush() -} - -[live] -fn pmessage() string { - return 'ORIGINAL' -} - -const ( - delay = 20 + live_program_source = get_source_template() ) -fn edefault(name string, default string) string { - res := os.getenv(name) - if res == '' { - return default - } - return res + +fn get_source_template() string { + src := os.read_file(os.join_path(os.dir(@FILE), 'live_test_template.vv')) or { + panic(err) + } + return src.replace('#OUTPUT_FILE#', output_file) } -fn main() { - mut info := live.info() - info.recheck_period_ms = 5 - myprintln('START') - myprintln('DATE: ' + time.now().str()) - pmessage() - pmessage() - max_cycles := edefault('LIVE_CYCLES', '1').int() - // NB: 1000 * 20 = maximum of ~20s runtime - for i:=0; i>>> could not open file $fname for appending, err: $err ') + return + } + f.writeln(s) + //info := live.info() + //f.writeln('>>> reloads: ${info.reloads} | ok reloads: ${info.reloads_ok}') + f.close() +} + +fn myprintln(s string) { + append_to_file('#OUTPUT_FILE#', s) + println(s) + os.flush() +} + +[live] +fn pmessage() string { + return 'ORIGINAL' +} + +const ( + delay = 20 +) +fn edefault(name string, default string) string { + res := os.getenv(name) + if res == '' { + return default + } + return res +} +fn main() { + mut info := live.info() + info.recheck_period_ms = 5 + myprintln('START') + myprintln('DATE: ' + time.now().str()) + pmessage() + pmessage() + max_cycles := edefault('LIVE_CYCLES', '1').int() + // NB: 1000 * 20 = maximum of ~20s runtime + for i:=0; i