Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Push this data into the Codegen message
  • Loading branch information
kyleconroy committed Oct 13, 2023
commit dfb30e42ffcbbc9640c78e3734be0d3f7233c748
38 changes: 16 additions & 22 deletions internal/cmd/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,56 +57,50 @@ func pluginSettings(r *compiler.Result, cs config.CombinedSettings) *plugin.Sett
Queries: []string(cs.Package.Queries),
Overrides: over,
Rename: cs.Rename,
Codegen: pluginCodegen(cs.Codegen),
Plugin: pluginPlugin(cs),
Codegen: pluginCodegen(cs, cs.Codegen),
}
}

func pluginCodegen(s config.Codegen) *plugin.Codegen {
func pluginCodegen(cs config.CombinedSettings, s config.Codegen) *plugin.Codegen {
opts, err := convert.YAMLtoJSON(s.Options)
if err != nil {
panic(err)
}
return &plugin.Codegen{
cg := &plugin.Codegen{
Out: s.Out,
Plugin: s.Plugin,
Options: opts,
}
for _, p := range cs.Global.Plugins {
if p.Name == s.Plugin {
cg.Env = p.Env
cg.Process = pluginProcess(p)
cg.Wasm = pluginWASM(p)
return cg
}
}
return cg
}

func pluginProcess(p config.Plugin) *plugin.Plugin_Process {
func pluginProcess(p config.Plugin) *plugin.Codegen_Process {
if p.Process != nil {
return &plugin.Plugin_Process{
return &plugin.Codegen_Process{
Cmd: p.Process.Cmd,
}
}
return nil
}

func pluginWASM(p config.Plugin) *plugin.Plugin_WASM {
func pluginWASM(p config.Plugin) *plugin.Codegen_WASM {
if p.WASM != nil {
return &plugin.Plugin_WASM{
return &plugin.Codegen_WASM{
Url: p.WASM.URL,
Sha256: p.WASM.SHA256,
}
}
return nil
}

func pluginPlugin(cs config.CombinedSettings) *plugin.Plugin {
for _, p := range cs.Global.Plugins {
if p.Name == cs.Codegen.Plugin {
return &plugin.Plugin{
Name: p.Name,
Env: p.Env,
Process: pluginProcess(p),
Wasm: pluginWASM(p),
}
}
}
return nil
}

func pluginGoType(o config.Override) *plugin.ParsedGoType {
// Note that there is a slight mismatch between this and the
// proto api. The GoType on the override is the unparsed type,
Expand Down
8 changes: 5 additions & 3 deletions internal/endtoend/testdata/codegen_json/gen/codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
"codegen": {
"out": "",
"plugin": "",
"options": ""
},
"plugin": null
"options": "",
"env": [],
"process": null,
"wasm": null
}
},
"catalog": {
"comment": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
"codegen": {
"out": "gen",
"plugin": "jsonb",
"options": "eyJmaWxlbmFtZSI6ImNvZGVnZW4uanNvbiIsImluZGVudCI6IiAgIn0="
},
"plugin": {
"name": "jsonb",
"options": "eyJmaWxlbmFtZSI6ImNvZGVnZW4uanNvbiIsImluZGVudCI6IiAgIn0=",
"env": [],
"process": {
"cmd": "sqlc-gen-json"
Expand Down
Loading