From 9322e91d1b1d78024b08b022eece601e110fbf6e Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 21 Oct 2020 15:20:07 +0300 Subject: [PATCH] v test-fmt: add 1 sec sleep before rebuilding vfmt, to avoid its parallel recompilation afterwards --- cmd/tools/vtest-fmt.v | 2 ++ vlib/v/util/util.v | 3 +++ 2 files changed, 5 insertions(+) diff --git a/cmd/tools/vtest-fmt.v b/cmd/tools/vtest-fmt.v index 3583d7eacb..c8d5ea89c8 100644 --- a/cmd/tools/vtest-fmt.v +++ b/cmd/tools/vtest-fmt.v @@ -1,6 +1,7 @@ module main import os +import time import testing import v.util @@ -62,6 +63,7 @@ fn prepare_vfmt_when_needed() { vroot := os.dir(vexe) vfmtv := os.join_path(vroot, 'cmd', 'tools', 'vfmt.v') if util.should_recompile_tool(vexe, vfmtv) { + time.sleep_ms(1001) // TODO: remove this when we can get mtime with a better resolution recompile_file(vexe, vfmtv) } } diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 3200a0a684..03b6737807 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -166,6 +166,9 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) { exit(os.system(tool_command)) } +// NB: should_recompile_tool/2 compares unix timestamps that have 1 second resolution +// That means that a tool can get recompiled twice, if called in short succession. +// TODO: use a nanosecond mtime timestamp, if available. pub fn should_recompile_tool(vexe string, tool_source string) bool { sfolder := os.dir(tool_source) tool_name := os.base(tool_source).replace('.v', '')