Skip to content

Commit

Permalink
codegen presets: add PackagePath
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Nov 16, 2024
1 parent 330fca2 commit b2555b5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmd/codegen/cimgui-go-preset.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"PackagePath": "github.com/AllenDang/cimgui-go",
"SkipFuncs": {
"igInputText": true,
"igInputTextWithHint": true,
Expand Down
4 changes: 2 additions & 2 deletions cmd/codegen/gengo_typedefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ extern "C" {
fmt.Fprintf(g.GoSb,
`// #include <stdlib.h>
// #include <memory.h>
// #include "../imgui/extra_types.h"
// #include "wrapper.h"
// #include "typedefs.h"
%s
import "C"
import "unsafe"
`)
`, g.ctx.preset.MergeCGoPreamble())
}

// k is plain C name of the typedef (key in typedefs_dict.json)
Expand Down
21 changes: 16 additions & 5 deletions cmd/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import (
)

const (
cimguiGoPackagePath = "github.com/AllenDang/cimgui-go"
generatorInfo = "// Code generated by cmd/codegen from https://github.com/AllenDang/cimgui-go.\n// DO NOT EDIT.\n\n"
goPackageHeader = generatorInfo + "package %[1]s\n\nimport (\n\"" + cimguiGoPackagePath + "/datautils\"\n\t\"" + cimguiGoPackagePath + "/%[2]s\"\n)\n\n"
cppFileHeader = generatorInfo
generatorInfo = "// Code generated by cmd/codegen from https://github.com/AllenDang/cimgui-go.\n// DO NOT EDIT.\n\n"
cppFileHeader = generatorInfo
)

// this cextracts enums and structs names from json file.
Expand Down Expand Up @@ -273,7 +271,20 @@ func main() {
}

func getGoPackageHeader(ctx *Context) string {
return fmt.Sprintf(goPackageHeader, ctx.flags.packageName, ctx.flags.refPackageName)
return fmt.Sprintf(
`%[1]s
package %[2]s
import (
"%[4]s/utils"
"%[4]s/%[3]s"
)
`,
generatorInfo,
ctx.flags.packageName,
ctx.flags.refPackageName,
ctx.preset.PackagePath,
)
}

func prefixGoPackage(t, sourcePackage GoIdentifier, ctx *Context) GoIdentifier {
Expand Down
7 changes: 7 additions & 0 deletions cmd/codegen/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ type Preset struct {
InternalFiles []string
// InternalPrefix is a prefix for identifiers from InternalFiles.
InternalPrefix string
// PackagePath is an import path of the package.
// This is base path. flags.packageName will be added.
// Example:
// "github.com/AllenDang/cimgui-go"
// If enerated with -pkg imgui, import path
// is supposed to be "github.com/AllenDang/cimgui-go/imgui"
PackagePath string
}

func (p *Preset) MergeCGoPreamble() string {
Expand Down

0 comments on commit b2555b5

Please sign in to comment.