mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 17:08:38 +00:00
genbindings/main: fix duplicate header name collision in packages
This commit is contained in:
parent
4d0eb716c1
commit
7347073bd8
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
@ -210,6 +211,25 @@ func generate(packageName string, srcDirs []string, clangBin, cflagsCombined, ou
|
||||
// Emit 3 code files from the intermediate format
|
||||
outputName := filepath.Join(outDir, "gen_"+strings.TrimSuffix(filepath.Base(parsed.Filename), `.h`))
|
||||
|
||||
// For packages where we scan multiple directories, it's possible that
|
||||
// there are filename collisions (e.g. Qt 6 has QtWidgets/qaction.h include
|
||||
// QtGui/qaction.h as a compatibility measure).
|
||||
// If the path exists, disambiguate it
|
||||
var counter = 0
|
||||
for {
|
||||
testName := outputName
|
||||
if counter > 0 {
|
||||
testName += fmt.Sprintf(".%d", counter)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(testName + ".go"); err != nil && os.IsNotExist(err) {
|
||||
outputName = testName // Safe
|
||||
break
|
||||
}
|
||||
|
||||
counter++
|
||||
}
|
||||
|
||||
goSrc, err := emitGo(parsed, filepath.Base(parsed.Filename), packageName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Loading…
Reference in New Issue
Block a user