mirror of
https://github.com/mappu/miqt.git
synced 2025-01-05 07:08:39 +00:00
genbindings/main: uniform handling for package subdirectories
This commit is contained in:
parent
30b7708a6c
commit
301fa27e83
@ -510,7 +510,8 @@ func emitBindingHeader(src *CppParsedHeader, filename string, packageName string
|
|||||||
includeGuard := "GEN_" + strings.ToUpper(strings.Replace(filename, `.`, `_`, -1))
|
includeGuard := "GEN_" + strings.ToUpper(strings.Replace(filename, `.`, `_`, -1))
|
||||||
|
|
||||||
bindingInclude := "../libmiqt/libmiqt.h"
|
bindingInclude := "../libmiqt/libmiqt.h"
|
||||||
if packageName != "qt" {
|
|
||||||
|
if strings.Contains(packageName, `/`) {
|
||||||
bindingInclude = "../" + bindingInclude
|
bindingInclude = "../" + bindingInclude
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"go/format"
|
"go/format"
|
||||||
"log"
|
"log"
|
||||||
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -103,7 +104,7 @@ func (p CppParameter) RenderTypeGo(gfs *goFileState) string {
|
|||||||
|
|
||||||
if enumInfo, ok := KnownEnums[ft.ParameterType]; ok && enumInfo.PackageName != gfs.currentPackageName {
|
if enumInfo, ok := KnownEnums[ft.ParameterType]; ok && enumInfo.PackageName != gfs.currentPackageName {
|
||||||
// Cross-package
|
// Cross-package
|
||||||
ret += enumInfo.PackageName + "." + cabiClassName(ft.ParameterType)
|
ret += path.Base(enumInfo.PackageName) + "." + cabiClassName(ft.ParameterType)
|
||||||
gfs.imports[importPathForQtPackage(enumInfo.PackageName)] = struct{}{}
|
gfs.imports[importPathForQtPackage(enumInfo.PackageName)] = struct{}{}
|
||||||
} else {
|
} else {
|
||||||
// Same package
|
// Same package
|
||||||
@ -113,7 +114,7 @@ func (p CppParameter) RenderTypeGo(gfs *goFileState) string {
|
|||||||
} else if enumInfo, ok := KnownEnums[p.ParameterType]; ok {
|
} else if enumInfo, ok := KnownEnums[p.ParameterType]; ok {
|
||||||
if enumInfo.PackageName != gfs.currentPackageName {
|
if enumInfo.PackageName != gfs.currentPackageName {
|
||||||
// Cross-package
|
// Cross-package
|
||||||
ret += enumInfo.PackageName + "." + cabiClassName(p.ParameterType)
|
ret += path.Base(enumInfo.PackageName) + "." + cabiClassName(p.ParameterType)
|
||||||
gfs.imports[importPathForQtPackage(enumInfo.PackageName)] = struct{}{}
|
gfs.imports[importPathForQtPackage(enumInfo.PackageName)] = struct{}{}
|
||||||
} else {
|
} else {
|
||||||
// Same package
|
// Same package
|
||||||
@ -132,7 +133,7 @@ func (p CppParameter) RenderTypeGo(gfs *goFileState) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pkg, ok := KnownClassnames[p.ParameterType]; ok && pkg.PackageName != gfs.currentPackageName {
|
if pkg, ok := KnownClassnames[p.ParameterType]; ok && pkg.PackageName != gfs.currentPackageName {
|
||||||
ret = pkg.PackageName + "." + ret
|
ret = path.Base(pkg.PackageName) + "." + ret
|
||||||
gfs.imports[importPathForQtPackage(pkg.PackageName)] = struct{}{}
|
gfs.imports[importPathForQtPackage(pkg.PackageName)] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +449,7 @@ func (gfs *goFileState) emitCabiToGo(assignExpr string, rt CppParameter, rvalue
|
|||||||
|
|
||||||
crossPackage := ""
|
crossPackage := ""
|
||||||
if pkg, ok := KnownClassnames[rt.ParameterType]; ok && pkg.PackageName != gfs.currentPackageName {
|
if pkg, ok := KnownClassnames[rt.ParameterType]; ok && pkg.PackageName != gfs.currentPackageName {
|
||||||
crossPackage = pkg.PackageName + "."
|
crossPackage = path.Base(pkg.PackageName) + "."
|
||||||
gfs.imports[importPathForQtPackage(pkg.PackageName)] = struct{}{}
|
gfs.imports[importPathForQtPackage(pkg.PackageName)] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,7 +498,7 @@ func (gfs *goFileState) emitCabiToGo(assignExpr string, rt CppParameter, rvalue
|
|||||||
func emitGo(src *CppParsedHeader, headerName string, packageName string) (string, error) {
|
func emitGo(src *CppParsedHeader, headerName string, packageName string) (string, error) {
|
||||||
|
|
||||||
ret := strings.Builder{}
|
ret := strings.Builder{}
|
||||||
ret.WriteString(`package ` + packageName + `
|
ret.WriteString(`package ` + path.Base(packageName) + `
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
@ -587,7 +588,7 @@ import "C"
|
|||||||
|
|
||||||
if pkg, ok := KnownClassnames[base]; ok && pkg.PackageName != gfs.currentPackageName {
|
if pkg, ok := KnownClassnames[base]; ok && pkg.PackageName != gfs.currentPackageName {
|
||||||
// Cross-package parent class
|
// Cross-package parent class
|
||||||
ret.WriteString("*" + pkg.PackageName + "." + cabiClassName(base) + "\n")
|
ret.WriteString("*" + path.Base(pkg.PackageName) + "." + cabiClassName(base) + "\n")
|
||||||
gfs.imports[importPathForQtPackage(pkg.PackageName)] = struct{}{}
|
gfs.imports[importPathForQtPackage(pkg.PackageName)] = struct{}{}
|
||||||
} else {
|
} else {
|
||||||
// Same-package parent class
|
// Same-package parent class
|
||||||
@ -622,7 +623,7 @@ import "C"
|
|||||||
|
|
||||||
ctorPrefix := ""
|
ctorPrefix := ""
|
||||||
if pkg, ok := KnownClassnames[base]; ok && pkg.PackageName != gfs.currentPackageName {
|
if pkg, ok := KnownClassnames[base]; ok && pkg.PackageName != gfs.currentPackageName {
|
||||||
ctorPrefix = pkg.PackageName + "."
|
ctorPrefix = path.Base(pkg.PackageName) + "."
|
||||||
}
|
}
|
||||||
|
|
||||||
localInit += ", " + cabiClassName(base) + ": " + ctorPrefix + "UnsafeNew" + cabiClassName(base) + "(unsafe.Pointer(h))"
|
localInit += ", " + cabiClassName(base) + ": " + ctorPrefix + "UnsafeNew" + cabiClassName(base) + "(unsafe.Pointer(h))"
|
||||||
|
@ -19,23 +19,14 @@ const (
|
|||||||
BaseModule = "github.com/mappu/miqt"
|
BaseModule = "github.com/mappu/miqt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func importPathForQtPackage(packageName string) string {
|
|
||||||
switch packageName {
|
|
||||||
case "qt":
|
|
||||||
return BaseModule + "/qt"
|
|
||||||
case "qscintilla":
|
|
||||||
return BaseModule + "/qt-restricted-extras/" + packageName
|
|
||||||
case "scintillaedit":
|
|
||||||
return BaseModule + "/qt-extras/" + packageName
|
|
||||||
default:
|
|
||||||
return BaseModule + "/qt/" + packageName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func cacheFilePath(inputHeader string) string {
|
func cacheFilePath(inputHeader string) string {
|
||||||
return filepath.Join("cachedir", strings.Replace(inputHeader, `/`, `__`, -1)+".json")
|
return filepath.Join("cachedir", strings.Replace(inputHeader, `/`, `__`, -1)+".json")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func importPathForQtPackage(packageName string) string {
|
||||||
|
return BaseModule + "/" + packageName
|
||||||
|
}
|
||||||
|
|
||||||
func findHeadersInDir(srcDir string) []string {
|
func findHeadersInDir(srcDir string) []string {
|
||||||
content, err := os.ReadDir(srcDir)
|
content, err := os.ReadDir(srcDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -117,42 +108,42 @@ func main() {
|
|||||||
},
|
},
|
||||||
*clang,
|
*clang,
|
||||||
strings.Fields(pkgConfigCflags("Qt5Widgets")),
|
strings.Fields(pkgConfigCflags("Qt5Widgets")),
|
||||||
filepath.Join(*outDir, "qt"),
|
*outDir,
|
||||||
ClangMatchSameHeaderDefinitionOnly,
|
ClangMatchSameHeaderDefinitionOnly,
|
||||||
)
|
)
|
||||||
|
|
||||||
generate(
|
generate(
|
||||||
"qprintsupport",
|
"qt/qprintsupport",
|
||||||
[]string{
|
[]string{
|
||||||
"/usr/include/x86_64-linux-gnu/qt5/QtPrintSupport",
|
"/usr/include/x86_64-linux-gnu/qt5/QtPrintSupport",
|
||||||
},
|
},
|
||||||
*clang,
|
*clang,
|
||||||
strings.Fields(pkgConfigCflags("Qt5PrintSupport")),
|
strings.Fields(pkgConfigCflags("Qt5PrintSupport")),
|
||||||
filepath.Join(*outDir, "qt/qprintsupport"),
|
*outDir,
|
||||||
ClangMatchSameHeaderDefinitionOnly,
|
ClangMatchSameHeaderDefinitionOnly,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Depends on QtCore/Gui/Widgets, QPrintSupport
|
// Depends on QtCore/Gui/Widgets, QPrintSupport
|
||||||
generate(
|
generate(
|
||||||
"qscintilla",
|
"qt-restricted-extras/qscintilla",
|
||||||
[]string{
|
[]string{
|
||||||
"/usr/include/x86_64-linux-gnu/qt5/Qsci",
|
"/usr/include/x86_64-linux-gnu/qt5/Qsci",
|
||||||
},
|
},
|
||||||
*clang,
|
*clang,
|
||||||
strings.Fields(pkgConfigCflags("Qt5PrintSupport")),
|
strings.Fields(pkgConfigCflags("Qt5PrintSupport")),
|
||||||
filepath.Join(*outDir, "qt-restricted-extras/qscintilla"),
|
*outDir,
|
||||||
ClangMatchSameHeaderDefinitionOnly,
|
ClangMatchSameHeaderDefinitionOnly,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Depends on QtCore/Gui/Widgets
|
// Depends on QtCore/Gui/Widgets
|
||||||
generate(
|
generate(
|
||||||
"scintillaedit",
|
"qt-extras/scintillaedit",
|
||||||
[]string{
|
[]string{
|
||||||
filepath.Join(*extraLibsDir, "scintilla/qt/ScintillaEdit/ScintillaEdit.h"),
|
filepath.Join(*extraLibsDir, "scintilla/qt/ScintillaEdit/ScintillaEdit.h"),
|
||||||
},
|
},
|
||||||
*clang,
|
*clang,
|
||||||
strings.Fields("--std=c++1z "+pkgConfigCflags("ScintillaEdit")),
|
strings.Fields("--std=c++1z "+pkgConfigCflags("ScintillaEdit")),
|
||||||
filepath.Join(*outDir, "qt-extras/scintillaedit"),
|
*outDir,
|
||||||
(&clangMatchUnderPath{filepath.Join(*extraLibsDir, "scintilla")}).Match,
|
(&clangMatchUnderPath{filepath.Join(*extraLibsDir, "scintilla")}).Match,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -170,6 +161,8 @@ func generate(packageName string, srcDirs []string, clangBin string, cflags []st
|
|||||||
|
|
||||||
log.Printf("Found %d header files to process.", len(includeFiles))
|
log.Printf("Found %d header files to process.", len(includeFiles))
|
||||||
|
|
||||||
|
outDir = filepath.Join(outDir, packageName)
|
||||||
|
|
||||||
cleanGeneratedFilesInDir(outDir)
|
cleanGeneratedFilesInDir(outDir)
|
||||||
|
|
||||||
var processHeaders []*CppParsedHeader
|
var processHeaders []*CppParsedHeader
|
||||||
|
Loading…
Reference in New Issue
Block a user