genbindings: add retry logic to clang subprocess execution

This commit is contained in:
mappu 2024-09-11 17:44:36 +12:00
parent ab7dd64d8a
commit 52c6c3b0ea

View File

@ -9,6 +9,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
) )
func cacheFilePath(inputHeader string) string { func cacheFilePath(inputHeader string) string {
@ -96,9 +97,22 @@ func main() {
log.Printf("No AST cache for file %q, running clang...", filepath.Base(inputHeader)) log.Printf("No AST cache for file %q, running clang...", filepath.Base(inputHeader))
// Parse the file // Parse the file
// This seems to intermittently fail, so allow retrying
nextRetry:
for retryCt := 0; retryCt < 5; retryCt++ {
astInner, err = clangExec(ctx, *clang, inputHeader, strings.Fields(*cflags)) astInner, err = clangExec(ctx, *clang, inputHeader, strings.Fields(*cflags))
if err != nil { if err != nil {
panic(err) // Log and continue with next retry
log.Printf("WARNING: Clang execution failed: %v", err)
time.Sleep(3 * time.Second)
log.Printf("Retrying...")
} else { // err == nil
break nextRetry
}
}
if err != nil {
panic("Clang execution failed after 5x retries")
} }
// Write to cache // Write to cache