From 0e56b96bda57517a52ebb772d1346daf41593e3f Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 21 Oct 2020 11:06:15 +0300 Subject: [PATCH] v test-fmt: recompile vfmt only when needed --- cmd/tools/vtest-fmt.v | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/cmd/tools/vtest-fmt.v b/cmd/tools/vtest-fmt.v index c3e335c2d0..2044afcb92 100644 --- a/cmd/tools/vtest-fmt.v +++ b/cmd/tools/vtest-fmt.v @@ -30,13 +30,7 @@ fn main() { fn v_test_formatting(vargs string) { all_v_files := v_files() - vexe := os.getenv('VEXE') - vroot := os.dir(vexe) - recompile_result := os.system('$vexe ' + os.join_path(vroot, 'cmd', 'tools', 'vfmt.v')) - if recompile_result != 0 { - eprintln('could not recompile cmd/tools/vfmt.v') - exit(2) - } + prepare_vfmt_when_needed() testing.eheader('Run "v fmt" over all .v files') mut vfmt_test_session := testing.new_test_session('$vargs fmt -worker') vfmt_test_session.files << all_v_files @@ -60,3 +54,16 @@ fn v_files() []string { } return files_that_can_be_formatted } + +fn prepare_vfmt_when_needed() { + vexe := os.getenv('VEXE') + vroot := os.dir(vexe) + vfmtv := os.join_path(vroot, 'cmd', 'tools', 'vfmt.v') + if os.file_last_mod_unix(vexe) <= os.file_last_mod_unix(vfmtv) { + recompile_result := os.system('$vexe ' + os.join_path(vroot, 'cmd', 'tools', 'vfmt.v')) + if recompile_result != 0 { + eprintln('could not recompile cmd/tools/vfmt.v') + exit(2) + } + } +}