Skip to content

Commit 8493f87

Browse files
authored
feat(codegen): Include plugin information (sqlc-dev#2846)
* feat(codegen): Include plugin information Include the configured plugin's env, name, sha256 and URL
1 parent cb45cb1 commit 8493f87

File tree

6 files changed

+1129
-237
lines changed

6 files changed

+1129
-237
lines changed

internal/cmd/shim.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,48 @@ func pluginSettings(r *compiler.Result, cs config.CombinedSettings) *plugin.Sett
5757
Queries: []string(cs.Package.Queries),
5858
Overrides: over,
5959
Rename: cs.Rename,
60-
Codegen: pluginCodegen(cs.Codegen),
60+
Codegen: pluginCodegen(cs, cs.Codegen),
6161
}
6262
}
6363

64-
func pluginCodegen(s config.Codegen) *plugin.Codegen {
64+
func pluginCodegen(cs config.CombinedSettings, s config.Codegen) *plugin.Codegen {
6565
opts, err := convert.YAMLtoJSON(s.Options)
6666
if err != nil {
6767
panic(err)
6868
}
69-
return &plugin.Codegen{
69+
cg := &plugin.Codegen{
7070
Out: s.Out,
7171
Plugin: s.Plugin,
7272
Options: opts,
7373
}
74+
for _, p := range cs.Global.Plugins {
75+
if p.Name == s.Plugin {
76+
cg.Env = p.Env
77+
cg.Process = pluginProcess(p)
78+
cg.Wasm = pluginWASM(p)
79+
return cg
80+
}
81+
}
82+
return cg
83+
}
84+
85+
func pluginProcess(p config.Plugin) *plugin.Codegen_Process {
86+
if p.Process != nil {
87+
return &plugin.Codegen_Process{
88+
Cmd: p.Process.Cmd,
89+
}
90+
}
91+
return nil
92+
}
93+
94+
func pluginWASM(p config.Plugin) *plugin.Codegen_WASM {
95+
if p.WASM != nil {
96+
return &plugin.Codegen_WASM{
97+
Url: p.WASM.URL,
98+
Sha256: p.WASM.SHA256,
99+
}
100+
}
101+
return nil
74102
}
75103

76104
func pluginGoType(o config.Override) *plugin.ParsedGoType {

internal/endtoend/testdata/codegen_json/gen/codegen.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
"codegen": {
1414
"out": "",
1515
"plugin": "",
16-
"options": ""
16+
"options": "",
17+
"env": [],
18+
"process": null,
19+
"wasm": null
1720
}
1821
},
1922
"catalog": {

internal/endtoend/testdata/process_plugin_sqlc_gen_json/gen/codegen.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
"codegen": {
1414
"out": "gen",
1515
"plugin": "jsonb",
16-
"options": "eyJmaWxlbmFtZSI6ImNvZGVnZW4uanNvbiIsImluZGVudCI6IiAgIn0="
16+
"options": "eyJmaWxlbmFtZSI6ImNvZGVnZW4uanNvbiIsImluZGVudCI6IiAgIn0=",
17+
"env": [],
18+
"process": {
19+
"cmd": "sqlc-gen-json"
20+
},
21+
"wasm": null
1722
}
1823
},
1924
"catalog": {

0 commit comments

Comments
 (0)