mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tools: make v watch webserver.v
monitor files used through $tmpl as well
This commit is contained in:
parent
7334f673a0
commit
dce65c7f46
@ -112,8 +112,8 @@ fn (mut context Context) get_stats_for_affected_vfiles() []VFileStat {
|
||||
// The next command will make V parse the program, and print all .v files,
|
||||
// needed for its compilation, without actually compiling it.
|
||||
copts := context.opts.join(' ')
|
||||
cmd := '"${context.vexe}" -silent -print-v-files ${copts}'
|
||||
// context.elog('> cmd: $cmd')
|
||||
cmd := '"${context.vexe}" -silent -print-watched-files ${copts}'
|
||||
// context.elog('> cmd: ${cmd}')
|
||||
mut paths := []string{}
|
||||
if context.add_files.len > 0 && context.add_files[0] != '' {
|
||||
paths << context.add_files
|
||||
@ -121,7 +121,11 @@ fn (mut context Context) get_stats_for_affected_vfiles() []VFileStat {
|
||||
vfiles := os.execute(cmd)
|
||||
if vfiles.exit_code == 0 {
|
||||
paths_trimmed := vfiles.output.trim_space()
|
||||
paths << paths_trimmed.split('\n')
|
||||
reported_used_files := paths_trimmed.split('\n')
|
||||
$if trace_reported_used_files ? {
|
||||
context.elog('reported_used_files: ${reported_used_files}')
|
||||
}
|
||||
paths << reported_used_files
|
||||
}
|
||||
for vf in paths {
|
||||
apaths[os.real_path(os.dir(vf))] = true
|
||||
|
@ -771,6 +771,7 @@ pub mut:
|
||||
notices []errors.Notice // all the checker notices in the file
|
||||
generic_fns []&FnDecl
|
||||
global_labels []string // from `asm { .globl labelname }`
|
||||
template_paths []string // all the .html/.md files that were processed with $tmpl
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
|
@ -243,6 +243,15 @@ pub fn (mut b Builder) parse_imports() {
|
||||
}
|
||||
exit(0)
|
||||
}
|
||||
if b.pref.print_watched_files {
|
||||
for p in b.parsed_files {
|
||||
println(p.path)
|
||||
for tp in p.template_paths {
|
||||
println(tp)
|
||||
}
|
||||
}
|
||||
exit(0)
|
||||
}
|
||||
if b.pref.dump_files != '' {
|
||||
b.dump_files(b.parsed_files.map(it.path))
|
||||
}
|
||||
|
@ -98,11 +98,12 @@ mut:
|
||||
script_mode bool
|
||||
script_mode_start_token token.Token
|
||||
pub mut:
|
||||
scanner &scanner.Scanner = unsafe { nil }
|
||||
errors []errors.Error
|
||||
warnings []errors.Warning
|
||||
notices []errors.Notice
|
||||
vet_errors []vet.Error
|
||||
scanner &scanner.Scanner = unsafe { nil }
|
||||
errors []errors.Error
|
||||
warnings []errors.Warning
|
||||
notices []errors.Notice
|
||||
vet_errors []vet.Error
|
||||
template_paths []string // record all compiled $tmpl files; needed for `v watch run webserver.v`
|
||||
}
|
||||
|
||||
__global codegen_files = unsafe { []&ast.File{} }
|
||||
@ -372,6 +373,7 @@ pub fn (mut p Parser) parse() &ast.File {
|
||||
warnings: warnings
|
||||
notices: notices
|
||||
global_labels: p.global_labels
|
||||
template_paths: p.template_paths
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,7 @@ pub fn (mut p Parser) compile_template_file(template_file string, fn_name string
|
||||
p.error('reading from ${template_file} failed')
|
||||
return ''
|
||||
}
|
||||
p.template_paths << template_file
|
||||
basepath := os.dir(template_file)
|
||||
lstartlength := lines.len * 30
|
||||
tmpl_str_start := "\tsb_${fn_name}.write_string('"
|
||||
@ -195,6 +196,7 @@ fn vweb_tmpl_${fn_name}() string {
|
||||
})
|
||||
''
|
||||
}
|
||||
p.template_paths << file_path
|
||||
file_splitted := file_content.split_into_lines().reverse()
|
||||
for f in file_splitted {
|
||||
tline_number--
|
||||
|
@ -193,17 +193,20 @@ pub mut:
|
||||
compile_defines []string // just ['vfmt']
|
||||
compile_defines_all []string // contains both: ['vfmt','another']
|
||||
//
|
||||
run_args []string // `v run x.v 1 2 3` => `1 2 3`
|
||||
printfn_list []string // a list of generated function names, whose source should be shown, for debugging
|
||||
print_v_files bool // when true, just print the list of all parsed .v files then stop.
|
||||
skip_running bool // when true, do no try to run the produced file (set by b.cc(), when -o x.c or -o x.js)
|
||||
skip_warnings bool // like C's "-w", forces warnings to be ignored.
|
||||
warn_impure_v bool // -Wimpure-v, force a warning for JS.fn()/C.fn(), outside of .js.v/.c.v files. TODO: turn to an error by default
|
||||
warns_are_errors bool // -W, like C's "-Werror", treat *every* warning is an error
|
||||
fatal_errors bool // unconditionally exit after the first error with exit(1)
|
||||
reuse_tmpc bool // do not use random names for .tmp.c and .tmp.c.rsp files, and do not remove them
|
||||
no_rsp bool // when true, pass C backend options directly on the CLI (do not use `.rsp` files for them, some older C compilers do not support them)
|
||||
no_std bool // when true, do not pass -std=gnu99(linux)/-std=c99 to the C backend
|
||||
run_args []string // `v run x.v 1 2 3` => `1 2 3`
|
||||
printfn_list []string // a list of generated function names, whose source should be shown, for debugging
|
||||
//
|
||||
print_v_files bool // when true, just print the list of all parsed .v files then stop.
|
||||
print_watched_files bool // when true, just print the list of all parsed .v files + all the compiled $tmpl files, then stop. Used by `v watch run webserver.v`
|
||||
//
|
||||
skip_running bool // when true, do no try to run the produced file (set by b.cc(), when -o x.c or -o x.js)
|
||||
skip_warnings bool // like C's "-w", forces warnings to be ignored.
|
||||
warn_impure_v bool // -Wimpure-v, force a warning for JS.fn()/C.fn(), outside of .js.v/.c.v files. TODO: turn to an error by default
|
||||
warns_are_errors bool // -W, like C's "-Werror", treat *every* warning is an error
|
||||
fatal_errors bool // unconditionally exit after the first error with exit(1)
|
||||
reuse_tmpc bool // do not use random names for .tmp.c and .tmp.c.rsp files, and do not remove them
|
||||
no_rsp bool // when true, pass C backend options directly on the CLI (do not use `.rsp` files for them, some older C compilers do not support them)
|
||||
no_std bool // when true, do not pass -std=gnu99(linux)/-std=c99 to the C backend
|
||||
//
|
||||
no_parallel bool // do not use threads when compiling; slower, but more portable and sometimes less buggy
|
||||
parallel_cc bool // whether to split the resulting .c file into many .c files + a common .h file, that are then compiled in parallel, then linked together.
|
||||
@ -662,6 +665,9 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||
'-print-v-files' {
|
||||
res.print_v_files = true
|
||||
}
|
||||
'-print-watched-files' {
|
||||
res.print_watched_files = true
|
||||
}
|
||||
'-os' {
|
||||
target_os := cmdline.option(current_args, '-os', '')
|
||||
i++
|
||||
|
Loading…
Reference in New Issue
Block a user