live: move to vlib/v/live
parent
8571d9395b
commit
5c3ef588c3
|
@ -2,7 +2,7 @@ module main
|
||||||
|
|
||||||
// Build this example with `v -live message.v`
|
// Build this example with `v -live message.v`
|
||||||
import time
|
import time
|
||||||
import live
|
import v.live
|
||||||
|
|
||||||
[live]
|
[live]
|
||||||
fn print_message() {
|
fn print_message() {
|
||||||
|
|
|
@ -89,7 +89,7 @@ fn (mut g Gen) generate_hotcode_reloading_main_caller() {
|
||||||
if g.pref.os == .windows {
|
if g.pref.os == .windows {
|
||||||
g.writeln('\t\tlive_fn_mutex = CreateMutexA(0, 0, 0);')
|
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("$file"),')
|
||||||
g.writeln('\t\t\t\t\t tos2("$vexe"),')
|
g.writeln('\t\t\t\t\t tos2("$vexe"),')
|
||||||
g.writeln('\t\t\t\t\t tos2("$vopts"),')
|
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,
|
// g_live_info gives access to the LiveReloadInfo methods,
|
||||||
// to the custom user code, through calling v_live_info()
|
// to the custom user code, through calling v_live_info()
|
||||||
g.writeln('\t\t g_live_info = (void*)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('\t}\t// end of live code initialization section')
|
||||||
g.writeln('')
|
g.writeln('')
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import os
|
||||||
import time
|
import time
|
||||||
import dl
|
import dl
|
||||||
import strconv
|
import strconv
|
||||||
import live
|
import v.live
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
is_used = 1
|
is_used = 1
|
||||||
|
@ -50,10 +50,11 @@ pub fn start_reloader(mut r live.LiveReloadInfo) {
|
||||||
go reloader(mut r)
|
go reloader(mut r)
|
||||||
}
|
}
|
||||||
|
|
||||||
[if debuglive]
|
|
||||||
fn elog(r &live.LiveReloadInfo, s string){
|
fn elog(r &live.LiveReloadInfo, s string){
|
||||||
|
$if debuglive ? {
|
||||||
eprintln(s)
|
eprintln(s)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn compile_and_reload_shared_lib(mut r live.LiveReloadInfo) ?bool {
|
fn compile_and_reload_shared_lib(mut r live.LiveReloadInfo) ?bool {
|
||||||
sw := time.new_stopwatch({})
|
sw := time.new_stopwatch({})
|
|
@ -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.
|
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,
|
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*,
|
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
|
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),
|
(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')
|
res_stop_file = os.join_path(os.temp_dir(), 'STOP.txt')
|
||||||
cleanup_files = [tmp_file, source_file, genexe_file, output_file, res_original_file,
|
cleanup_files = [tmp_file, source_file, genexe_file, output_file, res_original_file,
|
||||||
res_changed_file, res_another_file, res_stop_file]
|
res_changed_file, res_another_file, res_stop_file]
|
||||||
live_program_source = "
|
live_program_source = get_source_template()
|
||||||
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
|
|
||||||
)
|
)
|
||||||
fn edefault(name string, default string) string {
|
|
||||||
res := os.getenv(name)
|
fn get_source_template() string {
|
||||||
if res == '' {
|
src := os.read_file(os.join_path(os.dir(@FILE), 'live_test_template.vv')) or {
|
||||||
return default
|
panic(err)
|
||||||
}
|
}
|
||||||
return res
|
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<max_cycles; i++ {
|
|
||||||
s := pmessage()
|
|
||||||
myprintln(s)
|
|
||||||
append_to_file(os.resource_abs_path(s + '.txt'), s)
|
|
||||||
if s == 'STOP' {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.sleep_ms(delay)
|
|
||||||
}
|
|
||||||
pmessage()
|
|
||||||
pmessage()
|
|
||||||
myprintln('DATE: ' + time.now().str())
|
|
||||||
myprintln('END')
|
|
||||||
}
|
|
||||||
"
|
|
||||||
)
|
|
||||||
|
|
||||||
fn edefault(name string, default string) string {
|
fn edefault(name string, default string) string {
|
||||||
res := os.getenv(name)
|
res := os.getenv(name)
|
||||||
|
@ -206,7 +152,7 @@ fn setup_cycles_environment() {
|
||||||
fn test_live_program_can_be_compiled() {
|
fn test_live_program_can_be_compiled() {
|
||||||
setup_cycles_environment()
|
setup_cycles_environment()
|
||||||
eprintln('Compiling...')
|
eprintln('Compiling...')
|
||||||
os.system('$vexe -live -o $genexe_file $source_file')
|
os.system('$vexe -nocolor -live -o $genexe_file $source_file')
|
||||||
//
|
//
|
||||||
cmd := '$genexe_file > /dev/null &'
|
cmd := '$genexe_file > /dev/null &'
|
||||||
eprintln('Running with: $cmd')
|
eprintln('Running with: $cmd')
|
||||||
|
@ -227,6 +173,8 @@ fn test_live_program_can_be_changed_2() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_live_program_can_be_changed_3() {
|
fn test_live_program_can_be_changed_3() {
|
||||||
|
change_source('STOP')
|
||||||
|
change_source('STOP')
|
||||||
change_source('STOP')
|
change_source('STOP')
|
||||||
assert true
|
assert true
|
||||||
}
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
module main
|
||||||
|
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import v.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
|
||||||
|
)
|
||||||
|
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<max_cycles; i++ {
|
||||||
|
s := pmessage()
|
||||||
|
myprintln(s)
|
||||||
|
append_to_file(os.resource_abs_path(s + '.txt'), s)
|
||||||
|
if s == 'STOP' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.sleep_ms(delay)
|
||||||
|
}
|
||||||
|
pmessage()
|
||||||
|
pmessage()
|
||||||
|
myprintln('DATE: ' + time.now().str())
|
||||||
|
myprintln('END')
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
module sharedlib
|
module sharedlib
|
||||||
|
|
||||||
import live
|
import v.live
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
is_used = live.is_used + 1
|
is_used = live.is_used + 1
|
|
@ -2,7 +2,7 @@ module main
|
||||||
|
|
||||||
// This prelude is loaded in every v program compiled with -live,
|
// This prelude is loaded in every v program compiled with -live,
|
||||||
// in both the main executable, and in the shared library.
|
// in both the main executable, and in the shared library.
|
||||||
import live
|
import v.live
|
||||||
|
|
||||||
const (
|
const (
|
||||||
no_warning_live_is_used = live.is_used
|
no_warning_live_is_used = live.is_used
|
||||||
|
|
|
@ -2,7 +2,7 @@ module main
|
||||||
|
|
||||||
// This prelude is loaded in every v program compiled with -live,
|
// This prelude is loaded in every v program compiled with -live,
|
||||||
// but only for the main executable.
|
// but only for the main executable.
|
||||||
import live.executable
|
import v.live.executable
|
||||||
|
|
||||||
const (
|
const (
|
||||||
no_warning_live_executable_is_used = executable.is_used
|
no_warning_live_executable_is_used = executable.is_used
|
||||||
|
|
|
@ -2,7 +2,7 @@ module main
|
||||||
|
|
||||||
// This prelude is loaded in every v program compiled with -live,
|
// This prelude is loaded in every v program compiled with -live,
|
||||||
// but only for the shared library.
|
// but only for the shared library.
|
||||||
import live.sharedlib
|
import v.live.sharedlib
|
||||||
|
|
||||||
const (
|
const (
|
||||||
no_warning_live_shared_is_used = sharedlib.is_used
|
no_warning_live_shared_is_used = sharedlib.is_used
|
||||||
|
|
Loading…
Reference in New Issue