diff --git a/cmd/v/help/build-c.txt b/cmd/v/help/build-c.txt index c1aa57aba1..0cebb698c2 100644 --- a/cmd/v/help/build-c.txt +++ b/cmd/v/help/build-c.txt @@ -58,3 +58,6 @@ These build flags are enabled on `build` and `run` as long as the backend is set -custom-prelude Useful for similar use-case as above option, except it replaces V-generated prelude with your custom one loaded from specified . + + -reuse-tmpc + Do not remove the temporary .tmp.c and .tmp.c.rsp files. Also do not use a random prefix for them, so they would be fixed and predictable. diff --git a/cmd/v/help/build.txt b/cmd/v/help/build.txt index fd0d01da16..148851a428 100644 --- a/cmd/v/help/build.txt +++ b/cmd/v/help/build.txt @@ -118,6 +118,9 @@ The build flags are shared by the build and run commands: C GEN: 103ms C tcc: 95ms + -W + Treat all warnings as errors, even in development builds. + For C-specific build flags, use `v help build-c`. See also: diff --git a/vlib/v/builder/c.v b/vlib/v/builder/c.v index 4341ba0123..2690e31b0c 100644 --- a/vlib/v/builder/c.v +++ b/vlib/v/builder/c.v @@ -75,9 +75,9 @@ pub fn (mut b Builder) compile_c() { println('all .v files:') println(files) } - mut out_name_c := get_vtmp_filename(b.pref.out_name, '.tmp.c') + mut out_name_c := b.get_vtmp_filename(b.pref.out_name, '.tmp.c') if b.pref.is_shared { - out_name_c = get_vtmp_filename(b.pref.out_name, '.tmp.so.c') + out_name_c = b.get_vtmp_filename(b.pref.out_name, '.tmp.so.c') } b.build_c(files, out_name_c) if b.pref.os == .ios { diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 06fc468160..6ed7401406 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -78,6 +78,9 @@ fn (mut v Builder) find_win_cc() ? { fn (mut v Builder) post_process_c_compiler_output(res os.Result) { if res.exit_code == 0 { + if v.pref.reuse_tmpc { + return + } for tmpfile in v.pref.cleanup_files { if os.is_file(tmpfile) { if v.pref.is_verbose { diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index 5aaa507dc0..cc3cdf3709 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -22,10 +22,13 @@ fn get_vtmp_folder() string { return vtmp } -fn get_vtmp_filename(base_file_name string, postfix string) string { +fn (mut b Builder) get_vtmp_filename(base_file_name string, postfix string) string { vtmp := get_vtmp_folder() - uniq := rand.u64() - return os.real_path(os.join_path(vtmp, os.file_name(os.real_path(base_file_name)) + '.$uniq$postfix')) + mut uniq := '' + if !b.pref.reuse_tmpc { + uniq = '.${rand.u64()}' + } + return os.real_path(os.join_path(vtmp, os.file_name(os.real_path(base_file_name)) + '$uniq$postfix')) } pub fn compile(command string, pref &pref.Preferences) { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 499a544287..4c7231b18d 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -90,11 +90,7 @@ pub fn (mut c Checker) check_scope_vars(sc &ast.Scope) { ast.Var { if !c.pref.is_repl { if !obj.is_used && obj.name[0] != `_` { - if c.pref.is_prod { - c.error('unused variable: `$obj.name`', obj.pos) - } else { - c.warn('unused variable: `$obj.name`', obj.pos) - } + c.warn('unused variable: `$obj.name`', obj.pos) } } if obj.is_mut && !obj.is_changed && !c.is_builtin_mod && obj.name != 'it' { @@ -3854,7 +3850,7 @@ pub fn (mut c Checker) add_error_detail(s string) { } pub fn (mut c Checker) warn(s string, pos token.Position) { - allow_warnings := !c.pref.is_prod // allow warnings only in dev builds + allow_warnings := !(c.pref.is_prod || c.pref.warns_are_errors)// allow warnings only in dev builds c.warn_or_error(s, pos, allow_warnings) // allow warnings only in dev builds } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 8397dff3c7..4297a16af0 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -816,6 +816,10 @@ pub fn (mut p Parser) error_with_pos(s string, pos token.Position) { } pub fn (mut p Parser) warn_with_pos(s string, pos token.Position) { + if p.pref.warns_are_errors { + p.error_with_pos(s, pos) + return + } if p.pref.skip_warnings { return } diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 80548fa374..9a12ba679b 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -117,6 +117,8 @@ pub mut: 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" + warns_are_errors bool // -W, like C's "-Werror", treat *every* warning is an error + reuse_tmpc bool // do not use random names for .tmp.c and .tmp.c.rsp files, and do not remove them use_color ColorOutput // whether the warnings/errors should use ANSI color escapes. is_parallel bool error_limit int @@ -248,6 +250,12 @@ pub fn parse_args(args []string) (&Preferences, string) { '-x64' { res.backend = .x64 } + '-W' { + res.warns_are_errors = true + } + '-reuse-tmpc' { + res.reuse_tmpc = true + } '-w' { res.skip_warnings = true }