ci, builder: retry building of thirdparty object files with msvc, in case of permission errors (reduce CI false positives)

This commit is contained in:
Delyan Angelov 2023-12-02 15:58:31 +02:00
parent c943d9a815
commit 64733edc0f
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -1,6 +1,7 @@
module builder
import os
import time
import v.pref
import v.util
import v.cflag
@ -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(' ')
@ -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