mirror of
https://github.com/mappu/miqt.git
synced 2024-12-23 01:18:37 +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"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -210,6 +211,25 @@ func generate(packageName string, srcDirs []string, clangBin, cflagsCombined, ou
|
|||||||
// Emit 3 code files from the intermediate format
|
// Emit 3 code files from the intermediate format
|
||||||
outputName := filepath.Join(outDir, "gen_"+strings.TrimSuffix(filepath.Base(parsed.Filename), `.h`))
|
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)
|
goSrc, err := emitGo(parsed, filepath.Base(parsed.Filename), packageName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user