mirror of
https://github.com/mappu/miqt.git
synced 2025-01-03 06:08:38 +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))
|
||||
|
||||
bindingInclude := "../libmiqt/libmiqt.h"
|
||||
if packageName != "qt" {
|
||||
|
||||
if strings.Contains(packageName, `/`) {
|
||||
bindingInclude = "../" + bindingInclude
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"go/format"
|
||||
"log"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
@ -103,7 +104,7 @@ func (p CppParameter) RenderTypeGo(gfs *goFileState) string {
|
||||
|
||||
if enumInfo, ok := KnownEnums[ft.ParameterType]; ok && enumInfo.PackageName != gfs.currentPackageName {
|
||||
// Cross-package
|
||||
ret += enumInfo.PackageName + "." + cabiClassName(ft.ParameterType)
|
||||
ret += path.Base(enumInfo.PackageName) + "." + cabiClassName(ft.ParameterType)
|
||||
gfs.imports[importPathForQtPackage(enumInfo.PackageName)] = struct{}{}
|
||||
} else {
|
||||
// Same package
|
||||
@ -113,7 +114,7 @@ func (p CppParameter) RenderTypeGo(gfs *goFileState) string {
|
||||
} else if enumInfo, ok := KnownEnums[p.ParameterType]; ok {
|
||||
if enumInfo.PackageName != gfs.currentPackageName {
|
||||
// Cross-package
|
||||
ret += enumInfo.PackageName + "." + cabiClassName(p.ParameterType)
|
||||
ret += path.Base(enumInfo.PackageName) + "." + cabiClassName(p.ParameterType)
|
||||
gfs.imports[importPathForQtPackage(enumInfo.PackageName)] = struct{}{}
|
||||
} else {
|
||||
// Same package
|
||||
@ -132,7 +133,7 @@ func (p CppParameter) RenderTypeGo(gfs *goFileState) string {
|
||||
}
|
||||
|
||||
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{}{}
|
||||
}
|
||||
|
||||
@ -448,7 +449,7 @@ func (gfs *goFileState) emitCabiToGo(assignExpr string, rt CppParameter, rvalue
|
||||
|
||||
crossPackage := ""
|
||||
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{}{}
|
||||
}
|
||||
|
||||
@ -497,7 +498,7 @@ func (gfs *goFileState) emitCabiToGo(assignExpr string, rt CppParameter, rvalue
|
||||
func emitGo(src *CppParsedHeader, headerName string, packageName string) (string, error) {
|
||||
|
||||
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 {
|
||||
// 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{}{}
|
||||
} else {
|
||||
// Same-package parent class
|
||||
@ -622,7 +623,7 @@ import "C"
|
||||
|
||||
ctorPrefix := ""
|
||||
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))"
|
||||
|
@ -19,23 +19,14 @@ const (
|
||||
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 {
|
||||
return filepath.Join("cachedir", strings.Replace(inputHeader, `/`, `__`, -1)+".json")
|
||||
}
|
||||
|
||||
func importPathForQtPackage(packageName string) string {
|
||||
return BaseModule + "/" + packageName
|
||||
}
|
||||
|
||||
func findHeadersInDir(srcDir string) []string {
|
||||
content, err := os.ReadDir(srcDir)
|
||||
if err != nil {
|
||||
@ -117,42 +108,42 @@ func main() {
|
||||
},
|
||||
*clang,
|
||||
strings.Fields(pkgConfigCflags("Qt5Widgets")),
|
||||
filepath.Join(*outDir, "qt"),
|
||||
*outDir,
|
||||
ClangMatchSameHeaderDefinitionOnly,
|
||||
)
|
||||
|
||||
generate(
|
||||
"qprintsupport",
|
||||
"qt/qprintsupport",
|
||||
[]string{
|
||||
"/usr/include/x86_64-linux-gnu/qt5/QtPrintSupport",
|
||||
},
|
||||
*clang,
|
||||
strings.Fields(pkgConfigCflags("Qt5PrintSupport")),
|
||||
filepath.Join(*outDir, "qt/qprintsupport"),
|
||||
*outDir,
|
||||
ClangMatchSameHeaderDefinitionOnly,
|
||||
)
|
||||
|
||||
// Depends on QtCore/Gui/Widgets, QPrintSupport
|
||||
generate(
|
||||
"qscintilla",
|
||||
"qt-restricted-extras/qscintilla",
|
||||
[]string{
|
||||
"/usr/include/x86_64-linux-gnu/qt5/Qsci",
|
||||
},
|
||||
*clang,
|
||||
strings.Fields(pkgConfigCflags("Qt5PrintSupport")),
|
||||
filepath.Join(*outDir, "qt-restricted-extras/qscintilla"),
|
||||
*outDir,
|
||||
ClangMatchSameHeaderDefinitionOnly,
|
||||
)
|
||||
|
||||
// Depends on QtCore/Gui/Widgets
|
||||
generate(
|
||||
"scintillaedit",
|
||||
"qt-extras/scintillaedit",
|
||||
[]string{
|
||||
filepath.Join(*extraLibsDir, "scintilla/qt/ScintillaEdit/ScintillaEdit.h"),
|
||||
},
|
||||
*clang,
|
||||
strings.Fields("--std=c++1z "+pkgConfigCflags("ScintillaEdit")),
|
||||
filepath.Join(*outDir, "qt-extras/scintillaedit"),
|
||||
*outDir,
|
||||
(&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))
|
||||
|
||||
outDir = filepath.Join(outDir, packageName)
|
||||
|
||||
cleanGeneratedFilesInDir(outDir)
|
||||
|
||||
var processHeaders []*CppParsedHeader
|
||||
|
Loading…
Reference in New Issue
Block a user