From 3382806f62b9888c16760471fe1a4c676ea9cfe2 Mon Sep 17 00:00:00 2001 From: mappu Date: Mon, 14 Oct 2024 18:55:16 +1300 Subject: [PATCH] genbindings/main: refactor extract cleanGeneratedFilesInDir() --- cmd/genbindings/main.go | 58 +++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/cmd/genbindings/main.go b/cmd/genbindings/main.go index 13c2fe3a..e63b07b8 100644 --- a/cmd/genbindings/main.go +++ b/cmd/genbindings/main.go @@ -46,6 +46,35 @@ func findHeadersInDir(srcDir string) []string { return ret } +func cleanGeneratedFilesInDir(dirpath string) { + log.Printf("Cleaning up output directory %q...", dirpath) + + existing, err := os.ReadDir(dirpath) + if err != nil { + panic(err) + } + + cleaned := 0 + for _, e := range existing { + if e.IsDir() { + continue + } + if !strings.HasPrefix(e.Name(), `gen_`) { + continue + } + // One of ours, clean up + err := os.Remove(filepath.Join(dirpath, e.Name())) + if err != nil { + log.Printf("WARNING: Failed to remove existing file %q", e.Name()) + continue + } + + cleaned++ + } + + log.Printf("Removed %d file(s).", cleaned) +} + func main() { ctx := context.Background() @@ -67,34 +96,7 @@ func main() { log.Printf("Found %d header files to process.", len(includeFiles)) - { - log.Printf("Cleaning up output directory %q...", *outDir) - - existing, err := os.ReadDir(*outDir) - if err != nil { - panic(err) - } - - cleaned := 0 - for _, e := range existing { - if e.IsDir() { - continue - } - if !strings.HasPrefix(e.Name(), `gen_`) { - continue - } - // One of ours, clean up - err := os.Remove(filepath.Join(*outDir, e.Name())) - if err != nil { - log.Printf("WARNING: Failed to remove existing file %q", e.Name()) - continue - } - - cleaned++ - } - - log.Printf("Removed %d file(s).", cleaned) - } + cleanGeneratedFilesInDir(*outDir) var processHeaders []*CppParsedHeader atr := astTransformRedundant{