From 9248b925ff274f4c964323b1cf6d277d86f2a2ea Mon Sep 17 00:00:00 2001 From: mappu Date: Mon, 14 Oct 2024 18:54:39 +1300 Subject: [PATCH] genbindings/main: refactor extract findHeadersInDir() --- cmd/genbindings/main.go | 44 ++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/cmd/genbindings/main.go b/cmd/genbindings/main.go index 37f428a5..13c2fe3a 100644 --- a/cmd/genbindings/main.go +++ b/cmd/genbindings/main.go @@ -21,6 +21,31 @@ func cacheFilePath(inputHeader string) string { return filepath.Join("cachedir", strings.Replace(inputHeader, `/`, `__`, -1)+".json") } +func findHeadersInDir(srcDir string) []string { + content, err := os.ReadDir(srcDir) + if err != nil { + panic(err) + } + + var ret []string + + for _, includeFile := range content { + if includeFile.IsDir() { + continue + } + if !strings.HasSuffix(includeFile.Name(), `.h`) { + continue + } + fullPath := filepath.Join(srcDir, includeFile.Name()) + if !AllowHeader(fullPath) { + continue + } + ret = append(ret, fullPath) + } + + return ret +} + func main() { ctx := context.Background() @@ -37,24 +62,7 @@ func main() { "/usr/include/x86_64-linux-gnu/qt5/QtGui", "/usr/include/x86_64-linux-gnu/qt5/QtWidgets", } { - content, err := os.ReadDir(srcDir) - if err != nil { - panic(err) - } - - for _, includeFile := range content { - if includeFile.IsDir() { - continue - } - if !strings.HasSuffix(includeFile.Name(), `.h`) { - continue - } - fullPath := filepath.Join(srcDir, includeFile.Name()) - if !AllowHeader(fullPath) { - continue - } - includeFiles = append(includeFiles, fullPath) - } + includeFiles = append(includeFiles, findHeadersInDir(srcDir)...) } log.Printf("Found %d header files to process.", len(includeFiles))