tools: support `v watch -k run examples/gg/rectangles.v` (keep a program running)

master
Delyan Angelov 2022-06-15 18:00:02 +03:00
parent 0c1708db23
commit 205221074c
1 changed files with 6 additions and 0 deletions

View File

@ -89,6 +89,7 @@ mut:
v_cycles int // how many times the worker has restarted the V compiler v_cycles int // how many times the worker has restarted the V compiler
scan_cycles int // how many times the worker has scanned for source file changes scan_cycles int // how many times the worker has scanned for source file changes
clear_terminal bool // whether to clear the terminal before each re-run clear_terminal bool // whether to clear the terminal before each re-run
keep_running bool // when true, re-run the program automatically if it exits on its own. Useful for gg apps.
silent bool // when true, watch will not print a timestamp line before each re-run silent bool // when true, watch will not print a timestamp line before each re-run
add_files []string // path to additional files that have to be watched for changes add_files []string // path to additional files that have to be watched for changes
ignore_exts []string // extensions of files that will be ignored, even if they change (useful for sqlite.db files for example) ignore_exts []string // extensions of files that will be ignored, even if they change (useful for sqlite.db files for example)
@ -260,6 +261,9 @@ fn (mut context Context) compilation_runner_loop() {
if notalive_count == 1 { if notalive_count == 1 {
// a short lived process finished, do cleanup: // a short lived process finished, do cleanup:
context.run_after_cmd() context.run_after_cmd()
if context.keep_running {
break
}
} }
} }
select { select {
@ -282,6 +286,7 @@ fn (mut context Context) compilation_runner_loop() {
} }
} }
if !context.child_process.is_alive() { if !context.child_process.is_alive() {
context.elog('> child_process is no longer alive | notalive_count: $notalive_count')
context.child_process.wait() context.child_process.wait()
context.child_process.close() context.child_process.close()
if notalive_count == 0 { if notalive_count == 0 {
@ -317,6 +322,7 @@ fn main() {
context.is_worker = fp.bool('vwatchworker', 0, false, 'Internal flag. Used to distinguish vwatch manager and worker processes.') context.is_worker = fp.bool('vwatchworker', 0, false, 'Internal flag. Used to distinguish vwatch manager and worker processes.')
context.silent = fp.bool('silent', `s`, false, 'Be more silent; do not print the watch timestamp before each re-run.') context.silent = fp.bool('silent', `s`, false, 'Be more silent; do not print the watch timestamp before each re-run.')
context.clear_terminal = fp.bool('clear', `c`, false, 'Clears the terminal before each re-run.') context.clear_terminal = fp.bool('clear', `c`, false, 'Clears the terminal before each re-run.')
context.keep_running = fp.bool('keep', `k`, false, 'Keep the program running. Restart it automatically, if it exits by itself. Useful for gg/ui apps.')
context.add_files = fp.string('add', `a`, '', 'Add more files to be watched. Useful with `v watch -add=/tmp/feature.v run cmd/v /tmp/feature.v`, if you change *both* the compiler, and the feature.v file.').split(',') context.add_files = fp.string('add', `a`, '', 'Add more files to be watched. Useful with `v watch -add=/tmp/feature.v run cmd/v /tmp/feature.v`, if you change *both* the compiler, and the feature.v file.').split(',')
context.ignore_exts = fp.string('ignore', `i`, '', 'Ignore files having these extensions. Useful with `v watch -ignore=.db run server.v`, if your server writes to an sqlite.db file in the same folder.').split(',') context.ignore_exts = fp.string('ignore', `i`, '', 'Ignore files having these extensions. Useful with `v watch -ignore=.db run server.v`, if your server writes to an sqlite.db file in the same folder.').split(',')
show_help := fp.bool('help', `h`, false, 'Show this help screen.') show_help := fp.bool('help', `h`, false, 'Show this help screen.')