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

tools: cleanup all temporary files on successfull v check-md .

This commit is contained in:
Delyan Angelov 2022-03-27 10:24:10 +03:00
parent 0e496a8de2
commit a07d066e8f
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -22,6 +22,7 @@ const (
show_progress = os.getenv('GITHUB_JOB') == '' && '-silent' !in os.args show_progress = os.getenv('GITHUB_JOB') == '' && '-silent' !in os.args
non_option_args = cmdline.only_non_options(os.args[2..]) non_option_args = cmdline.only_non_options(os.args[2..])
is_verbose = os.getenv('VERBOSE') != '' is_verbose = os.getenv('VERBOSE') != ''
vcheckfolder = os.join_path_single(os.temp_dir(), 'vcheck_$os.getuid()')
) )
struct CheckResult { struct CheckResult {
@ -57,6 +58,10 @@ fn main() {
if term_colors { if term_colors {
os.setenv('VCOLORS', 'always', true) os.setenv('VCOLORS', 'always', true)
} }
os.mkdir_all(vcheckfolder) or {}
defer {
os.rmdir_all(vcheckfolder) or {}
}
for i := 0; i < files_paths.len; i++ { for i := 0; i < files_paths.len; i++ {
file_path := files_paths[i] file_path := files_paths[i]
if os.is_dir(file_path) { if os.is_dir(file_path) {
@ -427,8 +432,9 @@ fn (mut f MDFile) check_examples() CheckResult {
} }
fname := os.base(f.path).replace('.md', '_md') fname := os.base(f.path).replace('.md', '_md')
uid := rand.ulid() uid := rand.ulid()
cfile := os.join_path(os.temp_dir(), '${uid}.c') cfile := os.join_path(vcheckfolder, '${uid}.c')
vfile := os.join_path(os.temp_dir(), 'check_${fname}_example_${e.sline}__${e.eline}__${uid}.v') vfile := os.join_path(vcheckfolder, 'check_${fname}_example_${e.sline}__${e.eline}__${uid}.v')
efile := os.join_path(vcheckfolder, 'check_${fname}_example_${e.sline}__${e.eline}__${uid}.exe')
mut should_cleanup_vfile := true mut should_cleanup_vfile := true
// eprintln('>>> checking example $vfile ...') // eprintln('>>> checking example $vfile ...')
vcontent := e.text.join('\n') + '\n' vcontent := e.text.join('\n') + '\n'
@ -440,7 +446,7 @@ fn (mut f MDFile) check_examples() CheckResult {
fmt_res := if nofmt { 0 } else { get_fmt_exit_code(vfile, vexe) } fmt_res := if nofmt { 0 } else { get_fmt_exit_code(vfile, vexe) }
match command { match command {
'compile' { 'compile' {
res := cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors ${os.quoted_path(vfile)}') res := cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -o ${os.quoted_path(efile)} ${os.quoted_path(vfile)}')
if res != 0 || fmt_res != 0 { if res != 0 || fmt_res != 0 {
if res != 0 { if res != 0 {
eprintln(eline(f.path, e.sline, 0, 'example failed to compile')) eprintln(eline(f.path, e.sline, 0, 'example failed to compile'))
@ -457,7 +463,6 @@ fn (mut f MDFile) check_examples() CheckResult {
} }
'cgen' { 'cgen' {
res := cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -o ${os.quoted_path(cfile)} ${os.quoted_path(vfile)}') res := cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -o ${os.quoted_path(cfile)} ${os.quoted_path(vfile)}')
os.rm(cfile) or {}
if res != 0 || fmt_res != 0 { if res != 0 || fmt_res != 0 {
if res != 0 { if res != 0 {
eprintln(eline(f.path, e.sline, 0, 'example failed to generate C code')) eprintln(eline(f.path, e.sline, 0, 'example failed to generate C code'))
@ -474,7 +479,6 @@ fn (mut f MDFile) check_examples() CheckResult {
} }
'globals' { 'globals' {
res := cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -enable-globals -o ${os.quoted_path(cfile)} ${os.quoted_path(vfile)}') res := cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -enable-globals -o ${os.quoted_path(cfile)} ${os.quoted_path(vfile)}')
os.rm(cfile) or {}
if res != 0 || fmt_res != 0 { if res != 0 || fmt_res != 0 {
if res != 0 { if res != 0 {
eprintln(eline(f.path, e.sline, 0, '`example failed to compile with -enable-globals')) eprintln(eline(f.path, e.sline, 0, '`example failed to compile with -enable-globals'))
@ -491,7 +495,6 @@ fn (mut f MDFile) check_examples() CheckResult {
} }
'live' { 'live' {
res := cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -live -o ${os.quoted_path(cfile)} ${os.quoted_path(vfile)}') res := cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -live -o ${os.quoted_path(cfile)} ${os.quoted_path(vfile)}')
os.rm(cfile) or {}
if res != 0 || fmt_res != 0 { if res != 0 || fmt_res != 0 {
if res != 0 { if res != 0 {
eprintln(eline(f.path, e.sline, 0, 'example failed to compile with -live')) eprintln(eline(f.path, e.sline, 0, 'example failed to compile with -live'))
@ -508,7 +511,6 @@ fn (mut f MDFile) check_examples() CheckResult {
} }
'failcompile' { 'failcompile' {
res := silent_cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -o ${os.quoted_path(cfile)} ${os.quoted_path(vfile)}') res := silent_cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -o ${os.quoted_path(cfile)} ${os.quoted_path(vfile)}')
os.rm(cfile) or {}
if res == 0 || fmt_res != 0 { if res == 0 || fmt_res != 0 {
if res == 0 { if res == 0 {
eprintln(eline(f.path, e.sline, 0, '`failcompile` example compiled')) eprintln(eline(f.path, e.sline, 0, '`failcompile` example compiled'))
@ -558,6 +560,8 @@ fn (mut f MDFile) check_examples() CheckResult {
} }
} }
} }
os.rm(cfile) or {}
os.rm(efile) or {}
if should_cleanup_vfile { if should_cleanup_vfile {
os.rm(vfile) or { panic(err) } os.rm(vfile) or { panic(err) }
} }