genbindings/main: refactor extract findHeadersInDir()

This commit is contained in:
mappu 2024-10-14 18:54:39 +13:00
parent 2c668c77f3
commit 9248b925ff

View File

@ -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))