From af60eba5e6bf1d3f858f5959437ba6461be8ce38 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 15 Jun 2021 14:22:18 +0300 Subject: [PATCH] tools: cleanup generated executables by `v test-all` --- .gitignore | 2 ++ cmd/tools/vtest-all.v | 33 +++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 0ac4ad20c3..992d03d2a2 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,8 @@ a.out /v.c /v.*.c /v.c.out +/v_old +/v_old.exe .vrepl_temp.v fns.txt .noprefix.vrepl_temp.v diff --git a/cmd/tools/vtest-all.v b/cmd/tools/vtest-all.v index 6977cbd566..f75d9d70e3 100644 --- a/cmd/tools/vtest-all.v +++ b/cmd/tools/vtest-all.v @@ -4,12 +4,15 @@ import os import term import time -const ( - vexe = os.getenv('VEXE') - vroot = os.dir(vexe) - args_string = os.args[1..].join(' ') - vargs = args_string.all_before('test-all') -) +const vexe = os.getenv('VEXE') + +const vroot = os.dir(vexe) + +const args_string = os.args[1..].join(' ') + +const vargs = args_string.all_before('test-all') + +const vtest_nocleanup = os.getenv('VTEST_NOCLEANUP').bool() fn main() { mut commands := get_all_commands() @@ -44,6 +47,7 @@ mut: ecode int okmsg string errmsg string + rmfile string } fn get_all_commands() []Command { @@ -51,26 +55,32 @@ fn get_all_commands() []Command { res << Command{ line: '$vexe examples/hello_world.v' okmsg: 'V can compile hello world.' + rmfile: 'examples/hello_world' } res << Command{ line: '$vexe -o vtmp cmd/v' okmsg: 'V can compile itself.' + rmfile: 'vtmp' } res << Command{ line: '$vexe -o vtmp_werror -cstrict cmd/v' okmsg: 'V can compile itself with -cstrict.' + rmfile: 'vtmp_werror' } res << Command{ line: '$vexe -o vtmp_autofree -autofree cmd/v' okmsg: 'V can compile itself with -autofree.' + rmfile: 'vtmp_autofree' } res << Command{ line: '$vexe -o vtmp_prealloc -prealloc cmd/v' okmsg: 'V can compile itself with -prealloc.' + rmfile: 'vtmp_prealloc' } res << Command{ line: '$vexe -o vtmp_unused -skip-unused cmd/v' okmsg: 'V can compile itself with -skip-unused.' + rmfile: 'vtmp_unused' } res << Command{ line: '$vexe $vargs -progress test-cleancode' @@ -107,12 +117,14 @@ fn get_all_commands() []Command { res << Command{ line: '$vexe -usecache examples/tetris/tetris.v' okmsg: '`v -usecache` works.' + rmfile: 'examples/tetris/tetris' } $if macos { res << Command{ line: '$vexe -o v.c cmd/v && cc -Werror v.c && rm -rf v.c' label: 'v.c should be buildable with no warnings...' okmsg: 'v.c can be compiled without warnings. This is good :)' + rmfile: 'v.c' } } return res @@ -129,6 +141,15 @@ fn (mut cmd Command) run() { cmd.ecode = os.system(cmd.line) spent := sw.elapsed().milliseconds() println(term_highlight('> Running: "$cmd.line" took: $spent ms.')) + if vtest_nocleanup { + return + } + if cmd.rmfile != '' { + os.rm(cmd.rmfile) or {} + if os.user_os() == 'windows' { + os.rm(cmd.rmfile + '.exe') or {} + } + } } fn term_highlight(s string) string {