Skip to content

Commit

Permalink
ci, builder: retry building of thirdparty object files with msvc, in …
Browse files Browse the repository at this point in the history
…case of permission errors (reduce CI false positives)
  • Loading branch information
spytheman committed Dec 2, 2023
1 parent c943d9a commit 64733ed
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions vlib/v/builder/msvc_windows.v
@@ -1,6 +1,7 @@
module builder

import os
import time
import v.pref
import v.util
import v.cflag
Expand Down Expand Up @@ -400,6 +401,7 @@ fn (mut v Builder) build_thirdparty_obj_file_with_msvc(mod string, path string,
return
}
println('${obj_path} not found, building it (with msvc)...')
flush_stdout()
cfile := '${path_without_o_postfix}.c'
flags := msvc_string_flags(moduleflags)
inc_dirs := flags.inc_paths.join(' ')
Expand Down Expand Up @@ -438,15 +440,36 @@ fn (mut v Builder) build_thirdparty_obj_file_with_msvc(mod string, path string,
// Note: the quotes above ARE balanced.
$if trace_thirdparty_obj_files ? {
println('>>> build_thirdparty_obj_file_with_msvc cmd: ${cmd}')
flush_stdout()
}
// Note, that building object files with msvc can fail with permission denied errors,
// when the final .obj file, is locked by another msvc process for writing.
// Instead of failing, just retry several times in this case.
mut res := os.Result{}
mut i := 0
for i = 0; i < builder.thirdparty_obj_build_max_retries; i++ {
res = os.execute(cmd)
if res.exit_code == 0 || !res.output.contains('Permission denied') {
break
}
eprintln('---------------------------------------------------------------------')
eprintln(' msvc: failed to build a thirdparty object, try: ${i}/${builder.thirdparty_obj_build_max_retries}')
eprintln(' cmd: ${cmd}')
eprintln(' output:')
eprintln(res.output)
eprintln('---------------------------------------------------------------------')
time.sleep(builder.thirdparty_obj_build_retry_delay)
}
res := os.execute(cmd)
if res.exit_code != 0 {
println('msvc: failed to build a thirdparty object; cmd: ${cmd}')
verror(res.output)
verror('msvc: failed to build a thirdparty object after ${i}/${builder.thirdparty_obj_build_max_retries} retries, cmd: ${cmd}')
}
println(res.output)
flush_stdout()
}

const thirdparty_obj_build_max_retries = 5
const thirdparty_obj_build_retry_delay = 200 * time.millisecond

struct MsvcStringFlags {
mut:
real_libs []string
Expand Down

0 comments on commit 64733ed

Please sign in to comment.