compiler: implement -W and -reuse-tmpc
parent
42da37e900
commit
8b01146b90
|
@ -58,3 +58,6 @@ These build flags are enabled on `build` and `run` as long as the backend is set
|
||||||
-custom-prelude <path>
|
-custom-prelude <path>
|
||||||
Useful for similar use-case as above option, except it replaces V-generated prelude with
|
Useful for similar use-case as above option, except it replaces V-generated prelude with
|
||||||
your custom one loaded from specified <path>.
|
your custom one loaded from specified <path>.
|
||||||
|
|
||||||
|
-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.
|
||||||
|
|
|
@ -118,6 +118,9 @@ The build flags are shared by the build and run commands:
|
||||||
C GEN: 103ms
|
C GEN: 103ms
|
||||||
C tcc: 95ms
|
C tcc: 95ms
|
||||||
|
|
||||||
|
-W
|
||||||
|
Treat all warnings as errors, even in development builds.
|
||||||
|
|
||||||
For C-specific build flags, use `v help build-c`.
|
For C-specific build flags, use `v help build-c`.
|
||||||
|
|
||||||
See also:
|
See also:
|
||||||
|
|
|
@ -75,9 +75,9 @@ pub fn (mut b Builder) compile_c() {
|
||||||
println('all .v files:')
|
println('all .v files:')
|
||||||
println(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 {
|
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)
|
b.build_c(files, out_name_c)
|
||||||
if b.pref.os == .ios {
|
if b.pref.os == .ios {
|
||||||
|
|
|
@ -78,6 +78,9 @@ fn (mut v Builder) find_win_cc() ? {
|
||||||
|
|
||||||
fn (mut v Builder) post_process_c_compiler_output(res os.Result) {
|
fn (mut v Builder) post_process_c_compiler_output(res os.Result) {
|
||||||
if res.exit_code == 0 {
|
if res.exit_code == 0 {
|
||||||
|
if v.pref.reuse_tmpc {
|
||||||
|
return
|
||||||
|
}
|
||||||
for tmpfile in v.pref.cleanup_files {
|
for tmpfile in v.pref.cleanup_files {
|
||||||
if os.is_file(tmpfile) {
|
if os.is_file(tmpfile) {
|
||||||
if v.pref.is_verbose {
|
if v.pref.is_verbose {
|
||||||
|
|
|
@ -22,10 +22,13 @@ fn get_vtmp_folder() string {
|
||||||
return vtmp
|
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()
|
vtmp := get_vtmp_folder()
|
||||||
uniq := rand.u64()
|
mut uniq := ''
|
||||||
return os.real_path(os.join_path(vtmp, os.file_name(os.real_path(base_file_name)) + '.$uniq$postfix'))
|
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) {
|
pub fn compile(command string, pref &pref.Preferences) {
|
||||||
|
|
|
@ -90,11 +90,7 @@ pub fn (mut c Checker) check_scope_vars(sc &ast.Scope) {
|
||||||
ast.Var {
|
ast.Var {
|
||||||
if !c.pref.is_repl {
|
if !c.pref.is_repl {
|
||||||
if !obj.is_used && obj.name[0] != `_` {
|
if !obj.is_used && obj.name[0] != `_` {
|
||||||
if c.pref.is_prod {
|
c.warn('unused variable: `$obj.name`', obj.pos)
|
||||||
c.error('unused variable: `$obj.name`', obj.pos)
|
|
||||||
} else {
|
|
||||||
c.warn('unused variable: `$obj.name`', obj.pos)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if obj.is_mut && !obj.is_changed && !c.is_builtin_mod && obj.name != 'it' {
|
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) {
|
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
|
c.warn_or_error(s, pos, allow_warnings) // allow warnings only in dev builds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
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 {
|
if p.pref.skip_warnings {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,8 @@ pub mut:
|
||||||
print_v_files bool // when true, just print the list of all parsed .v files then stop.
|
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_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"
|
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.
|
use_color ColorOutput // whether the warnings/errors should use ANSI color escapes.
|
||||||
is_parallel bool
|
is_parallel bool
|
||||||
error_limit int
|
error_limit int
|
||||||
|
@ -248,6 +250,12 @@ pub fn parse_args(args []string) (&Preferences, string) {
|
||||||
'-x64' {
|
'-x64' {
|
||||||
res.backend = .x64
|
res.backend = .x64
|
||||||
}
|
}
|
||||||
|
'-W' {
|
||||||
|
res.warns_are_errors = true
|
||||||
|
}
|
||||||
|
'-reuse-tmpc' {
|
||||||
|
res.reuse_tmpc = true
|
||||||
|
}
|
||||||
'-w' {
|
'-w' {
|
||||||
res.skip_warnings = true
|
res.skip_warnings = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue