1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: implement -W and -reuse-tmpc

This commit is contained in:
Delyan Angelov 2020-10-24 20:29:24 +03:00
parent 42da37e900
commit 8b01146b90
8 changed files with 31 additions and 11 deletions

View File

@ -58,3 +58,6 @@ These build flags are enabled on `build` and `run` as long as the backend is set
-custom-prelude <path>
Useful for similar use-case as above option, except it replaces V-generated prelude with
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.

View File

@ -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:

View File

@ -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 {

View File

@ -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 {

View File

@ -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) {

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}