mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vfmt: add a comment about the role of the .is_worker field
This commit is contained in:
parent
aac8520838
commit
7bf46c36bb
@ -24,8 +24,7 @@ struct FormatOptions {
|
|||||||
is_debug bool
|
is_debug bool
|
||||||
is_noerror bool
|
is_noerror bool
|
||||||
is_verify bool // exit(1) if the file is not vfmt'ed
|
is_verify bool // exit(1) if the file is not vfmt'ed
|
||||||
mut:
|
is_worker bool // true *only* in the worker processes. NB: workers can crash.
|
||||||
is_worker bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -137,11 +136,7 @@ fn main() {
|
|||||||
wresult := worker_result.output.split(formatted_file_token)
|
wresult := worker_result.output.split(formatted_file_token)
|
||||||
formatted_warn_errs := wresult[0]
|
formatted_warn_errs := wresult[0]
|
||||||
formatted_file_path := wresult[1].trim_right('\n\r')
|
formatted_file_path := wresult[1].trim_right('\n\r')
|
||||||
foptions.is_worker = true
|
foptions.post_process_file(fpath, formatted_file_path) or { errors = errors + 1 }
|
||||||
foptions.post_process_file(fpath, formatted_file_path) or {
|
|
||||||
errors = errors + 1
|
|
||||||
}
|
|
||||||
foptions.is_worker = false
|
|
||||||
if formatted_warn_errs.len > 0 {
|
if formatted_warn_errs.len > 0 {
|
||||||
eprintln(formatted_warn_errs)
|
eprintln(formatted_warn_errs)
|
||||||
}
|
}
|
||||||
@ -251,9 +246,7 @@ fn (foptions &FormatOptions) post_process_file(file string, formatted_file_path
|
|||||||
}
|
}
|
||||||
if foptions.is_w {
|
if foptions.is_w {
|
||||||
if is_formatted_different {
|
if is_formatted_different {
|
||||||
os.mv_by_cp(formatted_file_path, file) or {
|
os.mv_by_cp(formatted_file_path, file) or { panic(err) }
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
eprintln('Reformatted file: $file')
|
eprintln('Reformatted file: $file')
|
||||||
} else {
|
} else {
|
||||||
eprintln('Already formatted file: $file')
|
eprintln('Already formatted file: $file')
|
||||||
@ -283,9 +276,7 @@ fn file_to_target_os(file string) string {
|
|||||||
fn file_to_mod_name_and_is_module_file(file string) (string, bool) {
|
fn file_to_mod_name_and_is_module_file(file string) (string, bool) {
|
||||||
mut mod_name := 'main'
|
mut mod_name := 'main'
|
||||||
mut is_module_file := false
|
mut is_module_file := false
|
||||||
flines := read_source_lines(file) or {
|
flines := read_source_lines(file) or { return mod_name, is_module_file }
|
||||||
return mod_name, is_module_file
|
|
||||||
}
|
|
||||||
for fline in flines {
|
for fline in flines {
|
||||||
line := fline.trim_space()
|
line := fline.trim_space()
|
||||||
if line.starts_with('module ') {
|
if line.starts_with('module ') {
|
||||||
@ -300,9 +291,7 @@ fn file_to_mod_name_and_is_module_file(file string) (string, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_source_lines(file string) ?[]string {
|
fn read_source_lines(file string) ?[]string {
|
||||||
source_lines := os.read_lines(file) or {
|
source_lines := os.read_lines(file) or { return error('can not read $file') }
|
||||||
return error('can not read $file')
|
|
||||||
}
|
|
||||||
return source_lines
|
return source_lines
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,9 +302,7 @@ fn get_compile_name_of_potential_v_project(file string) string {
|
|||||||
pfolder := os.real_path(os.dir(file))
|
pfolder := os.real_path(os.dir(file))
|
||||||
// a .v project has many 'module main' files in one folder
|
// a .v project has many 'module main' files in one folder
|
||||||
// if there is only one .v file, then it must be a standalone
|
// if there is only one .v file, then it must be a standalone
|
||||||
all_files_in_pfolder := os.ls(pfolder) or {
|
all_files_in_pfolder := os.ls(pfolder) or { panic(err) }
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
mut vfiles := []string{}
|
mut vfiles := []string{}
|
||||||
for f in all_files_in_pfolder {
|
for f in all_files_in_pfolder {
|
||||||
vf := os.join_path(pfolder, f)
|
vf := os.join_path(pfolder, f)
|
||||||
@ -335,9 +322,7 @@ fn get_compile_name_of_potential_v_project(file string) string {
|
|||||||
// a project folder, that should be compiled with `v pfolder`.
|
// a project folder, that should be compiled with `v pfolder`.
|
||||||
mut main_fns := 0
|
mut main_fns := 0
|
||||||
for f in vfiles {
|
for f in vfiles {
|
||||||
slines := read_source_lines(f) or {
|
slines := read_source_lines(f) or { panic(err) }
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
for line in slines {
|
for line in slines {
|
||||||
if line.contains('fn main()') {
|
if line.contains('fn main()') {
|
||||||
main_fns++
|
main_fns++
|
||||||
|
Loading…
Reference in New Issue
Block a user